@strapi/database 5.47.1 → 5.48.1

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.
Files changed (44) hide show
  1. package/dist/dialects/mysql/schema-inspector.d.ts +3 -0
  2. package/dist/dialects/mysql/schema-inspector.d.ts.map +1 -1
  3. package/dist/dialects/mysql/schema-inspector.js +145 -85
  4. package/dist/dialects/mysql/schema-inspector.js.map +1 -1
  5. package/dist/dialects/mysql/schema-inspector.mjs +145 -85
  6. package/dist/dialects/mysql/schema-inspector.mjs.map +1 -1
  7. package/dist/dialects/postgresql/schema-inspector.d.ts +3 -1
  8. package/dist/dialects/postgresql/schema-inspector.d.ts.map +1 -1
  9. package/dist/dialects/postgresql/schema-inspector.js +150 -109
  10. package/dist/dialects/postgresql/schema-inspector.js.map +1 -1
  11. package/dist/dialects/postgresql/schema-inspector.mjs +150 -109
  12. package/dist/dialects/postgresql/schema-inspector.mjs.map +1 -1
  13. package/dist/fields/biginteger.d.ts +4 -2
  14. package/dist/fields/biginteger.d.ts.map +1 -1
  15. package/dist/fields/biginteger.js +41 -2
  16. package/dist/fields/biginteger.js.map +1 -1
  17. package/dist/fields/biginteger.mjs +41 -2
  18. package/dist/fields/biginteger.mjs.map +1 -1
  19. package/dist/fields/number.d.ts +1 -1
  20. package/dist/fields/number.d.ts.map +1 -1
  21. package/dist/fields/number.js +20 -4
  22. package/dist/fields/number.js.map +1 -1
  23. package/dist/fields/number.mjs +20 -4
  24. package/dist/fields/number.mjs.map +1 -1
  25. package/dist/index.d.ts +7 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js.map +1 -1
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.d.ts +5 -0
  30. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.d.ts.map +1 -1
  31. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.js +7 -58
  32. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.js.map +1 -1
  33. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.mjs +7 -58
  34. package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.mjs.map +1 -1
  35. package/dist/query/helpers/populate/apply.js +1 -1
  36. package/dist/query/helpers/populate/apply.js.map +1 -1
  37. package/dist/query/helpers/populate/apply.mjs +1 -1
  38. package/dist/query/helpers/populate/apply.mjs.map +1 -1
  39. package/dist/transaction-context.d.ts.map +1 -1
  40. package/dist/transaction-context.js +22 -0
  41. package/dist/transaction-context.js.map +1 -1
  42. package/dist/transaction-context.mjs +22 -0
  43. package/dist/transaction-context.mjs.map +1 -1
  44. package/package.json +5 -5
@@ -3,11 +3,27 @@ import Field from './field.mjs';
3
3
 
4
4
  class NumberField extends Field {
5
5
  toDB(value) {
6
- const numberValue = toNumber(value);
7
- if (Number.isNaN(numberValue)) {
8
- throw new Error(`Expected a valid Number, got ${value}`);
6
+ if (value === null || value === undefined) {
7
+ return value;
9
8
  }
10
- return numberValue;
9
+ if (typeof value === 'number') {
10
+ if (!Number.isFinite(value)) {
11
+ throw new Error(`Expected a valid Number, got ${value}`);
12
+ }
13
+ return value;
14
+ }
15
+ if (typeof value === 'string') {
16
+ const trimmedValue = value.trim();
17
+ if (trimmedValue.length === 0) {
18
+ throw new Error(`Expected a valid Number, got ${value}`);
19
+ }
20
+ const numberValue = Number(trimmedValue);
21
+ if (!Number.isFinite(numberValue)) {
22
+ throw new Error(`Expected a valid Number, got ${value}`);
23
+ }
24
+ return numberValue;
25
+ }
26
+ throw new Error(`Expected a valid Number, got ${value}`);
11
27
  }
12
28
  fromDB(value) {
13
29
  return toNumber(value);
@@ -1 +1 @@
1
- {"version":3,"file":"number.mjs","sources":["../../src/fields/number.ts"],"sourcesContent":["import { toNumber } from 'lodash/fp';\nimport Field from './field';\n\nexport default class NumberField extends Field {\n toDB(value: unknown) {\n const numberValue = toNumber(value);\n\n if (Number.isNaN(numberValue)) {\n throw new Error(`Expected a valid Number, got ${value}`);\n }\n\n return numberValue;\n }\n\n fromDB(value: unknown) {\n return toNumber(value);\n }\n}\n"],"names":["NumberField","Field","toDB","value","numberValue","toNumber","Number","isNaN","Error","fromDB"],"mappings":";;;AAGe,MAAMA,WAAAA,SAAoBC,KAAAA,CAAAA;AACvCC,IAAAA,IAAAA,CAAKC,KAAc,EAAE;AACnB,QAAA,MAAMC,cAAcC,QAAAA,CAASF,KAAAA,CAAAA;QAE7B,IAAIG,MAAAA,CAAOC,KAAK,CAACH,WAAAA,CAAAA,EAAc;AAC7B,YAAA,MAAM,IAAII,KAAAA,CAAM,CAAC,6BAA6B,EAAEL,KAAAA,CAAAA,CAAO,CAAA;AACzD,QAAA;QAEA,OAAOC,WAAAA;AACT,IAAA;AAEAK,IAAAA,MAAAA,CAAON,KAAc,EAAE;AACrB,QAAA,OAAOE,QAAAA,CAASF,KAAAA,CAAAA;AAClB,IAAA;AACF;;;;"}
1
+ {"version":3,"file":"number.mjs","sources":["../../src/fields/number.ts"],"sourcesContent":["import { toNumber } from 'lodash/fp';\nimport Field from './field';\n\nexport default class NumberField extends Field {\n toDB(value: unknown) {\n if (value === null || value === undefined) {\n return value;\n }\n\n if (typeof value === 'number') {\n if (!Number.isFinite(value)) {\n throw new Error(`Expected a valid Number, got ${value}`);\n }\n\n return value;\n }\n\n if (typeof value === 'string') {\n const trimmedValue = value.trim();\n\n if (trimmedValue.length === 0) {\n throw new Error(`Expected a valid Number, got ${value}`);\n }\n\n const numberValue = Number(trimmedValue);\n\n if (!Number.isFinite(numberValue)) {\n throw new Error(`Expected a valid Number, got ${value}`);\n }\n\n return numberValue;\n }\n\n throw new Error(`Expected a valid Number, got ${value}`);\n }\n\n fromDB(value: unknown) {\n return toNumber(value);\n }\n}\n"],"names":["NumberField","Field","toDB","value","undefined","Number","isFinite","Error","trimmedValue","trim","length","numberValue","fromDB","toNumber"],"mappings":";;;AAGe,MAAMA,WAAAA,SAAoBC,KAAAA,CAAAA;AACvCC,IAAAA,IAAAA,CAAKC,KAAc,EAAE;QACnB,IAAIA,KAAAA,KAAU,IAAA,IAAQA,KAAAA,KAAUC,SAAAA,EAAW;YACzC,OAAOD,KAAAA;AACT,QAAA;QAEA,IAAI,OAAOA,UAAU,QAAA,EAAU;AAC7B,YAAA,IAAI,CAACE,MAAAA,CAAOC,QAAQ,CAACH,KAAAA,CAAAA,EAAQ;AAC3B,gBAAA,MAAM,IAAII,KAAAA,CAAM,CAAC,6BAA6B,EAAEJ,KAAAA,CAAAA,CAAO,CAAA;AACzD,YAAA;YAEA,OAAOA,KAAAA;AACT,QAAA;QAEA,IAAI,OAAOA,UAAU,QAAA,EAAU;YAC7B,MAAMK,YAAAA,GAAeL,MAAMM,IAAI,EAAA;YAE/B,IAAID,YAAAA,CAAaE,MAAM,KAAK,CAAA,EAAG;AAC7B,gBAAA,MAAM,IAAIH,KAAAA,CAAM,CAAC,6BAA6B,EAAEJ,KAAAA,CAAAA,CAAO,CAAA;AACzD,YAAA;AAEA,YAAA,MAAMQ,cAAcN,MAAAA,CAAOG,YAAAA,CAAAA;AAE3B,YAAA,IAAI,CAACH,MAAAA,CAAOC,QAAQ,CAACK,WAAAA,CAAAA,EAAc;AACjC,gBAAA,MAAM,IAAIJ,KAAAA,CAAM,CAAC,6BAA6B,EAAEJ,KAAAA,CAAAA,CAAO,CAAA;AACzD,YAAA;YAEA,OAAOQ,WAAAA;AACT,QAAA;AAEA,QAAA,MAAM,IAAIJ,KAAAA,CAAM,CAAC,6BAA6B,EAAEJ,KAAAA,CAAAA,CAAO,CAAA;AACzD,IAAA;AAEAS,IAAAA,MAAAA,CAAOT,KAAc,EAAE;AACrB,QAAA,OAAOU,QAAAA,CAASV,KAAAA,CAAAA;AAClB,IAAA;AACF;;;;"}
package/dist/index.d.ts CHANGED
@@ -42,6 +42,13 @@ declare class Database {
42
42
  }): Promise<this>;
43
43
  query(uid: string): import("./entity-manager").Repository;
44
44
  inTransaction(): boolean;
45
+ /**
46
+ * Run work inside a DB transaction. On a fulfilled callback, the transaction
47
+ * is committed; on rejection, it is rolled back. The callback receives Knex
48
+ * `commit` and `rollback` helpers: if you call `rollback` and return without
49
+ * throwing, the implementation avoids attempting a second `commit` on an
50
+ * already-finalised transactor.
51
+ */
45
52
  transaction(): Promise<TransactionObject>;
46
53
  transaction<TCallback extends Callback>(c: TCallback): Promise<ReturnType<TCallback>>;
47
54
  getSchemaName(): string | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAIjC,OAAO,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AACjD,OAAO,EAAwB,cAAc,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAkB,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAuB,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAA4B,iBAAiB,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAC3F,OAAO,EAA4B,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE3E,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAkB,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEpF,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAuB,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAEpE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,UAAU,QAAQ;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,EAAE;QACV,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,CAA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W,EAAE,SAAS,EAAE,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport path from 'node:path';\n\nimport { Dialect, getDialect } from './dialects';\nimport { createSchemaProvider, SchemaProvider } from './schema';\nimport { createMetadata, Metadata } from './metadata';\nimport { createEntityManager, EntityManager } from './entity-manager';\nimport { createMigrationsProvider, MigrationProvider, type Migration } from './migrations';\nimport { createLifecyclesProvider, LifecycleProvider } from './lifecycles';\nimport { createConnection } from './connection';\nimport * as errors from './errors';\nimport { Callback, transactionCtx, TransactionObject } from './transaction-context';\nimport { validateDatabase } from './validations';\nimport type { Model, JoinTable } from './types';\nimport type { Identifiers } from './utils/identifiers';\nimport { createRepairManager, type RepairManager } from './repairs';\n\nexport { isKnexQuery } from './utils/knex';\n\ninterface Settings {\n forceMigration?: boolean;\n runMigrations?: boolean;\n migrations: {\n dir: string;\n };\n [key: string]: unknown;\n}\n\nexport type Logger = Record<\n 'info' | 'warn' | 'error' | 'debug',\n (message: string | Record<string, unknown>) => void\n>;\n\nexport interface DatabaseConfig {\n connection: Knex.Config;\n settings: Settings;\n logger?: Logger;\n}\n\nconst afterCreate =\n (db: Database) =>\n (\n nativeConnection: unknown,\n done: (error: Error | null, nativeConnection: unknown) => Promise<void>\n ) => {\n // run initialize for it since commands such as postgres SET and sqlite PRAGMA are per-connection\n db.dialect.initialize(nativeConnection).then(() => {\n return done(null, nativeConnection);\n });\n };\n\nclass Database {\n connection: Knex;\n\n dialect: Dialect;\n\n config: DatabaseConfig;\n\n metadata: Metadata;\n\n schema: SchemaProvider;\n\n migrations: MigrationProvider;\n\n lifecycles: LifecycleProvider;\n\n entityManager: EntityManager;\n\n repair: RepairManager;\n\n logger: Logger;\n\n constructor(config: DatabaseConfig) {\n this.config = {\n ...config,\n settings: {\n forceMigration: true,\n runMigrations: true,\n ...(config.settings ?? {}),\n },\n };\n\n this.logger = config.logger ?? console;\n\n this.dialect = getDialect(this);\n\n let knexConfig: Knex.Config = this.config.connection;\n\n // for object connections, we can configure the dialect synchronously\n if (typeof this.config.connection.connection !== 'function') {\n this.dialect.configure();\n }\n // for connection functions, we wrap it so that we can modify it with dialect configure before it reaches knex\n else {\n this.logger.warn(\n 'Knex connection functions are currently experimental. Attempting to access the connection object before database initialization will result in errors.'\n );\n\n knexConfig = {\n ...this.config.connection,\n connection: async () => {\n // @ts-expect-error confirmed it was a function above\n const conn = await this.config.connection.connection();\n this.dialect.configure(conn);\n return conn;\n },\n };\n }\n\n this.metadata = createMetadata([]);\n\n this.connection = createConnection(knexConfig, {\n pool: { afterCreate: afterCreate(this) },\n });\n\n this.schema = createSchemaProvider(this);\n\n this.migrations = createMigrationsProvider(this);\n this.lifecycles = createLifecyclesProvider(this);\n\n this.entityManager = createEntityManager(this);\n\n this.repair = createRepairManager(this);\n }\n\n async init({ models }: { models: Model[] }) {\n if (typeof this.config.connection.connection === 'function') {\n /*\n * User code needs to be able to access `connection.connection` directly as if\n * it were always an object. For a connection function, that doesn't happen\n * until the pool is created, so we need to do that here\n *\n * TODO: In the next major version, we need to replace all internal code that\n * directly references `connection.connection` prior to init, and make a breaking\n * change that it cannot be relied on to exist before init so that we can call\n * this feature stable.\n */\n this.logger.debug('Forcing Knex to make real connection to db');\n\n // sqlite does not support connection pooling so acquireConnection doesn't work\n if (this.config.connection.client === 'sqlite') {\n await this.connection.raw('SELECT 1');\n } else {\n await this.connection.client.acquireConnection();\n }\n }\n\n this.metadata.loadModels(models);\n await validateDatabase(this);\n return this;\n }\n\n query(uid: string) {\n if (!this.metadata.has(uid)) {\n throw new Error(`Model ${uid} not found`);\n }\n\n return this.entityManager.getRepository(uid);\n }\n\n inTransaction() {\n return !!transactionCtx.get();\n }\n\n transaction(): Promise<TransactionObject>;\n transaction<TCallback extends Callback>(c: TCallback): Promise<ReturnType<TCallback>>;\n async transaction<TCallback extends Callback>(\n cb?: TCallback\n ): Promise<ReturnType<TCallback> | TransactionObject> {\n const notNestedTransaction = !transactionCtx.get();\n const trx = notNestedTransaction\n ? await this.connection.transaction()\n : (transactionCtx.get() as Knex.Transaction);\n\n async function commit() {\n if (notNestedTransaction) {\n await transactionCtx.commit(trx);\n }\n }\n\n async function rollback() {\n if (notNestedTransaction) {\n await transactionCtx.rollback(trx);\n }\n }\n\n if (!cb) {\n return { commit, rollback, get: () => trx };\n }\n\n return transactionCtx.run(trx, async () => {\n try {\n const callbackParams = {\n trx,\n commit,\n rollback,\n onCommit: transactionCtx.onCommit,\n onRollback: transactionCtx.onRollback,\n };\n const res = await cb(callbackParams);\n await commit();\n return res;\n } catch (error) {\n await rollback();\n throw error;\n }\n });\n }\n\n getSchemaName(): string | undefined {\n return this.connection.client.connectionSettings.schema;\n }\n\n getConnection(): Knex;\n getConnection(tableName?: string): Knex.QueryBuilder;\n getConnection(tableName?: string): Knex | Knex.QueryBuilder {\n const schema = this.getSchemaName();\n const connection = tableName ? this.connection(tableName) : this.connection;\n return schema ? connection.withSchema(schema) : connection;\n }\n\n // Returns basic info about the database connection\n getInfo() {\n const connectionSettings = this.connection?.client?.connectionSettings || {};\n const client = this.dialect?.client || '';\n\n let displayName = '';\n let schema;\n\n // For SQLite, get the relative filename\n if (client === 'sqlite') {\n const absolutePath = connectionSettings?.filename;\n if (absolutePath) {\n displayName = path.relative(process.cwd(), absolutePath);\n }\n }\n // For other dialects, get the database name\n else {\n displayName = connectionSettings?.database;\n schema = connectionSettings?.schema;\n }\n\n return {\n displayName,\n schema,\n client,\n };\n }\n\n getSchemaConnection(trx = this.connection) {\n const schema = this.getSchemaName();\n return schema ? trx.schema.withSchema(schema) : trx.schema;\n }\n\n queryBuilder(uid: string) {\n return this.entityManager.createQueryBuilder(uid);\n }\n\n async destroy() {\n await this.lifecycles.clear();\n await this.connection.destroy();\n }\n}\n\nexport { Database, errors };\nexport type { Model, JoinTable, Identifiers, Migration };\n"],"names":["afterCreate","db","nativeConnection","done","dialect","initialize","then","Database","init","models","config","connection","logger","debug","client","raw","acquireConnection","metadata","loadModels","validateDatabase","query","uid","has","Error","entityManager","getRepository","inTransaction","transactionCtx","get","transaction","cb","notNestedTransaction","trx","commit","rollback","run","callbackParams","onCommit","onRollback","res","error","getSchemaName","connectionSettings","schema","getConnection","tableName","withSchema","getInfo","displayName","absolutePath","filename","path","relative","process","cwd","database","getSchemaConnection","queryBuilder","createQueryBuilder","destroy","lifecycles","clear","settings","forceMigration","runMigrations","console","getDialect","knexConfig","configure","warn","conn","createMetadata","createConnection","pool","createSchemaProvider","migrations","createMigrationsProvider","createLifecyclesProvider","createEntityManager","repair","createRepairManager"],"mappings":";;;;;;;;;;;;;;;;AAwCA,MAAMA,WAAAA,GACJ,CAACC,EAAAA,GACD,CACEC,gBAAAA,EACAC,IAAAA,GAAAA;;AAGAF,QAAAA,EAAAA,CAAGG,OAAO,CAACC,UAAU,CAACH,gBAAAA,CAAAA,CAAkBI,IAAI,CAAC,IAAA;AAC3C,YAAA,OAAOH,KAAK,IAAA,EAAMD,gBAAAA,CAAAA;AACpB,QAAA,CAAA,CAAA;AACF,IAAA,CAAA;AAEF,MAAMK,QAAAA,CAAAA;AA0EJ,IAAA,MAAMC,IAAAA,CAAK,EAAEC,MAAM,EAAuB,EAAE;QAC1C,IAAI,OAAO,IAAI,CAACC,MAAM,CAACC,UAAU,CAACA,UAAU,KAAK,UAAA,EAAY;AAC3D;;;;;;;;;AASC,UACD,IAAI,CAACC,MAAM,CAACC,KAAK,CAAC,4CAAA,CAAA;;YAGlB,IAAI,IAAI,CAACH,MAAM,CAACC,UAAU,CAACG,MAAM,KAAK,QAAA,EAAU;AAC9C,gBAAA,MAAM,IAAI,CAACH,UAAU,CAACI,GAAG,CAAC,UAAA,CAAA;YAC5B,CAAA,MAAO;AACL,gBAAA,MAAM,IAAI,CAACJ,UAAU,CAACG,MAAM,CAACE,iBAAiB,EAAA;AAChD,YAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAACC,QAAQ,CAACC,UAAU,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knex';\n\nimport path from 'node:path';\n\nimport { Dialect, getDialect } from './dialects';\nimport { createSchemaProvider, SchemaProvider } from './schema';\nimport { createMetadata, Metadata } from './metadata';\nimport { createEntityManager, EntityManager } from './entity-manager';\nimport { createMigrationsProvider, MigrationProvider, type Migration } from './migrations';\nimport { createLifecyclesProvider, LifecycleProvider } from './lifecycles';\nimport { createConnection } from './connection';\nimport * as errors from './errors';\nimport { Callback, transactionCtx, TransactionObject } from './transaction-context';\nimport { validateDatabase } from './validations';\nimport type { Model, JoinTable } from './types';\nimport type { Identifiers } from './utils/identifiers';\nimport { createRepairManager, type RepairManager } from './repairs';\n\nexport { isKnexQuery } from './utils/knex';\n\ninterface Settings {\n forceMigration?: boolean;\n runMigrations?: boolean;\n migrations: {\n dir: string;\n };\n [key: string]: unknown;\n}\n\nexport type Logger = Record<\n 'info' | 'warn' | 'error' | 'debug',\n (message: string | Record<string, unknown>) => void\n>;\n\nexport interface DatabaseConfig {\n connection: Knex.Config;\n settings: Settings;\n logger?: Logger;\n}\n\nconst afterCreate =\n (db: Database) =>\n (\n nativeConnection: unknown,\n done: (error: Error | null, nativeConnection: unknown) => Promise<void>\n ) => {\n // run initialize for it since commands such as postgres SET and sqlite PRAGMA are per-connection\n db.dialect.initialize(nativeConnection).then(() => {\n return done(null, nativeConnection);\n });\n };\n\nclass Database {\n connection: Knex;\n\n dialect: Dialect;\n\n config: DatabaseConfig;\n\n metadata: Metadata;\n\n schema: SchemaProvider;\n\n migrations: MigrationProvider;\n\n lifecycles: LifecycleProvider;\n\n entityManager: EntityManager;\n\n repair: RepairManager;\n\n logger: Logger;\n\n constructor(config: DatabaseConfig) {\n this.config = {\n ...config,\n settings: {\n forceMigration: true,\n runMigrations: true,\n ...(config.settings ?? {}),\n },\n };\n\n this.logger = config.logger ?? console;\n\n this.dialect = getDialect(this);\n\n let knexConfig: Knex.Config = this.config.connection;\n\n // for object connections, we can configure the dialect synchronously\n if (typeof this.config.connection.connection !== 'function') {\n this.dialect.configure();\n }\n // for connection functions, we wrap it so that we can modify it with dialect configure before it reaches knex\n else {\n this.logger.warn(\n 'Knex connection functions are currently experimental. Attempting to access the connection object before database initialization will result in errors.'\n );\n\n knexConfig = {\n ...this.config.connection,\n connection: async () => {\n // @ts-expect-error confirmed it was a function above\n const conn = await this.config.connection.connection();\n this.dialect.configure(conn);\n return conn;\n },\n };\n }\n\n this.metadata = createMetadata([]);\n\n this.connection = createConnection(knexConfig, {\n pool: { afterCreate: afterCreate(this) },\n });\n\n this.schema = createSchemaProvider(this);\n\n this.migrations = createMigrationsProvider(this);\n this.lifecycles = createLifecyclesProvider(this);\n\n this.entityManager = createEntityManager(this);\n\n this.repair = createRepairManager(this);\n }\n\n async init({ models }: { models: Model[] }) {\n if (typeof this.config.connection.connection === 'function') {\n /*\n * User code needs to be able to access `connection.connection` directly as if\n * it were always an object. For a connection function, that doesn't happen\n * until the pool is created, so we need to do that here\n *\n * TODO: In the next major version, we need to replace all internal code that\n * directly references `connection.connection` prior to init, and make a breaking\n * change that it cannot be relied on to exist before init so that we can call\n * this feature stable.\n */\n this.logger.debug('Forcing Knex to make real connection to db');\n\n // sqlite does not support connection pooling so acquireConnection doesn't work\n if (this.config.connection.client === 'sqlite') {\n await this.connection.raw('SELECT 1');\n } else {\n await this.connection.client.acquireConnection();\n }\n }\n\n this.metadata.loadModels(models);\n await validateDatabase(this);\n return this;\n }\n\n query(uid: string) {\n if (!this.metadata.has(uid)) {\n throw new Error(`Model ${uid} not found`);\n }\n\n return this.entityManager.getRepository(uid);\n }\n\n inTransaction() {\n return !!transactionCtx.get();\n }\n\n /**\n * Run work inside a DB transaction. On a fulfilled callback, the transaction\n * is committed; on rejection, it is rolled back. The callback receives Knex\n * `commit` and `rollback` helpers: if you call `rollback` and return without\n * throwing, the implementation avoids attempting a second `commit` on an\n * already-finalised transactor.\n */\n transaction(): Promise<TransactionObject>;\n transaction<TCallback extends Callback>(c: TCallback): Promise<ReturnType<TCallback>>;\n async transaction<TCallback extends Callback>(\n cb?: TCallback\n ): Promise<ReturnType<TCallback> | TransactionObject> {\n const notNestedTransaction = !transactionCtx.get();\n const trx = notNestedTransaction\n ? await this.connection.transaction()\n : (transactionCtx.get() as Knex.Transaction);\n\n async function commit() {\n if (notNestedTransaction) {\n await transactionCtx.commit(trx);\n }\n }\n\n async function rollback() {\n if (notNestedTransaction) {\n await transactionCtx.rollback(trx);\n }\n }\n\n if (!cb) {\n return { commit, rollback, get: () => trx };\n }\n\n return transactionCtx.run(trx, async () => {\n try {\n const callbackParams = {\n trx,\n commit,\n rollback,\n onCommit: transactionCtx.onCommit,\n onRollback: transactionCtx.onRollback,\n };\n const res = await cb(callbackParams);\n await commit();\n return res;\n } catch (error) {\n await rollback();\n throw error;\n }\n });\n }\n\n getSchemaName(): string | undefined {\n return this.connection.client.connectionSettings.schema;\n }\n\n getConnection(): Knex;\n getConnection(tableName?: string): Knex.QueryBuilder;\n getConnection(tableName?: string): Knex | Knex.QueryBuilder {\n const schema = this.getSchemaName();\n const connection = tableName ? this.connection(tableName) : this.connection;\n return schema ? connection.withSchema(schema) : connection;\n }\n\n // Returns basic info about the database connection\n getInfo() {\n const connectionSettings = this.connection?.client?.connectionSettings || {};\n const client = this.dialect?.client || '';\n\n let displayName = '';\n let schema;\n\n // For SQLite, get the relative filename\n if (client === 'sqlite') {\n const absolutePath = connectionSettings?.filename;\n if (absolutePath) {\n displayName = path.relative(process.cwd(), absolutePath);\n }\n }\n // For other dialects, get the database name\n else {\n displayName = connectionSettings?.database;\n schema = connectionSettings?.schema;\n }\n\n return {\n displayName,\n schema,\n client,\n };\n }\n\n getSchemaConnection(trx = this.connection) {\n const schema = this.getSchemaName();\n return schema ? trx.schema.withSchema(schema) : trx.schema;\n }\n\n queryBuilder(uid: string) {\n return this.entityManager.createQueryBuilder(uid);\n }\n\n async destroy() {\n await this.lifecycles.clear();\n await this.connection.destroy();\n }\n}\n\nexport { Database, errors };\nexport type { Model, JoinTable, Identifiers, Migration };\n"],"names":["afterCreate","db","nativeConnection","done","dialect","initialize","then","Database","init","models","config","connection","logger","debug","client","raw","acquireConnection","metadata","loadModels","validateDatabase","query","uid","has","Error","entityManager","getRepository","inTransaction","transactionCtx","get","transaction","cb","notNestedTransaction","trx","commit","rollback","run","callbackParams","onCommit","onRollback","res","error","getSchemaName","connectionSettings","schema","getConnection","tableName","withSchema","getInfo","displayName","absolutePath","filename","path","relative","process","cwd","database","getSchemaConnection","queryBuilder","createQueryBuilder","destroy","lifecycles","clear","settings","forceMigration","runMigrations","console","getDialect","knexConfig","configure","warn","conn","createMetadata","createConnection","pool","createSchemaProvider","migrations","createMigrationsProvider","createLifecyclesProvider","createEntityManager","repair","createRepairManager"],"mappings":";;;;;;;;;;;;;;;;AAwCA,MAAMA,WAAAA,GACJ,CAACC,EAAAA,GACD,CACEC,gBAAAA,EACAC,IAAAA,GAAAA;;AAGAF,QAAAA,EAAAA,CAAGG,OAAO,CAACC,UAAU,CAACH,gBAAAA,CAAAA,CAAkBI,IAAI,CAAC,IAAA;AAC3C,YAAA,OAAOH,KAAK,IAAA,EAAMD,gBAAAA,CAAAA;AACpB,QAAA,CAAA,CAAA;AACF,IAAA,CAAA;AAEF,MAAMK,QAAAA,CAAAA;AA0EJ,IAAA,MAAMC,IAAAA,CAAK,EAAEC,MAAM,EAAuB,EAAE;QAC1C,IAAI,OAAO,IAAI,CAACC,MAAM,CAACC,UAAU,CAACA,UAAU,KAAK,UAAA,EAAY;AAC3D;;;;;;;;;AASC,UACD,IAAI,CAACC,MAAM,CAACC,KAAK,CAAC,4CAAA,CAAA;;YAGlB,IAAI,IAAI,CAACH,MAAM,CAACC,UAAU,CAACG,MAAM,KAAK,QAAA,EAAU;AAC9C,gBAAA,MAAM,IAAI,CAACH,UAAU,CAACI,GAAG,CAAC,UAAA,CAAA;YAC5B,CAAA,MAAO;AACL,gBAAA,MAAM,IAAI,CAACJ,UAAU,CAACG,MAAM,CAACE,iBAAiB,EAAA;AAChD,YAAA;AACF,QAAA;AAEA,QAAA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"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport path from 'node:path';\n\nimport { Dialect, getDialect } from './dialects';\nimport { createSchemaProvider, SchemaProvider } from './schema';\nimport { createMetadata, Metadata } from './metadata';\nimport { createEntityManager, EntityManager } from './entity-manager';\nimport { createMigrationsProvider, MigrationProvider, type Migration } from './migrations';\nimport { createLifecyclesProvider, LifecycleProvider } from './lifecycles';\nimport { createConnection } from './connection';\nimport * as errors from './errors';\nimport { Callback, transactionCtx, TransactionObject } from './transaction-context';\nimport { validateDatabase } from './validations';\nimport type { Model, JoinTable } from './types';\nimport type { Identifiers } from './utils/identifiers';\nimport { createRepairManager, type RepairManager } from './repairs';\n\nexport { isKnexQuery } from './utils/knex';\n\ninterface Settings {\n forceMigration?: boolean;\n runMigrations?: boolean;\n migrations: {\n dir: string;\n };\n [key: string]: unknown;\n}\n\nexport type Logger = Record<\n 'info' | 'warn' | 'error' | 'debug',\n (message: string | Record<string, unknown>) => void\n>;\n\nexport interface DatabaseConfig {\n connection: Knex.Config;\n settings: Settings;\n logger?: Logger;\n}\n\nconst afterCreate =\n (db: Database) =>\n (\n nativeConnection: unknown,\n done: (error: Error | null, nativeConnection: unknown) => Promise<void>\n ) => {\n // run initialize for it since commands such as postgres SET and sqlite PRAGMA are per-connection\n db.dialect.initialize(nativeConnection).then(() => {\n return done(null, nativeConnection);\n });\n };\n\nclass Database {\n connection: Knex;\n\n dialect: Dialect;\n\n config: DatabaseConfig;\n\n metadata: Metadata;\n\n schema: SchemaProvider;\n\n migrations: MigrationProvider;\n\n lifecycles: LifecycleProvider;\n\n entityManager: EntityManager;\n\n repair: RepairManager;\n\n logger: Logger;\n\n constructor(config: DatabaseConfig) {\n this.config = {\n ...config,\n settings: {\n forceMigration: true,\n runMigrations: true,\n ...(config.settings ?? {}),\n },\n };\n\n this.logger = config.logger ?? console;\n\n this.dialect = getDialect(this);\n\n let knexConfig: Knex.Config = this.config.connection;\n\n // for object connections, we can configure the dialect synchronously\n if (typeof this.config.connection.connection !== 'function') {\n this.dialect.configure();\n }\n // for connection functions, we wrap it so that we can modify it with dialect configure before it reaches knex\n else {\n this.logger.warn(\n 'Knex connection functions are currently experimental. Attempting to access the connection object before database initialization will result in errors.'\n );\n\n knexConfig = {\n ...this.config.connection,\n connection: async () => {\n // @ts-expect-error confirmed it was a function above\n const conn = await this.config.connection.connection();\n this.dialect.configure(conn);\n return conn;\n },\n };\n }\n\n this.metadata = createMetadata([]);\n\n this.connection = createConnection(knexConfig, {\n pool: { afterCreate: afterCreate(this) },\n });\n\n this.schema = createSchemaProvider(this);\n\n this.migrations = createMigrationsProvider(this);\n this.lifecycles = createLifecyclesProvider(this);\n\n this.entityManager = createEntityManager(this);\n\n this.repair = createRepairManager(this);\n }\n\n async init({ models }: { models: Model[] }) {\n if (typeof this.config.connection.connection === 'function') {\n /*\n * User code needs to be able to access `connection.connection` directly as if\n * it were always an object. For a connection function, that doesn't happen\n * until the pool is created, so we need to do that here\n *\n * TODO: In the next major version, we need to replace all internal code that\n * directly references `connection.connection` prior to init, and make a breaking\n * change that it cannot be relied on to exist before init so that we can call\n * this feature stable.\n */\n this.logger.debug('Forcing Knex to make real connection to db');\n\n // sqlite does not support connection pooling so acquireConnection doesn't work\n if (this.config.connection.client === 'sqlite') {\n await this.connection.raw('SELECT 1');\n } else {\n await this.connection.client.acquireConnection();\n }\n }\n\n this.metadata.loadModels(models);\n await validateDatabase(this);\n return this;\n }\n\n query(uid: string) {\n if (!this.metadata.has(uid)) {\n throw new Error(`Model ${uid} not found`);\n }\n\n return this.entityManager.getRepository(uid);\n }\n\n inTransaction() {\n return !!transactionCtx.get();\n }\n\n transaction(): Promise<TransactionObject>;\n transaction<TCallback extends Callback>(c: TCallback): Promise<ReturnType<TCallback>>;\n async transaction<TCallback extends Callback>(\n cb?: TCallback\n ): Promise<ReturnType<TCallback> | TransactionObject> {\n const notNestedTransaction = !transactionCtx.get();\n const trx = notNestedTransaction\n ? await this.connection.transaction()\n : (transactionCtx.get() as Knex.Transaction);\n\n async function commit() {\n if (notNestedTransaction) {\n await transactionCtx.commit(trx);\n }\n }\n\n async function rollback() {\n if (notNestedTransaction) {\n await transactionCtx.rollback(trx);\n }\n }\n\n if (!cb) {\n return { commit, rollback, get: () => trx };\n }\n\n return transactionCtx.run(trx, async () => {\n try {\n const callbackParams = {\n trx,\n commit,\n rollback,\n onCommit: transactionCtx.onCommit,\n onRollback: transactionCtx.onRollback,\n };\n const res = await cb(callbackParams);\n await commit();\n return res;\n } catch (error) {\n await rollback();\n throw error;\n }\n });\n }\n\n getSchemaName(): string | undefined {\n return this.connection.client.connectionSettings.schema;\n }\n\n getConnection(): Knex;\n getConnection(tableName?: string): Knex.QueryBuilder;\n getConnection(tableName?: string): Knex | Knex.QueryBuilder {\n const schema = this.getSchemaName();\n const connection = tableName ? this.connection(tableName) : this.connection;\n return schema ? connection.withSchema(schema) : connection;\n }\n\n // Returns basic info about the database connection\n getInfo() {\n const connectionSettings = this.connection?.client?.connectionSettings || {};\n const client = this.dialect?.client || '';\n\n let displayName = '';\n let schema;\n\n // For SQLite, get the relative filename\n if (client === 'sqlite') {\n const absolutePath = connectionSettings?.filename;\n if (absolutePath) {\n displayName = path.relative(process.cwd(), absolutePath);\n }\n }\n // For other dialects, get the database name\n else {\n displayName = connectionSettings?.database;\n schema = connectionSettings?.schema;\n }\n\n return {\n displayName,\n schema,\n client,\n };\n }\n\n getSchemaConnection(trx = this.connection) {\n const schema = this.getSchemaName();\n return schema ? trx.schema.withSchema(schema) : trx.schema;\n }\n\n queryBuilder(uid: string) {\n return this.entityManager.createQueryBuilder(uid);\n }\n\n async destroy() {\n await this.lifecycles.clear();\n await this.connection.destroy();\n }\n}\n\nexport { Database, errors };\nexport type { Model, JoinTable, Identifiers, Migration };\n"],"names":["afterCreate","db","nativeConnection","done","dialect","initialize","then","Database","init","models","config","connection","logger","debug","client","raw","acquireConnection","metadata","loadModels","validateDatabase","query","uid","has","Error","entityManager","getRepository","inTransaction","transactionCtx","get","transaction","cb","notNestedTransaction","trx","commit","rollback","run","callbackParams","onCommit","onRollback","res","error","getSchemaName","connectionSettings","schema","getConnection","tableName","withSchema","getInfo","displayName","absolutePath","filename","path","relative","process","cwd","database","getSchemaConnection","queryBuilder","createQueryBuilder","destroy","lifecycles","clear","settings","forceMigration","runMigrations","console","getDialect","knexConfig","configure","warn","conn","createMetadata","createConnection","pool","createSchemaProvider","migrations","createMigrationsProvider","createLifecyclesProvider","createEntityManager","repair","createRepairManager"],"mappings":";;;;;;;;;;;;;;;AAwCA,MAAMA,WAAAA,GACJ,CAACC,EAAAA,GACD,CACEC,gBAAAA,EACAC,IAAAA,GAAAA;;AAGAF,QAAAA,EAAAA,CAAGG,OAAO,CAACC,UAAU,CAACH,gBAAAA,CAAAA,CAAkBI,IAAI,CAAC,IAAA;AAC3C,YAAA,OAAOH,KAAK,IAAA,EAAMD,gBAAAA,CAAAA;AACpB,QAAA,CAAA,CAAA;AACF,IAAA,CAAA;AAEF,MAAMK,QAAAA,CAAAA;AA0EJ,IAAA,MAAMC,IAAAA,CAAK,EAAEC,MAAM,EAAuB,EAAE;QAC1C,IAAI,OAAO,IAAI,CAACC,MAAM,CAACC,UAAU,CAACA,UAAU,KAAK,UAAA,EAAY;AAC3D;;;;;;;;;AASC,UACD,IAAI,CAACC,MAAM,CAACC,KAAK,CAAC,4CAAA,CAAA;;YAGlB,IAAI,IAAI,CAACH,MAAM,CAACC,UAAU,CAACG,MAAM,KAAK,QAAA,EAAU;AAC9C,gBAAA,MAAM,IAAI,CAACH,UAAU,CAACI,GAAG,CAAC,UAAA,CAAA;YAC5B,CAAA,MAAO;AACL,gBAAA,MAAM,IAAI,CAACJ,UAAU,CAACG,MAAM,CAACE,iBAAiB,EAAA;AAChD,YAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAACC,QAAQ,CAACC,UAAU,CAACT,MAAAA,CAAAA;AACzB,QAAA,MAAMU,iBAAiB,IAAI,CAAA;AAC3B,QAAA,OA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,IAAI,CAACD,MAAM,CAACC,UAAU,CAACA,UAAU,KAAK,UAAA,EAAY;YAC3D,IAAI,CAACP,OAAO,CAACgE,SAAS,EAAA;QACxB,CAAA,MAEK;AACH,YAAA,IAAI,CAACxD,MAAM,CAACyD,IAAI,CACd,wJAAA,CAAA;YAGFF,UAAAA,GAAa;AACX,gBAAA,GAAG,IAAI,CAACzD,MAAM,CAACC,UAAU;gBACzBA,UAAAA,EAAY,UAAA;;oBAEV,MAAM2D,IAAAA,GAAO,MAAM,IAAI,CAAC5D,MAAM,CAACC,UAAU,CAACA,UAAU,EAAA;AACpD,oBAAA,IAAI,CAACP,OAAO,CAACgE,SAAS,CAACE,IAAAA,CAAAA;oBACvB,OAAOA,IAAAA;AACT,gBAAA;AACF,aAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAACrD,QAAQ,GAAGsD,cAAAA,CAAe,EAAE,CAAA;AAEjC,QAAA,IAAI,CAAC5D,UAAU,GAAG6D,gBAAAA,CAAiBL,UAAAA,EAAY;YAC7CM,IAAAA,EAAM;AAAEzE,gBAAAA,WAAAA,EAAaA,YAAY,IAAI;AAAE;AACzC,SAAA,CAAA;AAEA,QAAA,IAAI,CAAC2C,MAAM,GAAG+B,oBAAAA,CAAqB,IAAI,CAAA;AAEvC,QAAA,IAAI,CAACC,UAAU,GAAGC,wBAAAA,CAAyB,IAAI,CAAA;AAC/C,QAAA,IAAI,CAAChB,UAAU,GAAGiB,wBAAAA,CAAyB,IAAI,CAAA;AAE/C,QAAA,IAAI,CAACrD,aAAa,GAAGsD,mBAAAA,CAAoB,IAAI,CAAA;AAE7C,QAAA,IAAI,CAACC,MAAM,GAAGC,mBAAAA,CAAoB,IAAI,CAAA;AACxC,IAAA;AA2IF;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport path from 'node:path';\n\nimport { Dialect, getDialect } from './dialects';\nimport { createSchemaProvider, SchemaProvider } from './schema';\nimport { createMetadata, Metadata } from './metadata';\nimport { createEntityManager, EntityManager } from './entity-manager';\nimport { createMigrationsProvider, MigrationProvider, type Migration } from './migrations';\nimport { createLifecyclesProvider, LifecycleProvider } from './lifecycles';\nimport { createConnection } from './connection';\nimport * as errors from './errors';\nimport { Callback, transactionCtx, TransactionObject } from './transaction-context';\nimport { validateDatabase } from './validations';\nimport type { Model, JoinTable } from './types';\nimport type { Identifiers } from './utils/identifiers';\nimport { createRepairManager, type RepairManager } from './repairs';\n\nexport { isKnexQuery } from './utils/knex';\n\ninterface Settings {\n forceMigration?: boolean;\n runMigrations?: boolean;\n migrations: {\n dir: string;\n };\n [key: string]: unknown;\n}\n\nexport type Logger = Record<\n 'info' | 'warn' | 'error' | 'debug',\n (message: string | Record<string, unknown>) => void\n>;\n\nexport interface DatabaseConfig {\n connection: Knex.Config;\n settings: Settings;\n logger?: Logger;\n}\n\nconst afterCreate =\n (db: Database) =>\n (\n nativeConnection: unknown,\n done: (error: Error | null, nativeConnection: unknown) => Promise<void>\n ) => {\n // run initialize for it since commands such as postgres SET and sqlite PRAGMA are per-connection\n db.dialect.initialize(nativeConnection).then(() => {\n return done(null, nativeConnection);\n });\n };\n\nclass Database {\n connection: Knex;\n\n dialect: Dialect;\n\n config: DatabaseConfig;\n\n metadata: Metadata;\n\n schema: SchemaProvider;\n\n migrations: MigrationProvider;\n\n lifecycles: LifecycleProvider;\n\n entityManager: EntityManager;\n\n repair: RepairManager;\n\n logger: Logger;\n\n constructor(config: DatabaseConfig) {\n this.config = {\n ...config,\n settings: {\n forceMigration: true,\n runMigrations: true,\n ...(config.settings ?? {}),\n },\n };\n\n this.logger = config.logger ?? console;\n\n this.dialect = getDialect(this);\n\n let knexConfig: Knex.Config = this.config.connection;\n\n // for object connections, we can configure the dialect synchronously\n if (typeof this.config.connection.connection !== 'function') {\n this.dialect.configure();\n }\n // for connection functions, we wrap it so that we can modify it with dialect configure before it reaches knex\n else {\n this.logger.warn(\n 'Knex connection functions are currently experimental. Attempting to access the connection object before database initialization will result in errors.'\n );\n\n knexConfig = {\n ...this.config.connection,\n connection: async () => {\n // @ts-expect-error confirmed it was a function above\n const conn = await this.config.connection.connection();\n this.dialect.configure(conn);\n return conn;\n },\n };\n }\n\n this.metadata = createMetadata([]);\n\n this.connection = createConnection(knexConfig, {\n pool: { afterCreate: afterCreate(this) },\n });\n\n this.schema = createSchemaProvider(this);\n\n this.migrations = createMigrationsProvider(this);\n this.lifecycles = createLifecyclesProvider(this);\n\n this.entityManager = createEntityManager(this);\n\n this.repair = createRepairManager(this);\n }\n\n async init({ models }: { models: Model[] }) {\n if (typeof this.config.connection.connection === 'function') {\n /*\n * User code needs to be able to access `connection.connection` directly as if\n * it were always an object. For a connection function, that doesn't happen\n * until the pool is created, so we need to do that here\n *\n * TODO: In the next major version, we need to replace all internal code that\n * directly references `connection.connection` prior to init, and make a breaking\n * change that it cannot be relied on to exist before init so that we can call\n * this feature stable.\n */\n this.logger.debug('Forcing Knex to make real connection to db');\n\n // sqlite does not support connection pooling so acquireConnection doesn't work\n if (this.config.connection.client === 'sqlite') {\n await this.connection.raw('SELECT 1');\n } else {\n await this.connection.client.acquireConnection();\n }\n }\n\n this.metadata.loadModels(models);\n await validateDatabase(this);\n return this;\n }\n\n query(uid: string) {\n if (!this.metadata.has(uid)) {\n throw new Error(`Model ${uid} not found`);\n }\n\n return this.entityManager.getRepository(uid);\n }\n\n inTransaction() {\n return !!transactionCtx.get();\n }\n\n /**\n * Run work inside a DB transaction. On a fulfilled callback, the transaction\n * is committed; on rejection, it is rolled back. The callback receives Knex\n * `commit` and `rollback` helpers: if you call `rollback` and return without\n * throwing, the implementation avoids attempting a second `commit` on an\n * already-finalised transactor.\n */\n transaction(): Promise<TransactionObject>;\n transaction<TCallback extends Callback>(c: TCallback): Promise<ReturnType<TCallback>>;\n async transaction<TCallback extends Callback>(\n cb?: TCallback\n ): Promise<ReturnType<TCallback> | TransactionObject> {\n const notNestedTransaction = !transactionCtx.get();\n const trx = notNestedTransaction\n ? await this.connection.transaction()\n : (transactionCtx.get() as Knex.Transaction);\n\n async function commit() {\n if (notNestedTransaction) {\n await transactionCtx.commit(trx);\n }\n }\n\n async function rollback() {\n if (notNestedTransaction) {\n await transactionCtx.rollback(trx);\n }\n }\n\n if (!cb) {\n return { commit, rollback, get: () => trx };\n }\n\n return transactionCtx.run(trx, async () => {\n try {\n const callbackParams = {\n trx,\n commit,\n rollback,\n onCommit: transactionCtx.onCommit,\n onRollback: transactionCtx.onRollback,\n };\n const res = await cb(callbackParams);\n await commit();\n return res;\n } catch (error) {\n await rollback();\n throw error;\n }\n });\n }\n\n getSchemaName(): string | undefined {\n return this.connection.client.connectionSettings.schema;\n }\n\n getConnection(): Knex;\n getConnection(tableName?: string): Knex.QueryBuilder;\n getConnection(tableName?: string): Knex | Knex.QueryBuilder {\n const schema = this.getSchemaName();\n const connection = tableName ? this.connection(tableName) : this.connection;\n return schema ? connection.withSchema(schema) : connection;\n }\n\n // Returns basic info about the database connection\n getInfo() {\n const connectionSettings = this.connection?.client?.connectionSettings || {};\n const client = this.dialect?.client || '';\n\n let displayName = '';\n let schema;\n\n // For SQLite, get the relative filename\n if (client === 'sqlite') {\n const absolutePath = connectionSettings?.filename;\n if (absolutePath) {\n displayName = path.relative(process.cwd(), absolutePath);\n }\n }\n // For other dialects, get the database name\n else {\n displayName = connectionSettings?.database;\n schema = connectionSettings?.schema;\n }\n\n return {\n displayName,\n schema,\n client,\n };\n }\n\n getSchemaConnection(trx = this.connection) {\n const schema = this.getSchemaName();\n return schema ? trx.schema.withSchema(schema) : trx.schema;\n }\n\n queryBuilder(uid: string) {\n return this.entityManager.createQueryBuilder(uid);\n }\n\n async destroy() {\n await this.lifecycles.clear();\n await this.connection.destroy();\n }\n}\n\nexport { Database, errors };\nexport type { Model, JoinTable, Identifiers, Migration };\n"],"names":["afterCreate","db","nativeConnection","done","dialect","initialize","then","Database","init","models","config","connection","logger","debug","client","raw","acquireConnection","metadata","loadModels","validateDatabase","query","uid","has","Error","entityManager","getRepository","inTransaction","transactionCtx","get","transaction","cb","notNestedTransaction","trx","commit","rollback","run","callbackParams","onCommit","onRollback","res","error","getSchemaName","connectionSettings","schema","getConnection","tableName","withSchema","getInfo","displayName","absolutePath","filename","path","relative","process","cwd","database","getSchemaConnection","queryBuilder","createQueryBuilder","destroy","lifecycles","clear","settings","forceMigration","runMigrations","console","getDialect","knexConfig","configure","warn","conn","createMetadata","createConnection","pool","createSchemaProvider","migrations","createMigrationsProvider","createLifecyclesProvider","createEntityManager","repair","createRepairManager"],"mappings":";;;;;;;;;;;;;;;AAwCA,MAAMA,WAAAA,GACJ,CAACC,EAAAA,GACD,CACEC,gBAAAA,EACAC,IAAAA,GAAAA;;AAGAF,QAAAA,EAAAA,CAAGG,OAAO,CAACC,UAAU,CAACH,gBAAAA,CAAAA,CAAkBI,IAAI,CAAC,IAAA;AAC3C,YAAA,OAAOH,KAAK,IAAA,EAAMD,gBAAAA,CAAAA;AACpB,QAAA,CAAA,CAAA;AACF,IAAA,CAAA;AAEF,MAAMK,QAAAA,CAAAA;AA0EJ,IAAA,MAAMC,IAAAA,CAAK,EAAEC,MAAM,EAAuB,EAAE;QAC1C,IAAI,OAAO,IAAI,CAACC,MAAM,CAACC,UAAU,CAACA,UAAU,KAAK,UAAA,EAAY;AAC3D;;;;;;;;;AASC,UACD,IAAI,CAACC,MAAM,CAACC,KAAK,CAAC,4CAAA,CAAA;;YAGlB,IAAI,IAAI,CAACH,MAAM,CAACC,UAAU,CAACG,MAAM,KAAK,QAAA,EAAU;AAC9C,gBAAA,MAAM,IAAI,CAACH,UAAU,CAACI,GAAG,CAAC,UAAA,CAAA;YAC5B,CAAA,MAAO;AACL,gBAAA,MAAM,IAAI,CAACJ,UAAU,CAACG,MAAM,CAACE,iBAAiB,EAAA;AAChD,YAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAACC,QAAQ,CAACC,UAAU,CAACT,MAAAA,CAAAA;AACzB,QAAA,MAAMU,iBAAiB,IAAI,CA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QAGpD,IAAI,OAAO,IAAI,CAACD,MAAM,CAACC,UAAU,CAACA,UAAU,KAAK,UAAA,EAAY;YAC3D,IAAI,CAACP,OAAO,CAACgE,SAAS,EAAA;QACxB,CAAA,MAEK;AACH,YAAA,IAAI,CAACxD,MAAM,CAACyD,IAAI,CACd,wJAAA,CAAA;YAGFF,UAAAA,GAAa;AACX,gBAAA,GAAG,IAAI,CAACzD,MAAM,CAACC,UAAU;gBACzBA,UAAAA,EAAY,UAAA;;oBAEV,MAAM2D,IAAAA,GAAO,MAAM,IAAI,CAAC5D,MAAM,CAACC,UAAU,CAACA,UAAU,EAAA;AACpD,oBAAA,IAAI,CAACP,OAAO,CAACgE,SAAS,CAACE,IAAAA,CAAAA;oBACvB,OAAOA,IAAAA;AACT,gBAAA;AACF,aAAA;AACF,QAAA;AAEA,QAAA,IAAI,CAACrD,QAAQ,GAAGsD,cAAAA,CAAe,EAAE,CAAA;AAEjC,QAAA,IAAI,CAAC5D,UAAU,GAAG6D,gBAAAA,CAAiBL,UAAAA,EAAY;YAC7CM,IAAAA,EAAM;AAAEzE,gBAAAA,WAAAA,EAAaA,YAAY,IAAI;AAAE;AACzC,SAAA,CAAA;AAEA,QAAA,IAAI,CAAC2C,MAAM,GAAG+B,oBAAAA,CAAqB,IAAI,CAAA;AAEvC,QAAA,IAAI,CAACC,UAAU,GAAGC,wBAAAA,CAAyB,IAAI,CAAA;AAC/C,QAAA,IAAI,CAAChB,UAAU,GAAGiB,wBAAAA,CAAyB,IAAI,CAAA;AAE/C,QAAA,IAAI,CAACrD,aAAa,GAAGsD,mBAAAA,CAAoB,IAAI,CAAA;AAE7C,QAAA,IAAI,CAACC,MAAM,GAAGC,mBAAAA,CAAoB,IAAI,CAAA;AACxC,IAAA;AAkJF;;;;"}
@@ -1,3 +1,8 @@
1
1
  import type { Migration } from '../common';
2
+ /**
3
+ * Previously created secondary indexes on `document_id` (and composites) via raw DDL.
4
+ * Those indexes are now owned by schema sync from model metadata (see transform-content-types-to-models).
5
+ * Keep this migration as a stable no-op so Umzug / `strapi_migrations_internal` stay consistent.
6
+ */
2
7
  export declare const addDocumentIdIndexes: Migration;
3
8
  //# sourceMappingURL=5.0.0-06-add-document-id-indexes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-06-add-document-id-indexes.d.ts","sourceRoot":"","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAgE3C,eAAO,MAAM,oBAAoB,EAAE,SAelC,CAAC"}
1
+ {"version":3,"file":"5.0.0-06-add-document-id-indexes.d.ts","sourceRoot":"","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;GAIG;AAEH,eAAO,MAAM,oBAAoB,EAAE,SAQlC,CAAC"}
@@ -1,64 +1,13 @@
1
1
  'use strict';
2
2
 
3
- // Add an index if it does not already exist
4
- const createIndex = async (knex, tableName, columns, indexName)=>{
5
- try {
6
- // If the database can check for indexes, avoid duplicates
7
- const hasIndex = knex.schema.hasIndex;
8
- if (hasIndex) {
9
- const exists = await hasIndex.call(knex.schema, tableName, indexName);
10
- if (exists) {
11
- return;
12
- }
13
- }
14
- await knex.schema.alterTable(tableName, (table)=>{
15
- table.index(columns, indexName);
16
- });
17
- } catch (error) {
18
- // If the index exists (or cannot be created), move on
19
- }
20
- };
21
- const addIndexesForTable = async (knex, tableName)=>{
22
- // Only add indexes when the column is present
23
- const hasDocumentId = await knex.schema.hasColumn(tableName, 'document_id');
24
- if (!hasDocumentId) {
25
- return;
26
- }
27
- const hasLocale = await knex.schema.hasColumn(tableName, 'locale');
28
- const hasPublishedAt = await knex.schema.hasColumn(tableName, 'published_at');
29
- // Single column index for basic lookups
30
- await createIndex(knex, tableName, [
31
- 'document_id'
32
- ], `${tableName}_document_id_idx`);
33
- if (hasLocale && hasPublishedAt) {
34
- // Composite index for common filters
35
- await createIndex(knex, tableName, [
36
- 'document_id',
37
- 'locale',
38
- 'published_at'
39
- ], `${tableName}_document_id_locale_published_at_idx`);
40
- } else if (hasLocale) {
41
- await createIndex(knex, tableName, [
42
- 'document_id',
43
- 'locale'
44
- ], `${tableName}_document_id_locale_idx`);
45
- } else if (hasPublishedAt) {
46
- await createIndex(knex, tableName, [
47
- 'document_id',
48
- 'published_at'
49
- ], `${tableName}_document_id_published_at_idx`);
50
- }
51
- };
52
- const addDocumentIdIndexes = {
3
+ /**
4
+ * Previously created secondary indexes on `document_id` (and composites) via raw DDL.
5
+ * Those indexes are now owned by schema sync from model metadata (see transform-content-types-to-models).
6
+ * Keep this migration as a stable no-op so Umzug / `strapi_migrations_internal` stay consistent.
7
+ */ const addDocumentIdIndexes = {
53
8
  name: '5.0.0-06-add-document-id-indexes',
54
- async up (knex, db) {
55
- for (const meta of db.metadata.values()){
56
- const hasTable = await knex.schema.hasTable(meta.tableName);
57
- if (!hasTable) {
58
- continue;
59
- }
60
- await addIndexesForTable(knex, meta.tableName);
61
- }
9
+ async up () {
10
+ // No-op: the document_id indexes are now created by schema sync (see transform-content-types-to-models).
62
11
  },
63
12
  async down () {
64
13
  throw new Error('not implemented');
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-06-add-document-id-indexes.js","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n// Add an index if it does not already exist\nconst createIndex = async (knex: Knex, tableName: string, columns: string[], indexName: string) => {\n try {\n // If the database can check for indexes, avoid duplicates\n const hasIndex = (\n knex.schema as unknown as {\n hasIndex?: (tableName: string, indexName: string) => Promise<boolean>;\n }\n ).hasIndex;\n if (hasIndex) {\n const exists = await hasIndex.call(knex.schema, tableName, indexName);\n if (exists) {\n return;\n }\n }\n\n await knex.schema.alterTable(tableName, (table) => {\n table.index(columns, indexName);\n });\n } catch (error) {\n // If the index exists (or cannot be created), move on\n }\n};\n\nconst addIndexesForTable = async (knex: Knex, tableName: string) => {\n // Only add indexes when the column is present\n const hasDocumentId = await knex.schema.hasColumn(tableName, 'document_id');\n if (!hasDocumentId) {\n return;\n }\n\n const hasLocale = await knex.schema.hasColumn(tableName, 'locale');\n const hasPublishedAt = await knex.schema.hasColumn(tableName, 'published_at');\n\n // Single column index for basic lookups\n await createIndex(knex, tableName, ['document_id'], `${tableName}_document_id_idx`);\n\n if (hasLocale && hasPublishedAt) {\n // Composite index for common filters\n await createIndex(\n knex,\n tableName,\n ['document_id', 'locale', 'published_at'],\n `${tableName}_document_id_locale_published_at_idx`\n );\n } else if (hasLocale) {\n await createIndex(\n knex,\n tableName,\n ['document_id', 'locale'],\n `${tableName}_document_id_locale_idx`\n );\n } else if (hasPublishedAt) {\n await createIndex(\n knex,\n tableName,\n ['document_id', 'published_at'],\n `${tableName}_document_id_published_at_idx`\n );\n }\n};\n\nexport const addDocumentIdIndexes: Migration = {\n name: '5.0.0-06-add-document-id-indexes',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n if (!hasTable) {\n continue;\n }\n\n await addIndexesForTable(knex, meta.tableName);\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createIndex","knex","tableName","columns","indexName","hasIndex","schema","exists","call","alterTable","table","index","error","addIndexesForTable","hasDocumentId","hasColumn","hasLocale","hasPublishedAt","addDocumentIdIndexes","name","up","db","meta","metadata","values","hasTable","down","Error"],"mappings":";;AAIA;AACA,MAAMA,WAAAA,GAAc,OAAOC,IAAAA,EAAYC,SAAAA,EAAmBC,OAAAA,EAAmBC,SAAAA,GAAAA;IAC3E,IAAI;;AAEF,QAAA,MAAMC,QAAAA,GACJJ,IAAAA,CAAKK,MAAM,CAGXD,QAAQ;AACV,QAAA,IAAIA,QAAAA,EAAU;YACZ,MAAME,MAAA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;AAAC,YAAA,aAAA;AAAe,YAAA;SAAS,EACzB,CAAA,EAAGA,SAAAA,CAAU,uBAAuB,CAAC,CAAA;AAEzC,IAAA,CAAA,MAAO,IAAIe,cAAAA,EAAgB;QACzB,MAAMjB,WAAAA,CACJC,MACAC,SAAAA,EACA;AAAC,YAAA,aAAA;AAAe,YAAA;SAAe,EAC/B,CAAA,EAAGA,SAAAA,CAAU,6BAA6B,CAAC,CAAA;AAE/C,IAAA;AACF,CAAA;MAEagB,oBAAAA,GAAkC;IAC7CC,IAAAA,EAAM,kCAAA;IACN,MAAMC,EAAAA,CAAAA,CAAGnB,IAAI,EAAEoB,EAAE,EAAA;AACf,QAAA,KAAK,MAAMC,IAAAA,IAAQD,EAAAA,CAAGE,QAAQ,CAACC,MAAM,EAAA,CAAI;YACvC,MAAMC,QAAAA,GAAW,MAAMxB,IAAAA,CAAKK,MAAM,CAACmB,QAAQ,CAACH,KAAKpB,SAAS,CAAA;AAC1D,YAAA,IAAI,CAACuB,QAAAA,EAAU;AACb,gBAAA;AACF,YAAA;YAEA,MAAMZ,kBAAAA,CAAmBZ,IAAAA,EAAMqB,IAAAA,CAAKpB,SAAS,CAAA;AAC/C,QAAA;AACF,IAAA,CAAA;IACA,MAAMwB,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
1
+ {"version":3,"file":"5.0.0-06-add-document-id-indexes.js","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"sourcesContent":["import type { Migration } from '../common';\n\n/**\n * Previously created secondary indexes on `document_id` (and composites) via raw DDL.\n * Those indexes are now owned by schema sync from model metadata (see transform-content-types-to-models).\n * Keep this migration as a stable no-op so Umzug / `strapi_migrations_internal` stay consistent.\n */\n\nexport const addDocumentIdIndexes: Migration = {\n name: '5.0.0-06-add-document-id-indexes',\n async up() {\n // No-op: the document_id indexes are now created by schema sync (see transform-content-types-to-models).\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["addDocumentIdIndexes","name","up","down","Error"],"mappings":";;AAEA;;;;UAMaA,oBAAAA,GAAkC;IAC7CC,IAAAA,EAAM,kCAAA;IACN,MAAMC,EAAAA,CAAAA,GAAAA;;AAEN,IAAA,CAAA;IACA,MAAMC,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
@@ -1,62 +1,11 @@
1
- // Add an index if it does not already exist
2
- const createIndex = async (knex, tableName, columns, indexName)=>{
3
- try {
4
- // If the database can check for indexes, avoid duplicates
5
- const hasIndex = knex.schema.hasIndex;
6
- if (hasIndex) {
7
- const exists = await hasIndex.call(knex.schema, tableName, indexName);
8
- if (exists) {
9
- return;
10
- }
11
- }
12
- await knex.schema.alterTable(tableName, (table)=>{
13
- table.index(columns, indexName);
14
- });
15
- } catch (error) {
16
- // If the index exists (or cannot be created), move on
17
- }
18
- };
19
- const addIndexesForTable = async (knex, tableName)=>{
20
- // Only add indexes when the column is present
21
- const hasDocumentId = await knex.schema.hasColumn(tableName, 'document_id');
22
- if (!hasDocumentId) {
23
- return;
24
- }
25
- const hasLocale = await knex.schema.hasColumn(tableName, 'locale');
26
- const hasPublishedAt = await knex.schema.hasColumn(tableName, 'published_at');
27
- // Single column index for basic lookups
28
- await createIndex(knex, tableName, [
29
- 'document_id'
30
- ], `${tableName}_document_id_idx`);
31
- if (hasLocale && hasPublishedAt) {
32
- // Composite index for common filters
33
- await createIndex(knex, tableName, [
34
- 'document_id',
35
- 'locale',
36
- 'published_at'
37
- ], `${tableName}_document_id_locale_published_at_idx`);
38
- } else if (hasLocale) {
39
- await createIndex(knex, tableName, [
40
- 'document_id',
41
- 'locale'
42
- ], `${tableName}_document_id_locale_idx`);
43
- } else if (hasPublishedAt) {
44
- await createIndex(knex, tableName, [
45
- 'document_id',
46
- 'published_at'
47
- ], `${tableName}_document_id_published_at_idx`);
48
- }
49
- };
50
- const addDocumentIdIndexes = {
1
+ /**
2
+ * Previously created secondary indexes on `document_id` (and composites) via raw DDL.
3
+ * Those indexes are now owned by schema sync from model metadata (see transform-content-types-to-models).
4
+ * Keep this migration as a stable no-op so Umzug / `strapi_migrations_internal` stay consistent.
5
+ */ const addDocumentIdIndexes = {
51
6
  name: '5.0.0-06-add-document-id-indexes',
52
- async up (knex, db) {
53
- for (const meta of db.metadata.values()){
54
- const hasTable = await knex.schema.hasTable(meta.tableName);
55
- if (!hasTable) {
56
- continue;
57
- }
58
- await addIndexesForTable(knex, meta.tableName);
59
- }
7
+ async up () {
8
+ // No-op: the document_id indexes are now created by schema sync (see transform-content-types-to-models).
60
9
  },
61
10
  async down () {
62
11
  throw new Error('not implemented');
@@ -1 +1 @@
1
- {"version":3,"file":"5.0.0-06-add-document-id-indexes.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n// Add an index if it does not already exist\nconst createIndex = async (knex: Knex, tableName: string, columns: string[], indexName: string) => {\n try {\n // If the database can check for indexes, avoid duplicates\n const hasIndex = (\n knex.schema as unknown as {\n hasIndex?: (tableName: string, indexName: string) => Promise<boolean>;\n }\n ).hasIndex;\n if (hasIndex) {\n const exists = await hasIndex.call(knex.schema, tableName, indexName);\n if (exists) {\n return;\n }\n }\n\n await knex.schema.alterTable(tableName, (table) => {\n table.index(columns, indexName);\n });\n } catch (error) {\n // If the index exists (or cannot be created), move on\n }\n};\n\nconst addIndexesForTable = async (knex: Knex, tableName: string) => {\n // Only add indexes when the column is present\n const hasDocumentId = await knex.schema.hasColumn(tableName, 'document_id');\n if (!hasDocumentId) {\n return;\n }\n\n const hasLocale = await knex.schema.hasColumn(tableName, 'locale');\n const hasPublishedAt = await knex.schema.hasColumn(tableName, 'published_at');\n\n // Single column index for basic lookups\n await createIndex(knex, tableName, ['document_id'], `${tableName}_document_id_idx`);\n\n if (hasLocale && hasPublishedAt) {\n // Composite index for common filters\n await createIndex(\n knex,\n tableName,\n ['document_id', 'locale', 'published_at'],\n `${tableName}_document_id_locale_published_at_idx`\n );\n } else if (hasLocale) {\n await createIndex(\n knex,\n tableName,\n ['document_id', 'locale'],\n `${tableName}_document_id_locale_idx`\n );\n } else if (hasPublishedAt) {\n await createIndex(\n knex,\n tableName,\n ['document_id', 'published_at'],\n `${tableName}_document_id_published_at_idx`\n );\n }\n};\n\nexport const addDocumentIdIndexes: Migration = {\n name: '5.0.0-06-add-document-id-indexes',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n if (!hasTable) {\n continue;\n }\n\n await addIndexesForTable(knex, meta.tableName);\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createIndex","knex","tableName","columns","indexName","hasIndex","schema","exists","call","alterTable","table","index","error","addIndexesForTable","hasDocumentId","hasColumn","hasLocale","hasPublishedAt","addDocumentIdIndexes","name","up","db","meta","metadata","values","hasTable","down","Error"],"mappings":"AAIA;AACA,MAAMA,WAAAA,GAAc,OAAOC,IAAAA,EAAYC,SAAAA,EAAmBC,OAAAA,EAAmBC,SAAAA,GAAAA;IAC3E,IAAI;;AAEF,QAAA,MAAMC,QAAAA,GACJJ,IAAAA,CAAKK,MAAM,CAGXD,QAAQ;AACV,QAAA,IAAIA,QAAAA,EAAU;YACZ,MAAME,MAAAA,GAAS,MAAMF,QAAAA,CAASG,IAAI,CAACP,IAAAA,CAAKK,MAAM,EAAEJ,SAAAA,EAAWE,SAAAA,CAAAA;AAC3D,YAAA,IAAIG,MAAAA,EAAQ;AACV,gBAAA;AACF,YAAA;AACF,QAAA;AAEA,QAAA,MAAMN,KAAKK,MAAM,CAACG,UAAU,CAACP,WAAW,CAACQ,KAAAA,GAAAA;YACvCA,KAAAA,CAAMC,KAAK,CAACR,OAAAA,EAASC,SAAAA,CAAAA;AACvB,QAAA,CAAA,CAAA;AACF,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EAAM,kCAAA;IACN,MAAMC,EAAAA,CAAAA,CAAGnB,IAAI,EAAEoB,EAAE,EAAA;AACf,QAAA,KAAK,MAAMC,IAAAA,IAAQD,EAAAA,CAAGE,QAAQ,CAACC,MAAM,EAAA,CAAI;YACvC,MAAMC,QAAAA,GAAW,MAAMxB,IAAAA,CAAKK,MAAM,CAACmB,QAAQ,CAACH,KAAKpB,SAAS,CAAA;AAC1D,YAAA,IAAI,CAACuB,QAAAA,EAAU;AACb,gBAAA;AACF,YAAA;YAEA,MAAMZ,kBAAAA,CAAmBZ,IAAAA,EAAMqB,IAAAA,CAAKpB,SAAS,CAAA;AAC/C,QAAA;AACF,IAAA,CAAA;IACA,MAAMwB,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
1
+ {"version":3,"file":"5.0.0-06-add-document-id-indexes.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.ts"],"sourcesContent":["import type { Migration } from '../common';\n\n/**\n * Previously created secondary indexes on `document_id` (and composites) via raw DDL.\n * Those indexes are now owned by schema sync from model metadata (see transform-content-types-to-models).\n * Keep this migration as a stable no-op so Umzug / `strapi_migrations_internal` stay consistent.\n */\n\nexport const addDocumentIdIndexes: Migration = {\n name: '5.0.0-06-add-document-id-indexes',\n async up() {\n // No-op: the document_id indexes are now created by schema sync (see transform-content-types-to-models).\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["addDocumentIdIndexes","name","up","down","Error"],"mappings":"AAEA;;;;UAMaA,oBAAAA,GAAkC;IAC7CC,IAAAA,EAAM,kCAAA;IACN,MAAMC,EAAAA,CAAAA,GAAAA;;AAEN,IAAA,CAAA;IACA,MAAMC,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
@@ -12,7 +12,7 @@ const joinColPrefix = '__strapi';
12
12
  * When `populateValue.orderBy` is present, join-table ordering must not take precedence
13
13
  * over the target attribute sort (see query-builder join vs root orderBy ordering).
14
14
  */ const getJoinTableOrderBy = (populateValue, joinTable)=>{
15
- if (populateValue.orderBy || !joinTable.orderBy) {
15
+ if (!_.isEmpty(populateValue.orderBy) || !joinTable.orderBy) {
16
16
  return undefined;
17
17
  }
18
18
  return _.mapValues((v)=>populateValue.ordering || v, joinTable.orderBy);