@adonis-agora/media 1.0.0-rc.7 → 1.0.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/commands/tenancy_backfill.d.ts +1 -0
- package/dist/commands/tenancy_backfill.d.ts.map +1 -1
- package/dist/commands/tenancy_backfill.js +4 -0
- package/dist/commands/tenancy_backfill.js.map +1 -1
- package/dist/providers/media_provider.d.ts.map +1 -1
- package/dist/providers/media_provider.js +5 -1
- package/dist/providers/media_provider.js.map +1 -1
- package/dist/src/commands/tenancy_backfill.d.ts +2 -0
- package/dist/src/commands/tenancy_backfill.d.ts.map +1 -1
- package/dist/src/commands/tenancy_backfill.js +3 -2
- package/dist/src/commands/tenancy_backfill.js.map +1 -1
- package/dist/src/doctor/checks.d.ts +24 -0
- package/dist/src/doctor/checks.d.ts.map +1 -1
- package/dist/src/doctor/checks.js +100 -0
- package/dist/src/doctor/checks.js.map +1 -1
- package/dist/src/doctor/index.d.ts +1 -1
- package/dist/src/doctor/index.d.ts.map +1 -1
- package/dist/src/doctor/index.js +1 -1
- package/dist/src/doctor/index.js.map +1 -1
- package/dist/src/stores/factory.d.ts +6 -0
- package/dist/src/stores/factory.d.ts.map +1 -1
- package/dist/src/stores/factory.js +6 -1
- package/dist/src/stores/factory.js.map +1 -1
- package/dist/src/stores/lucid-schema.d.ts +50 -13
- package/dist/src/stores/lucid-schema.d.ts.map +1 -1
- package/dist/src/stores/lucid-schema.js +186 -32
- package/dist/src/stores/lucid-schema.js.map +1 -1
- package/dist/src/stores/lucid.d.ts +20 -0
- package/dist/src/stores/lucid.d.ts.map +1 -1
- package/dist/src/stores/lucid.js +42 -8
- package/dist/src/stores/lucid.js.map +1 -1
- package/dist/src/upload_sessions/factory.d.ts +5 -0
- package/dist/src/upload_sessions/factory.d.ts.map +1 -1
- package/dist/src/upload_sessions/factory.js +6 -1
- package/dist/src/upload_sessions/factory.js.map +1 -1
- package/dist/src/upload_sessions/lucid.d.ts +17 -0
- package/dist/src/upload_sessions/lucid.d.ts.map +1 -1
- package/dist/src/upload_sessions/lucid.js +38 -2
- package/dist/src/upload_sessions/lucid.js.map +1 -1
- package/dist/stubs/database/migrations/add_media_tenant_id.stub +18 -6
- package/dist/stubs/database/migrations/create_media_table.stub +17 -2
- package/dist/stubs/database/migrations/create_media_upload_sessions_table.stub +19 -4
- package/package.json +3 -1
- package/skills/media-stores-delivery/SKILL.md +22 -0
|
@@ -32,14 +32,54 @@ export interface MediaTableNames {
|
|
|
32
32
|
}
|
|
33
33
|
/** The default table names for the Lucid store's media schema. */
|
|
34
34
|
export declare const MEDIA_TABLES: Required<MediaTableNames>;
|
|
35
|
+
/** Options the schema functions take. */
|
|
36
|
+
export interface MediaSchemaOptions {
|
|
37
|
+
/** Table-name override (defaults to {@link MEDIA_TABLES}). */
|
|
38
|
+
table?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Database schema the table lives in (a Postgres schema, a MySQL database). Every statement
|
|
41
|
+
* names it. Default: the connection's current schema.
|
|
42
|
+
*/
|
|
43
|
+
schema?: string;
|
|
44
|
+
}
|
|
35
45
|
/** Reject any table name that is not a bare SQL identifier (these are interpolated, never bound). */
|
|
36
46
|
export declare function assertSafeIdentifier(id: string): string;
|
|
37
47
|
export declare function isPostgres(dialect: string | undefined): boolean;
|
|
38
48
|
export declare function isMysql(dialect: string | undefined): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Validate a `schema` option: `undefined` passes through; anything else must be a plain identifier
|
|
51
|
+
* (letters, digits, `_`, `$`, at most 63 characters) on a dialect that has schemas. SQLite fails.
|
|
52
|
+
*/
|
|
53
|
+
export declare function assertSchema(schema: string | undefined, dialect: string | undefined, where: string): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* A table name for Lucid's query builder: `schema.table` (knex quotes the two parts separately,
|
|
56
|
+
* `"schema"."table"`), or the bare table without a schema.
|
|
57
|
+
*/
|
|
58
|
+
export declare function qualifiedTable(table: string, schema: string | undefined): string;
|
|
39
59
|
/**
|
|
40
60
|
* Best-effort dialect name from a Lucid client; `undefined` when it can't be read.
|
|
41
61
|
*/
|
|
42
62
|
export declare function detectDialect(db: LucidDatabase): string | undefined;
|
|
63
|
+
/** The rows of a Lucid `rawQuery` result, whatever the driver returned. */
|
|
64
|
+
export declare function rowsOf(result: unknown): Record<string, unknown>[];
|
|
65
|
+
/** Whether `schema` exists, read from `information_schema` (Postgres and MySQL). */
|
|
66
|
+
export declare function mediaSchemaExists(db: LucidQueryClient, schema: string): Promise<boolean>;
|
|
67
|
+
/** What {@link inspectSchemaTables} reports for `agora:doctor`. */
|
|
68
|
+
export interface MediaSchemaInspection {
|
|
69
|
+
schema: string;
|
|
70
|
+
/** Whether the schema exists (and this connection can see it). */
|
|
71
|
+
exists: boolean;
|
|
72
|
+
/** The tables not found in the schema. */
|
|
73
|
+
missingTables: string[];
|
|
74
|
+
/** Why a no-op write failed, or `null` when it went through. */
|
|
75
|
+
writeError: string | null;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether `schema` exists, which of `tables` are missing from it, and whether this connection may
|
|
79
|
+
* write to each one present (a no-op `INSERT … SELECT … WHERE 1 = 0` and `DELETE … WHERE 1 = 0`, which
|
|
80
|
+
* change nothing but need the privileges).
|
|
81
|
+
*/
|
|
82
|
+
export declare function inspectSchemaTables(db: LucidQueryClient, schema: string, tables: readonly string[]): Promise<MediaSchemaInspection>;
|
|
43
83
|
/**
|
|
44
84
|
* Create the `media` table (idempotent — `CREATE TABLE IF NOT EXISTS`). Safe to call
|
|
45
85
|
* from a Lucid migration `up()` or repeatedly at boot.
|
|
@@ -47,32 +87,30 @@ export declare function detectDialect(db: LucidDatabase): string | undefined;
|
|
|
47
87
|
* The shape mirrors the migration published by `node ace configure @adonis-agora/media`:
|
|
48
88
|
* JSON payloads (`custom_properties`, `conversions`) are stored as TEXT — the store
|
|
49
89
|
* (de)serializes them — and timestamps as epoch-ms integers, so the schema is portable
|
|
50
|
-
* across SQLite / Postgres / MySQL.
|
|
90
|
+
* across SQLite / Postgres / MySQL. With `options.schema`, the schema is created when missing
|
|
91
|
+
* and the table lives in it.
|
|
51
92
|
*
|
|
52
93
|
* @param db a Lucid `Database` or connection client
|
|
53
94
|
* @param options.table optional table-name override (defaults to {@link MEDIA_TABLES})
|
|
95
|
+
* @param options.schema optional database schema (a MySQL database)
|
|
54
96
|
*/
|
|
55
|
-
export declare function createMediaTables(db: LucidDatabase, options?:
|
|
56
|
-
table?: string;
|
|
57
|
-
}): Promise<void>;
|
|
97
|
+
export declare function createMediaTables(db: LucidDatabase, options?: MediaSchemaOptions): Promise<void>;
|
|
58
98
|
/**
|
|
59
99
|
* Drop the `media` table (idempotent — `DROP TABLE IF EXISTS`). For a migration `down()`.
|
|
60
100
|
*
|
|
61
101
|
* @param db a Lucid `Database` or connection client
|
|
62
102
|
* @param options.table optional table-name override (defaults to {@link MEDIA_TABLES})
|
|
103
|
+
* @param options.schema optional database schema (a MySQL database)
|
|
63
104
|
*/
|
|
64
|
-
export declare function dropMediaTables(db: LucidDatabase, options?:
|
|
65
|
-
table?: string;
|
|
66
|
-
}): Promise<void>;
|
|
105
|
+
export declare function dropMediaTables(db: LucidDatabase, options?: MediaSchemaOptions): Promise<void>;
|
|
67
106
|
/**
|
|
68
107
|
* Whether the `media` table has the `tenant_id` column tenancy needs (a zero-row probe query).
|
|
69
108
|
*
|
|
70
109
|
* @param db a Lucid `Database` or connection client
|
|
71
110
|
* @param options.table optional table-name override (defaults to {@link MEDIA_TABLES})
|
|
111
|
+
* @param options.schema optional database schema (a MySQL database)
|
|
72
112
|
*/
|
|
73
|
-
export declare function hasMediaTenantColumn(db:
|
|
74
|
-
table?: string;
|
|
75
|
-
}): Promise<boolean>;
|
|
113
|
+
export declare function hasMediaTenantColumn(db: LucidDatabase, options?: MediaSchemaOptions): Promise<boolean>;
|
|
76
114
|
/**
|
|
77
115
|
* Add the nullable `tenant_id` column and its `(tenant_id, owner_type, owner_id, collection)` index
|
|
78
116
|
* to the `media` table when missing (idempotent). Tenancy (organizations as tenants) stamps new
|
|
@@ -81,8 +119,7 @@ export declare function hasMediaTenantColumn(db: LucidQueryClient, options?: {
|
|
|
81
119
|
*
|
|
82
120
|
* @param db a Lucid `Database` or connection client
|
|
83
121
|
* @param options.table optional table-name override (defaults to {@link MEDIA_TABLES})
|
|
122
|
+
* @param options.schema optional database schema (a MySQL database)
|
|
84
123
|
*/
|
|
85
|
-
export declare function ensureMediaTenantColumn(db: LucidDatabase, options?:
|
|
86
|
-
table?: string;
|
|
87
|
-
}): Promise<void>;
|
|
124
|
+
export declare function ensureMediaTenantColumn(db: LucidDatabase, options?: MediaSchemaOptions): Promise<void>;
|
|
88
125
|
//# sourceMappingURL=lucid-schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lucid-schema.d.ts","sourceRoot":"","sources":["../../../src/stores/lucid-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,4EAA4E;AAC5E,MAAM,MAAM,kBAAkB,GAAG,SAAS,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE9E,sEAAsE;AACtE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxE;AAED,sDAAsD;AACtD,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACrD,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5B,UAAU,CAAC,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG;QAAE,OAAO,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAC7D;AAED,+DAA+D;AAC/D,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,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,EAAE,EAAE,aAAa,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,EAAE,EAAE,aAAa,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,OAAO,CAAC,CASlB;AAED;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,EAAE,EAAE,aAAa,EACjB,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAcf"}
|
|
@@ -14,6 +14,8 @@ export const MEDIA_TABLES = {
|
|
|
14
14
|
media: 'media',
|
|
15
15
|
};
|
|
16
16
|
const IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
17
|
+
const SCHEMA_IDENT = /^[A-Za-z_][A-Za-z0-9_$]*$/;
|
|
18
|
+
const MAX_SCHEMA_LENGTH = 63;
|
|
17
19
|
/** Reject any table name that is not a bare SQL identifier (these are interpolated, never bound). */
|
|
18
20
|
export function assertSafeIdentifier(id) {
|
|
19
21
|
if (!IDENT.test(id))
|
|
@@ -26,6 +28,34 @@ export function isPostgres(dialect) {
|
|
|
26
28
|
export function isMysql(dialect) {
|
|
27
29
|
return !!dialect && /mysql|mariadb/i.test(dialect);
|
|
28
30
|
}
|
|
31
|
+
/** Whether `dialect` has no schemas to put a table in (SQLite and its drivers). */
|
|
32
|
+
function isSchemaless(dialect) {
|
|
33
|
+
return !!dialect && /sqlite|libsql/i.test(dialect);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validate a `schema` option: `undefined` passes through; anything else must be a plain identifier
|
|
37
|
+
* (letters, digits, `_`, `$`, at most 63 characters) on a dialect that has schemas. SQLite fails.
|
|
38
|
+
*/
|
|
39
|
+
export function assertSchema(schema, dialect, where) {
|
|
40
|
+
if (schema === undefined)
|
|
41
|
+
return undefined;
|
|
42
|
+
if (typeof schema !== 'string' ||
|
|
43
|
+
!SCHEMA_IDENT.test(schema) ||
|
|
44
|
+
schema.length > MAX_SCHEMA_LENGTH) {
|
|
45
|
+
throw new Error(`@adonis-agora/media: ${where} \`schema\` must be a plain identifier (letters, digits, _ and $, not starting with a digit, at most ${MAX_SCHEMA_LENGTH} characters); got ${JSON.stringify(schema)}.`);
|
|
46
|
+
}
|
|
47
|
+
if (isSchemaless(dialect)) {
|
|
48
|
+
throw new Error(`@adonis-agora/media: ${where} sets \`schema: "${schema}"\`, but the connection is ${dialect}, which has no schemas. Remove \`schema\` or use a Postgres or MySQL connection.`);
|
|
49
|
+
}
|
|
50
|
+
return schema;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A table name for Lucid's query builder: `schema.table` (knex quotes the two parts separately,
|
|
54
|
+
* `"schema"."table"`), or the bare table without a schema.
|
|
55
|
+
*/
|
|
56
|
+
export function qualifiedTable(table, schema) {
|
|
57
|
+
return schema === undefined ? table : `${schema}.${table}`;
|
|
58
|
+
}
|
|
29
59
|
/**
|
|
30
60
|
* Best-effort dialect name from a Lucid client; `undefined` when it can't be read.
|
|
31
61
|
*/
|
|
@@ -40,6 +70,17 @@ export function detectDialect(db) {
|
|
|
40
70
|
return undefined;
|
|
41
71
|
}
|
|
42
72
|
}
|
|
73
|
+
function sqlFor(db, schema, where) {
|
|
74
|
+
const dialect = detectDialect(db);
|
|
75
|
+
const valid = assertSchema(schema, dialect, where);
|
|
76
|
+
const mysql = isMysql(dialect);
|
|
77
|
+
const q = (identifier) => (mysql ? `\`${identifier}\`` : `"${identifier}"`);
|
|
78
|
+
return {
|
|
79
|
+
q,
|
|
80
|
+
table: (name) => (valid === undefined ? q(name) : `${q(valid)}.${q(name)}`),
|
|
81
|
+
mysql,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
43
84
|
/** Resolve the effective table name, validating the identifier. */
|
|
44
85
|
function resolveTables(options) {
|
|
45
86
|
const t = { ...MEDIA_TABLES };
|
|
@@ -49,6 +90,101 @@ function resolveTables(options) {
|
|
|
49
90
|
}
|
|
50
91
|
return t;
|
|
51
92
|
}
|
|
93
|
+
/** Whether `error` is "this index already exists" (MySQL has no `CREATE INDEX IF NOT EXISTS`). */
|
|
94
|
+
function isDuplicateIndex(error) {
|
|
95
|
+
const { code, errno } = (error ?? {});
|
|
96
|
+
return (code === 'ER_DUP_KEYNAME' ||
|
|
97
|
+
code === '42P07' ||
|
|
98
|
+
errno === 1061 ||
|
|
99
|
+
/already exists|duplicate/i.test(String(error?.message ?? error)));
|
|
100
|
+
}
|
|
101
|
+
/** Whether `error` is a missing privilege (Postgres 42501, MySQL 1044 / 1142 / 1227). */
|
|
102
|
+
function isPermissionDenied(error) {
|
|
103
|
+
const { code, errno } = (error ?? {});
|
|
104
|
+
return (code === '42501' ||
|
|
105
|
+
code === 'ER_DBACCESS_DENIED_ERROR' ||
|
|
106
|
+
code === 'ER_TABLEACCESS_DENIED_ERROR' ||
|
|
107
|
+
code === 'ER_SPECIFIC_ACCESS_DENIED_ERROR' ||
|
|
108
|
+
errno === 1044 ||
|
|
109
|
+
errno === 1142 ||
|
|
110
|
+
errno === 1227);
|
|
111
|
+
}
|
|
112
|
+
/** The rows of a Lucid `rawQuery` result, whatever the driver returned. */
|
|
113
|
+
export function rowsOf(result) {
|
|
114
|
+
if (Array.isArray(result)) {
|
|
115
|
+
// mysql2 resolves `[rows, fields]`; sqlite resolves the rows themselves.
|
|
116
|
+
return (Array.isArray(result[0]) ? result[0] : result);
|
|
117
|
+
}
|
|
118
|
+
const rows = result?.rows;
|
|
119
|
+
return Array.isArray(rows) ? rows : [];
|
|
120
|
+
}
|
|
121
|
+
/** Whether `schema` exists, read from `information_schema` (Postgres and MySQL). */
|
|
122
|
+
export async function mediaSchemaExists(db, schema) {
|
|
123
|
+
const rows = rowsOf(await db.rawQuery('SELECT 1 AS found FROM information_schema.schemata WHERE schema_name = ?', [
|
|
124
|
+
schema,
|
|
125
|
+
]));
|
|
126
|
+
return rows.length > 0;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Whether `schema` exists, which of `tables` are missing from it, and whether this connection may
|
|
130
|
+
* write to each one present (a no-op `INSERT … SELECT … WHERE 1 = 0` and `DELETE … WHERE 1 = 0`, which
|
|
131
|
+
* change nothing but need the privileges).
|
|
132
|
+
*/
|
|
133
|
+
export async function inspectSchemaTables(db, schema, tables) {
|
|
134
|
+
if (!(await mediaSchemaExists(db, schema))) {
|
|
135
|
+
return { schema, exists: false, missingTables: [], writeError: null };
|
|
136
|
+
}
|
|
137
|
+
const found = rowsOf(await db.rawQuery(`SELECT table_name AS name FROM information_schema.tables WHERE table_schema = ? AND table_name IN (${tables.map(() => '?').join(', ')})`, [schema, ...tables])).map((row) => String(row.name ?? row.NAME ?? row.TABLE_NAME));
|
|
138
|
+
const missingTables = tables.filter((table) => !found.includes(table));
|
|
139
|
+
let writeError = null;
|
|
140
|
+
for (const table of tables) {
|
|
141
|
+
if (missingTables.includes(table))
|
|
142
|
+
continue;
|
|
143
|
+
const qualified = qualifiedTable(table, schema);
|
|
144
|
+
try {
|
|
145
|
+
await db.rawQuery('INSERT INTO ?? SELECT * FROM ?? WHERE 1 = 0', [qualified, qualified]);
|
|
146
|
+
await db.rawQuery('DELETE FROM ?? WHERE 1 = 0', [qualified]);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
writeError = `${table}: ${error instanceof Error ? error.message : String(error)}`;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return { schema, exists: true, missingTables, writeError };
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Create `schema` when it is missing: `CREATE SCHEMA IF NOT EXISTS` (Postgres) or
|
|
157
|
+
* `CREATE DATABASE IF NOT EXISTS` (MySQL). The catalog is read first, so a role that may use an
|
|
158
|
+
* existing schema but not create one is fine. When the role cannot create it, the error names the
|
|
159
|
+
* schema and the grant it needs.
|
|
160
|
+
*/
|
|
161
|
+
async function ensureDatabaseSchema(db, schema, sql) {
|
|
162
|
+
if (await mediaSchemaExists(db, schema))
|
|
163
|
+
return;
|
|
164
|
+
try {
|
|
165
|
+
await db.rawQuery(`${sql.mysql ? 'CREATE DATABASE' : 'CREATE SCHEMA'} IF NOT EXISTS ${sql.q(schema)}`);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (!isPermissionDenied(error))
|
|
169
|
+
throw error;
|
|
170
|
+
const grant = sql.mysql
|
|
171
|
+
? `GRANT ALL ON \`${schema}\`.* TO <app user>`
|
|
172
|
+
: `GRANT CREATE ON DATABASE <database> TO <app role> (or create it once: CREATE SCHEMA "${schema}" AUTHORIZATION <app role>)`;
|
|
173
|
+
throw new Error(`@adonis-agora/media: cannot create the ${sql.mysql ? 'database' : 'schema'} "${schema}": the connection's role is not allowed to. Create it beforehand or grant the role: ${grant}.`, { cause: error });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
/** `CREATE INDEX` that is a no-op when the index exists, on every dialect. */
|
|
177
|
+
async function createIndex(db, sql, name, table, columns) {
|
|
178
|
+
const statement = `CREATE INDEX ${sql.mysql ? '' : 'IF NOT EXISTS '}${sql.q(name)} ON ${sql.table(table)} (${columns.map(sql.q).join(', ')})`;
|
|
179
|
+
try {
|
|
180
|
+
await db.rawQuery(statement);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
// MySQL reports an existing index; Postgres may lose a concurrent `IF NOT EXISTS` race.
|
|
184
|
+
if (!isDuplicateIndex(error))
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
52
188
|
/**
|
|
53
189
|
* Create the `media` table (idempotent — `CREATE TABLE IF NOT EXISTS`). Safe to call
|
|
54
190
|
* from a Lucid migration `up()` or repeatedly at boot.
|
|
@@ -56,57 +192,75 @@ function resolveTables(options) {
|
|
|
56
192
|
* The shape mirrors the migration published by `node ace configure @adonis-agora/media`:
|
|
57
193
|
* JSON payloads (`custom_properties`, `conversions`) are stored as TEXT — the store
|
|
58
194
|
* (de)serializes them — and timestamps as epoch-ms integers, so the schema is portable
|
|
59
|
-
* across SQLite / Postgres / MySQL.
|
|
195
|
+
* across SQLite / Postgres / MySQL. With `options.schema`, the schema is created when missing
|
|
196
|
+
* and the table lives in it.
|
|
60
197
|
*
|
|
61
198
|
* @param db a Lucid `Database` or connection client
|
|
62
199
|
* @param options.table optional table-name override (defaults to {@link MEDIA_TABLES})
|
|
200
|
+
* @param options.schema optional database schema (a MySQL database)
|
|
63
201
|
*/
|
|
64
202
|
export async function createMediaTables(db, options = {}) {
|
|
65
203
|
const t = resolveTables(options);
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
204
|
+
const sql = sqlFor(db, options.schema, 'createMediaTables()');
|
|
205
|
+
const { q } = sql;
|
|
206
|
+
if (options.schema !== undefined)
|
|
207
|
+
await ensureDatabaseSchema(db, options.schema, sql);
|
|
208
|
+
await db.rawQuery(`CREATE TABLE IF NOT EXISTS ${sql.table(t.media)} (
|
|
209
|
+
${q('id')} VARCHAR(255) PRIMARY KEY,
|
|
210
|
+
${q('owner_type')} VARCHAR(255) NOT NULL,
|
|
211
|
+
${q('owner_id')} VARCHAR(255) NOT NULL,
|
|
212
|
+
${q('collection')} VARCHAR(255) NOT NULL,
|
|
213
|
+
${q('name')} VARCHAR(255) NOT NULL,
|
|
214
|
+
${q('file_name')} VARCHAR(255) NOT NULL,
|
|
215
|
+
${q('mime_type')} VARCHAR(255) NOT NULL,
|
|
216
|
+
${q('size')} BIGINT NOT NULL,
|
|
217
|
+
${q('disk')} VARCHAR(255) NOT NULL,
|
|
218
|
+
${q('path')} TEXT NOT NULL,
|
|
219
|
+
${q('order')} INTEGER NOT NULL DEFAULT 0,
|
|
220
|
+
${q('custom_properties')} TEXT,
|
|
221
|
+
${q('conversions')} TEXT,
|
|
222
|
+
${q('created_at')} BIGINT NOT NULL,
|
|
223
|
+
${q('updated_at')} BIGINT NOT NULL
|
|
83
224
|
)`);
|
|
84
225
|
// `(owner_type, owner_id)` lookups use the leftmost prefix of the owner+collection index.
|
|
85
|
-
|
|
226
|
+
// Index names are never schema-qualified: they live in their table's schema.
|
|
227
|
+
await createIndex(db, sql, `${t.media}_owner_collection_idx`, t.media, [
|
|
228
|
+
'owner_type',
|
|
229
|
+
'owner_id',
|
|
230
|
+
'collection',
|
|
231
|
+
]);
|
|
86
232
|
// The newest-first keyset `list()` pages on, unfiltered and per collection.
|
|
87
|
-
await
|
|
88
|
-
await
|
|
233
|
+
await createIndex(db, sql, `${t.media}_created_idx`, t.media, ['created_at', 'id']);
|
|
234
|
+
await createIndex(db, sql, `${t.media}_collection_created_idx`, t.media, [
|
|
235
|
+
'collection',
|
|
236
|
+
'created_at',
|
|
237
|
+
'id',
|
|
238
|
+
]);
|
|
89
239
|
}
|
|
90
240
|
/**
|
|
91
241
|
* Drop the `media` table (idempotent — `DROP TABLE IF EXISTS`). For a migration `down()`.
|
|
92
242
|
*
|
|
93
243
|
* @param db a Lucid `Database` or connection client
|
|
94
244
|
* @param options.table optional table-name override (defaults to {@link MEDIA_TABLES})
|
|
245
|
+
* @param options.schema optional database schema (a MySQL database)
|
|
95
246
|
*/
|
|
96
247
|
export async function dropMediaTables(db, options = {}) {
|
|
97
248
|
const t = resolveTables(options);
|
|
98
|
-
|
|
249
|
+
const sql = sqlFor(db, options.schema, 'dropMediaTables()');
|
|
250
|
+
await db.rawQuery(`DROP TABLE IF EXISTS ${sql.table(t.media)}`);
|
|
99
251
|
}
|
|
100
252
|
/**
|
|
101
253
|
* Whether the `media` table has the `tenant_id` column tenancy needs (a zero-row probe query).
|
|
102
254
|
*
|
|
103
255
|
* @param db a Lucid `Database` or connection client
|
|
104
256
|
* @param options.table optional table-name override (defaults to {@link MEDIA_TABLES})
|
|
257
|
+
* @param options.schema optional database schema (a MySQL database)
|
|
105
258
|
*/
|
|
106
259
|
export async function hasMediaTenantColumn(db, options = {}) {
|
|
107
260
|
const t = resolveTables(options);
|
|
261
|
+
const sql = sqlFor(db, options.schema, 'hasMediaTenantColumn()');
|
|
108
262
|
try {
|
|
109
|
-
await db.rawQuery(`SELECT tenant_id FROM ${t.media} WHERE 1 = 0`);
|
|
263
|
+
await db.rawQuery(`SELECT ${sql.q('tenant_id')} FROM ${sql.table(t.media)} WHERE 1 = 0`);
|
|
110
264
|
return true;
|
|
111
265
|
}
|
|
112
266
|
catch {
|
|
@@ -121,19 +275,19 @@ export async function hasMediaTenantColumn(db, options = {}) {
|
|
|
121
275
|
*
|
|
122
276
|
* @param db a Lucid `Database` or connection client
|
|
123
277
|
* @param options.table optional table-name override (defaults to {@link MEDIA_TABLES})
|
|
278
|
+
* @param options.schema optional database schema (a MySQL database)
|
|
124
279
|
*/
|
|
125
280
|
export async function ensureMediaTenantColumn(db, options = {}) {
|
|
126
281
|
const t = resolveTables(options);
|
|
282
|
+
const sql = sqlFor(db, options.schema, 'ensureMediaTenantColumn()');
|
|
127
283
|
if (!(await hasMediaTenantColumn(db, options))) {
|
|
128
|
-
await db.rawQuery(`ALTER TABLE ${t.media} ADD COLUMN tenant_id VARCHAR(255) NULL`);
|
|
129
|
-
}
|
|
130
|
-
// MySQL has no `CREATE INDEX IF NOT EXISTS`: a duplicate index there is reported and ignored.
|
|
131
|
-
try {
|
|
132
|
-
await db.rawQuery(`CREATE INDEX ${isMysql(detectDialect(db)) ? '' : 'IF NOT EXISTS '}${t.media}_tenant_owner_idx ON ${t.media} (tenant_id, owner_type, owner_id, collection)`);
|
|
133
|
-
}
|
|
134
|
-
catch (error) {
|
|
135
|
-
if (!/duplicate|exists/i.test(String(error?.message ?? error)))
|
|
136
|
-
throw error;
|
|
284
|
+
await db.rawQuery(`ALTER TABLE ${sql.table(t.media)} ADD COLUMN ${sql.q('tenant_id')} VARCHAR(255) NULL`);
|
|
137
285
|
}
|
|
286
|
+
await createIndex(db, sql, `${t.media}_tenant_owner_idx`, t.media, [
|
|
287
|
+
'tenant_id',
|
|
288
|
+
'owner_type',
|
|
289
|
+
'owner_id',
|
|
290
|
+
'collection',
|
|
291
|
+
]);
|
|
138
292
|
}
|
|
139
293
|
//# sourceMappingURL=lucid-schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lucid-schema.js","sourceRoot":"","sources":["../../../src/stores/lucid-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAqBH,kEAAkE;AAClE,MAAM,CAAC,MAAM,YAAY,GAA8B;IACrD,KAAK,EAAE,OAAO;CACf,CAAC;
|
|
1
|
+
{"version":3,"file":"lucid-schema.js","sourceRoot":"","sources":["../../../src/stores/lucid-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAqBH,kEAAkE;AAClE,MAAM,CAAC,MAAM,YAAY,GAA8B;IACrD,KAAK,EAAE,OAAO;CACf,CAAC;AAaF,MAAM,KAAK,GAAG,0BAA0B,CAAC;AACzC,MAAM,YAAY,GAAG,2BAA2B,CAAC;AACjD,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,qGAAqG;AACrG,MAAM,UAAU,oBAAoB,CAAC,EAAU;IAC7C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,+CAA+C,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACvF,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,OAA2B;IACpD,OAAO,CAAC,CAAC,OAAO,IAAI,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC5D,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,OAA2B;IACjD,OAAO,CAAC,CAAC,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC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,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAC;IACjE,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,SAAS,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QACzF,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,EAAiB,EACjB,OAAO,GAAuB,EAAE;IAEhC,MAAM,CAAC,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;IACpE,IAAI,CAAC,CAAC,MAAM,oBAAoB,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC;QAC/C,MAAM,EAAE,CAAC,QAAQ,CACf,eAAe,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,eAAe,GAAG,CAAC,CAAC,CAAC,WAAW,CAAC,oBAAoB,CACvF,CAAC;IACJ,CAAC;IACD,MAAM,WAAW,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,KAAK,mBAAmB,EAAE,CAAC,CAAC,KAAK,EAAE;QACjE,WAAW;QACX,YAAY;QACZ,UAAU;QACV,YAAY;KACb,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import type { Database } from '@adonisjs/lucid/database';
|
|
2
2
|
import type { MediaRecord } from '../media_record.js';
|
|
3
3
|
import { type MediaCollectionTotals, type MediaListOptions, type MediaListPage, type MediaOwnerPageOptions, type MediaStore, type MediaTotalsOptions } from '../media_store.js';
|
|
4
|
+
import { type MediaSchemaInspection } from './lucid-schema.js';
|
|
4
5
|
export interface LucidMediaStoreOptions {
|
|
5
6
|
/** The Lucid connection name. Defaults to the `Database` default connection. */
|
|
6
7
|
connectionName?: string;
|
|
7
8
|
/** Table name. Default `media`. */
|
|
8
9
|
table?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Database schema the table lives in (a Postgres schema, a MySQL database). Every query names
|
|
12
|
+
* it; with `autoCreateSchema` it is created when missing. Not supported on SQLite (the
|
|
13
|
+
* constructor throws). Default: the connection's current schema.
|
|
14
|
+
*/
|
|
15
|
+
schema?: string;
|
|
9
16
|
/**
|
|
10
17
|
* Auto-create the `media` table on first use (default `true`). Set to `false` to
|
|
11
18
|
* manage the schema explicitly via a migration calling {@link createMediaTables}.
|
|
@@ -39,11 +46,19 @@ export declare class LucidMediaStore implements MediaStore {
|
|
|
39
46
|
private readonly db;
|
|
40
47
|
readonly tenantFiltering = true;
|
|
41
48
|
private readonly table;
|
|
49
|
+
/** The configured database schema, or `undefined` for the connection's current one. */
|
|
50
|
+
readonly schema: string | undefined;
|
|
51
|
+
/** {@link table} as the query builder takes it (`schema.table` when a schema is set). */
|
|
52
|
+
private readonly qualified;
|
|
42
53
|
private readonly connectionName;
|
|
43
54
|
private readonly autoCreate;
|
|
44
55
|
private readonly tenantColumn;
|
|
45
56
|
private schemaReady;
|
|
46
57
|
constructor(db: Database, options?: LucidMediaStoreOptions);
|
|
58
|
+
/** The connection's dialect name, when it can be read without a query. */
|
|
59
|
+
private dialect;
|
|
60
|
+
/** The options every schema helper takes: the table and, when set, the schema. */
|
|
61
|
+
private schemaOptions;
|
|
47
62
|
private client;
|
|
48
63
|
private query;
|
|
49
64
|
/** Ensure the schema exists before the first operation, once per store instance. */
|
|
@@ -51,6 +66,11 @@ export declare class LucidMediaStore implements MediaStore {
|
|
|
51
66
|
private assertTenantColumn;
|
|
52
67
|
/** Whether the table has the `tenant_id` column tenancy needs. */
|
|
53
68
|
hasTenantColumn(): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Where the configured {@link schema} stands, for `agora:doctor`: whether it exists, whether the
|
|
71
|
+
* table is in it, and whether this connection may write to it. `null` without a schema.
|
|
72
|
+
*/
|
|
73
|
+
inspectSchema(): Promise<MediaSchemaInspection | null>;
|
|
54
74
|
/**
|
|
55
75
|
* Create the `media` table (idempotent). Delegates to the standalone {@link createMediaTables}
|
|
56
76
|
* so the auto-create path and a migration-based one run identical DDL.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lucid.d.ts","sourceRoot":"","sources":["../../../src/stores/lucid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAIL,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACxB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"lucid.d.ts","sourceRoot":"","sources":["../../../src/stores/lucid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAEzD,OAAO,KAAK,EAAmB,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAIL,KAAK,qBAAqB,EAC1B,KAAK,gBAAgB,EACrB,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EASL,KAAK,qBAAqB,EAE3B,MAAM,mBAAmB,CAAC;AAE3B,MAAM,WAAW,sBAAsB;IACrC,gFAAgF;IAChF,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mCAAmC;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,MAAM,CAAC,EAA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AAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC,CAIlD;IAEK,WAAW,CACf,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,WAAW,EAAE,CAAC,CAMxB;IAEK,gBAAgB,CACpB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,qBAA0B,GAClC,OAAO,CAAC,aAAa,CAAC,CAYxB;IAEK,IAAI,CACR,OAAO,GAAE,gBAAgB,GAAG;QAAE,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAO,GACpE,OAAO,CAAC,aAAa,CAAC,CA2CxB;IAEK,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAGtC;IAEK,gBAAgB,CAAC,OAAO,GAAE,kBAAuB,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC,CAsBzF;IAEK,WAAW,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CASrC;IAEK,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAUvF;CACF"}
|
package/dist/src/stores/lucid.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { clampMediaListLimit, decodeMediaCursor, encodeMediaCursor, } from '../media_store.js';
|
|
2
|
-
import { createMediaTables, ensureMediaTenantColumn, hasMediaTenantColumn, } from './lucid-schema.js';
|
|
2
|
+
import { assertSafeIdentifier, assertSchema, createMediaTables, detectDialect, ensureMediaTenantColumn, hasMediaTenantColumn, inspectSchemaTables, qualifiedTable, } from './lucid-schema.js';
|
|
3
3
|
/** Thrown when tenancy is on and the `media` table has no `tenant_id` column. */
|
|
4
4
|
export class MediaTenancySchemaError extends Error {
|
|
5
5
|
code = 'E_MEDIA_TENANCY_SCHEMA';
|
|
@@ -23,6 +23,10 @@ export class LucidMediaStore {
|
|
|
23
23
|
db;
|
|
24
24
|
tenantFiltering = true;
|
|
25
25
|
table;
|
|
26
|
+
/** The configured database schema, or `undefined` for the connection's current one. */
|
|
27
|
+
schema;
|
|
28
|
+
/** {@link table} as the query builder takes it (`schema.table` when a schema is set). */
|
|
29
|
+
qualified;
|
|
26
30
|
connectionName;
|
|
27
31
|
autoCreate;
|
|
28
32
|
tenantColumn;
|
|
@@ -33,12 +37,33 @@ export class LucidMediaStore {
|
|
|
33
37
|
this.connectionName = options.connectionName;
|
|
34
38
|
this.autoCreate = options.autoCreateSchema !== false;
|
|
35
39
|
this.tenantColumn = options.tenantColumn === true;
|
|
40
|
+
this.schema =
|
|
41
|
+
options.schema === undefined
|
|
42
|
+
? undefined
|
|
43
|
+
: assertSchema(options.schema, this.dialect(), 'stores.lucid()');
|
|
44
|
+
// With a schema the table must be a bare name: `a.b` would make a three-part reference.
|
|
45
|
+
if (this.schema !== undefined)
|
|
46
|
+
assertSafeIdentifier(this.table);
|
|
47
|
+
this.qualified = qualifiedTable(this.table, this.schema);
|
|
48
|
+
}
|
|
49
|
+
/** The connection's dialect name, when it can be read without a query. */
|
|
50
|
+
dialect() {
|
|
51
|
+
try {
|
|
52
|
+
return detectDialect(this.client());
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** The options every schema helper takes: the table and, when set, the schema. */
|
|
59
|
+
schemaOptions() {
|
|
60
|
+
return { table: this.table, ...(this.schema !== undefined ? { schema: this.schema } : {}) };
|
|
36
61
|
}
|
|
37
62
|
client() {
|
|
38
63
|
return this.connectionName ? this.db.connection(this.connectionName) : this.db.connection();
|
|
39
64
|
}
|
|
40
65
|
query() {
|
|
41
|
-
return this.client().from(this.
|
|
66
|
+
return this.client().from(this.qualified);
|
|
42
67
|
}
|
|
43
68
|
/** Ensure the schema exists before the first operation, once per store instance. */
|
|
44
69
|
async ready() {
|
|
@@ -54,13 +79,22 @@ export class LucidMediaStore {
|
|
|
54
79
|
return this.schemaReady;
|
|
55
80
|
}
|
|
56
81
|
async assertTenantColumn() {
|
|
57
|
-
if (!(await hasMediaTenantColumn(this.client(),
|
|
58
|
-
throw new MediaTenancySchemaError(this.
|
|
82
|
+
if (!(await hasMediaTenantColumn(this.client(), this.schemaOptions()))) {
|
|
83
|
+
throw new MediaTenancySchemaError(this.qualified);
|
|
59
84
|
}
|
|
60
85
|
}
|
|
61
86
|
/** Whether the table has the `tenant_id` column tenancy needs. */
|
|
62
87
|
async hasTenantColumn() {
|
|
63
|
-
return hasMediaTenantColumn(this.client(),
|
|
88
|
+
return hasMediaTenantColumn(this.client(), this.schemaOptions());
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Where the configured {@link schema} stands, for `agora:doctor`: whether it exists, whether the
|
|
92
|
+
* table is in it, and whether this connection may write to it. `null` without a schema.
|
|
93
|
+
*/
|
|
94
|
+
async inspectSchema() {
|
|
95
|
+
if (this.schema === undefined)
|
|
96
|
+
return null;
|
|
97
|
+
return inspectSchemaTables(this.client(), this.schema, [this.table]);
|
|
64
98
|
}
|
|
65
99
|
/**
|
|
66
100
|
* Create the `media` table (idempotent). Delegates to the standalone {@link createMediaTables}
|
|
@@ -69,16 +103,16 @@ export class LucidMediaStore {
|
|
|
69
103
|
async ensureSchema() {
|
|
70
104
|
// On the store's own connection: the `Database` facade would run the DDL on the default one.
|
|
71
105
|
const client = this.client();
|
|
72
|
-
await createMediaTables(client,
|
|
106
|
+
await createMediaTables(client, this.schemaOptions());
|
|
73
107
|
if (this.tenantColumn)
|
|
74
|
-
await ensureMediaTenantColumn(client,
|
|
108
|
+
await ensureMediaTenantColumn(client, this.schemaOptions());
|
|
75
109
|
}
|
|
76
110
|
async save(record) {
|
|
77
111
|
await this.ready();
|
|
78
112
|
const row = toRow(record, this.tenantColumn);
|
|
79
113
|
// Single atomic upsert (portable Knex `INSERT ... ON CONFLICT (id) DO UPDATE`) instead of a
|
|
80
114
|
// racy read-then-branch: concurrent saves of the same id can't interleave into a lost write.
|
|
81
|
-
await this.client().table(this.
|
|
115
|
+
await this.client().table(this.qualified).insert(row).onConflict('id').merge();
|
|
82
116
|
return { ...record };
|
|
83
117
|
}
|
|
84
118
|
async find(id) {
|