@strapi/database 5.37.1 → 5.38.0
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/dist/connection.js.map +1 -1
- package/dist/connection.mjs.map +1 -1
- package/dist/dialects/dialect.js.map +1 -1
- package/dist/dialects/dialect.mjs.map +1 -1
- package/dist/dialects/index.js.map +1 -1
- package/dist/dialects/index.mjs.map +1 -1
- package/dist/dialects/mysql/database-inspector.js.map +1 -1
- package/dist/dialects/mysql/database-inspector.mjs.map +1 -1
- package/dist/dialects/mysql/index.js.map +1 -1
- package/dist/dialects/mysql/index.mjs.map +1 -1
- package/dist/dialects/mysql/schema-inspector.js.map +1 -1
- package/dist/dialects/mysql/schema-inspector.mjs.map +1 -1
- package/dist/dialects/postgresql/index.js.map +1 -1
- package/dist/dialects/postgresql/index.mjs.map +1 -1
- package/dist/dialects/postgresql/schema-inspector.js.map +1 -1
- package/dist/dialects/postgresql/schema-inspector.mjs.map +1 -1
- package/dist/dialects/sqlite/index.js.map +1 -1
- package/dist/dialects/sqlite/index.mjs.map +1 -1
- package/dist/dialects/sqlite/schema-inspector.js.map +1 -1
- package/dist/dialects/sqlite/schema-inspector.mjs.map +1 -1
- package/dist/entity-manager/entity-repository.js.map +1 -1
- package/dist/entity-manager/entity-repository.mjs.map +1 -1
- package/dist/entity-manager/index.js.map +1 -1
- package/dist/entity-manager/index.mjs +4 -4
- package/dist/entity-manager/index.mjs.map +1 -1
- package/dist/entity-manager/morph-relations.js.map +1 -1
- package/dist/entity-manager/morph-relations.mjs.map +1 -1
- package/dist/entity-manager/regular-relations.js.map +1 -1
- package/dist/entity-manager/regular-relations.mjs +1 -1
- package/dist/entity-manager/regular-relations.mjs.map +1 -1
- package/dist/entity-manager/relations-orderer.js.map +1 -1
- package/dist/entity-manager/relations-orderer.mjs.map +1 -1
- package/dist/errors/database.js.map +1 -1
- package/dist/errors/database.mjs.map +1 -1
- package/dist/errors/invalid-date.js.map +1 -1
- package/dist/errors/invalid-date.mjs.map +1 -1
- package/dist/errors/invalid-datetime.js.map +1 -1
- package/dist/errors/invalid-datetime.mjs.map +1 -1
- package/dist/errors/invalid-relation.js.map +1 -1
- package/dist/errors/invalid-relation.mjs.map +1 -1
- package/dist/errors/invalid-time.js.map +1 -1
- package/dist/errors/invalid-time.mjs.map +1 -1
- package/dist/errors/not-null.js.map +1 -1
- package/dist/errors/not-null.mjs.map +1 -1
- package/dist/fields/biginteger.js.map +1 -1
- package/dist/fields/biginteger.mjs.map +1 -1
- package/dist/fields/boolean.js.map +1 -1
- package/dist/fields/boolean.mjs.map +1 -1
- package/dist/fields/date.js.map +1 -1
- package/dist/fields/date.mjs.map +1 -1
- package/dist/fields/datetime.js.map +1 -1
- package/dist/fields/datetime.mjs.map +1 -1
- package/dist/fields/field.js.map +1 -1
- package/dist/fields/field.mjs.map +1 -1
- package/dist/fields/index.js.map +1 -1
- package/dist/fields/index.mjs.map +1 -1
- package/dist/fields/json.js.map +1 -1
- package/dist/fields/json.mjs.map +1 -1
- package/dist/fields/number.js.map +1 -1
- package/dist/fields/number.mjs.map +1 -1
- package/dist/fields/shared/parsers.js.map +1 -1
- package/dist/fields/shared/parsers.mjs +1 -1
- package/dist/fields/shared/parsers.mjs.map +1 -1
- package/dist/fields/string.js.map +1 -1
- package/dist/fields/string.mjs.map +1 -1
- package/dist/fields/time.js.map +1 -1
- package/dist/fields/time.mjs.map +1 -1
- package/dist/fields/timestamp.js.map +1 -1
- package/dist/fields/timestamp.mjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/lifecycles/index.js.map +1 -1
- package/dist/lifecycles/index.mjs.map +1 -1
- package/dist/lifecycles/subscribers/index.js.map +1 -1
- package/dist/lifecycles/subscribers/index.mjs.map +1 -1
- package/dist/lifecycles/subscribers/models-lifecycles.js.map +1 -1
- package/dist/lifecycles/subscribers/models-lifecycles.mjs.map +1 -1
- package/dist/lifecycles/subscribers/timestamps.js.map +1 -1
- package/dist/lifecycles/subscribers/timestamps.mjs.map +1 -1
- package/dist/metadata/index.js.map +1 -1
- package/dist/metadata/index.mjs.map +1 -1
- package/dist/metadata/metadata.js.map +1 -1
- package/dist/metadata/metadata.mjs.map +1 -1
- package/dist/metadata/relations.js +2 -6
- package/dist/metadata/relations.js.map +1 -1
- package/dist/metadata/relations.mjs +2 -6
- package/dist/metadata/relations.mjs.map +1 -1
- package/dist/migrations/common.js.map +1 -1
- package/dist/migrations/common.mjs.map +1 -1
- package/dist/migrations/index.js.map +1 -1
- package/dist/migrations/index.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.js.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.js.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-02-document-id.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-03-locale.js.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-03-locale.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-04-published-at.js.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-04-published-at.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.js.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.js.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-06-add-document-id-indexes.mjs.map +1 -1
- package/dist/migrations/internal-migrations/index.js.map +1 -1
- package/dist/migrations/internal-migrations/index.mjs.map +1 -1
- package/dist/migrations/internal.js.map +1 -1
- package/dist/migrations/internal.mjs.map +1 -1
- package/dist/migrations/logger.js.map +1 -1
- package/dist/migrations/logger.mjs.map +1 -1
- package/dist/migrations/storage.js.map +1 -1
- package/dist/migrations/storage.mjs.map +1 -1
- package/dist/migrations/users.js.map +1 -1
- package/dist/migrations/users.mjs.map +1 -1
- package/dist/query/helpers/join.js.map +1 -1
- package/dist/query/helpers/join.mjs.map +1 -1
- package/dist/query/helpers/order-by.js.map +1 -1
- package/dist/query/helpers/order-by.mjs.map +1 -1
- package/dist/query/helpers/populate/apply.js +3 -9
- package/dist/query/helpers/populate/apply.js.map +1 -1
- package/dist/query/helpers/populate/apply.mjs +3 -9
- package/dist/query/helpers/populate/apply.mjs.map +1 -1
- package/dist/query/helpers/populate/process.js.map +1 -1
- package/dist/query/helpers/populate/process.mjs.map +1 -1
- package/dist/query/helpers/search.js.map +1 -1
- package/dist/query/helpers/search.mjs.map +1 -1
- package/dist/query/helpers/streams/readable.js.map +1 -1
- package/dist/query/helpers/streams/readable.mjs.map +1 -1
- package/dist/query/helpers/transform.js.map +1 -1
- package/dist/query/helpers/transform.mjs.map +1 -1
- package/dist/query/helpers/where.js.map +1 -1
- package/dist/query/helpers/where.mjs.map +1 -1
- package/dist/query/query-builder.js.map +1 -1
- package/dist/query/query-builder.mjs +4 -4
- package/dist/query/query-builder.mjs.map +1 -1
- package/dist/repairs/index.js.map +1 -1
- package/dist/repairs/index.mjs.map +1 -1
- package/dist/repairs/operations/process-unidirectional-join-tables.js.map +1 -1
- package/dist/repairs/operations/process-unidirectional-join-tables.mjs.map +1 -1
- package/dist/repairs/operations/remove-orphan-morph-types.js.map +1 -1
- package/dist/repairs/operations/remove-orphan-morph-types.mjs.map +1 -1
- package/dist/schema/builder.js.map +1 -1
- package/dist/schema/builder.mjs +1 -1
- package/dist/schema/builder.mjs.map +1 -1
- package/dist/schema/diff.js.map +1 -1
- package/dist/schema/diff.mjs.map +1 -1
- package/dist/schema/index.js.map +1 -1
- package/dist/schema/index.mjs.map +1 -1
- package/dist/schema/schema.js.map +1 -1
- package/dist/schema/schema.mjs.map +1 -1
- package/dist/schema/storage.js.map +1 -1
- package/dist/schema/storage.mjs.map +1 -1
- package/dist/transaction-context.js.map +1 -1
- package/dist/transaction-context.mjs.map +1 -1
- package/dist/utils/async-curry.js.map +1 -1
- package/dist/utils/async-curry.mjs.map +1 -1
- package/dist/utils/identifiers/hash.js.map +1 -1
- package/dist/utils/identifiers/hash.mjs.map +1 -1
- package/dist/utils/identifiers/index.js.map +1 -1
- package/dist/utils/identifiers/index.mjs.map +1 -1
- package/dist/utils/knex.js.map +1 -1
- package/dist/utils/knex.mjs.map +1 -1
- package/dist/utils/types.js.map +1 -1
- package/dist/utils/types.mjs.map +1 -1
- package/dist/validations/index.js.map +1 -1
- package/dist/validations/index.mjs.map +1 -1
- package/dist/validations/relations/bidirectional.js.map +1 -1
- package/dist/validations/relations/bidirectional.mjs.map +1 -1
- package/dist/validations/relations/index.js.map +1 -1
- package/dist/validations/relations/index.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"5.0.0-01-convert-identifiers-long-than-max-length.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport createDebug from 'debug';\nimport type { Migration } from '../common';\nimport type { Metadata } from '../../metadata';\nimport { type Database } from '../..';\nimport { identifiers } from '../../utils/identifiers';\n\nconst debug = createDebug('strapi::database::migration');\n\ntype NameDiff<T> = {\n short: T;\n full: T;\n};\n\ntype IndexDiff = NameDiff<{ index: number; key: string; tableName: string; indexName: string }>;\n\n// key isn't really used except for debugging, but it's helpful to track down problems\ntype IdentifierDiffs = {\n indexes: IndexDiff[];\n tables: NameDiff<{ index: number; key: string; tableName: string }>[];\n columns: NameDiff<{ index: number; key: string; tableName: string; columnName: string }>[];\n};\n\nexport const renameIdentifiersLongerThanMaxLength: Migration = {\n name: '5.0.0-rename-identifiers-longer-than-max-length',\n async up(knex, db) {\n const md = db.metadata;\n\n const diffs = findDiffs(md);\n // migrate indexes before tables so we know to target the original tableName\n for (const indexDiff of diffs.indexes) {\n await renameIndex(knex, db, indexDiff);\n }\n\n // migrate columns before table names so we know to target the original tableName\n for (const columnDiff of diffs.columns) {\n const { full, short } = columnDiff;\n const tableName = full.tableName;\n\n const hasTable = await knex.schema.hasTable(tableName);\n\n if (hasTable) {\n // tablebuilder methods MUST be synchronous and so you cannot use async inside it, which is why we check the column here\n const hasColumn = await knex.schema.hasColumn(tableName, full.columnName);\n\n if (hasColumn) {\n await knex.schema.alterTable(tableName, async (table) => {\n debug(`renaming column ${full.columnName} to ${short.columnName}`);\n table.renameColumn(full.columnName, short.columnName);\n });\n }\n }\n }\n\n // migrate table names\n for (const tableDiff of diffs.tables) {\n const hasTable = await knex.schema.hasTable(tableDiff.full.tableName);\n\n if (hasTable) {\n debug(`renaming table ${tableDiff.full.tableName} to ${tableDiff.short.tableName}`);\n await knex.schema.renameTable(tableDiff.full.tableName, tableDiff.short.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n\nconst renameIndex = async (knex: Knex, db: Database, diff: IndexDiff) => {\n const client = db.config.connection.client;\n const short = diff.short;\n const full = diff.full;\n\n if (full.indexName === short.indexName) {\n debug(`not renaming index ${full.indexName} because name hasn't changed`);\n return;\n }\n\n // fk indexes can't be easily renamed, and will be recreated by db sync\n // if this misses something due to the loose string matching, it's not critical, it just means index will be rebuilt in db sync\n if (short.indexName.endsWith('fk') || full.indexName.endsWith('fk')) {\n return;\n }\n\n debug(`renaming index from ${full.indexName} to ${short.indexName}`);\n\n // If schema creation has never actually run before, none of these will exist, and they will throw an error\n // we have no way of running an \"if exists\" other than a per-dialect manual check, which we won't do\n // because even if it fails for some other reason, the schema sync will recreate them anyway\n // Therefore, we wrap this in a nested transaction (considering we are running this migration in a transaction)\n // so that we can suppress the error\n try {\n await knex.transaction(async (trx) => {\n if (client === 'mysql' || client === 'mariadb') {\n await knex\n .raw('ALTER TABLE ?? RENAME INDEX ?? TO ??', [\n full.tableName,\n full.indexName,\n short.indexName,\n ])\n .transacting(trx);\n } else if (client === 'pg' || client === 'postgres') {\n await knex\n .raw('ALTER INDEX ?? RENAME TO ??', [full.indexName, short.indexName])\n .transacting(trx);\n } else if (['sqlite', 'sqlite3', 'better-sqlite3'].includes(client as any)) {\n // SQLite doesn't support renaming, so rather than trying to drop/recreate we'll let db sync handle it\n debug(`SQLite does not support index renaming, not renaming index ${full.indexName}`);\n } else {\n debug(`No db client name matches, not renaming index ${full.indexName}`);\n }\n });\n } catch (err) {\n debug(`error creating index: ${JSON.stringify(err)}`);\n }\n};\n\nconst findDiffs = (shortMap: Metadata) => {\n const diffs = {\n tables: [],\n columns: [],\n indexes: [],\n } as IdentifierDiffs;\n\n const shortArr = Array.from(shortMap.entries());\n\n shortArr.forEach(([, shortObj], index) => {\n const fullTableName = identifiers.getUnshortenedName(shortObj.tableName);\n if (!fullTableName) {\n throw new Error(`Missing full table name for ${shortObj.tableName}`);\n }\n\n // find table name diffs\n if (shortObj.tableName !== fullTableName) {\n diffs.tables.push({\n full: {\n index,\n key: 'tableName',\n tableName: fullTableName,\n },\n short: {\n index,\n key: 'tableName',\n tableName: shortObj.tableName,\n },\n });\n }\n\n // find column name diffs\n // eslint-disable-next-line guard-for-in\n for (const attrKey in shortObj.attributes) {\n if (shortObj.attributes[attrKey].type === 'relation') {\n continue;\n }\n\n // TODO: add more type checks so we don't need any\n const attr = shortObj.attributes[attrKey] as any;\n const shortColumnName = attr.columnName;\n const longColumnName = identifiers.getUnshortenedName(shortColumnName);\n\n if (!shortColumnName || !longColumnName) {\n throw new Error(`missing column name(s) for attribute ${JSON.stringify(attr, null, 2)}`);\n }\n if (shortColumnName && longColumnName && shortColumnName !== longColumnName) {\n diffs.columns.push({\n short: {\n index,\n tableName: fullTableName, // NOTE: this means that we must rename columns before tables\n key: `attributes.${attrKey}`,\n columnName: shortColumnName,\n },\n full: {\n index,\n tableName: fullTableName,\n key: `attributes.${attrKey}`,\n columnName: longColumnName,\n },\n });\n }\n }\n\n // find index name diffs\n // eslint-disable-next-line guard-for-in\n for (const attrKey in shortObj.indexes) {\n const shortIndexName = shortObj.indexes[attrKey].name;\n const longIndexName = identifiers.getUnshortenedName(shortIndexName);\n if (!longIndexName) {\n throw new Error(`Missing full index name for ${shortIndexName}`);\n }\n\n if (shortIndexName && longIndexName && shortIndexName !== longIndexName) {\n diffs.indexes.push({\n short: {\n index,\n tableName: fullTableName, // NOTE: this means that we must rename columns before tables\n key: `indexes.${attrKey}`,\n indexName: shortIndexName,\n },\n full: {\n index,\n tableName: fullTableName,\n key: `indexes.${attrKey}`,\n indexName: longIndexName,\n },\n });\n }\n }\n });\n\n return diffs;\n};\n"],"names":["debug","createDebug","renameIdentifiersLongerThanMaxLength","name","up","knex","db","md","metadata","diffs","findDiffs","indexDiff","indexes","renameIndex","columnDiff","columns","full","short","tableName","hasTable","schema","hasColumn","columnName","alterTable","table","renameColumn","tableDiff","tables","renameTable","down","Error","diff","client","config","connection","indexName","endsWith","transaction","trx","raw","transacting","includes","err","JSON","stringify","shortMap","shortArr","Array","from","entries","forEach","shortObj","index","fullTableName","identifiers","getUnshortenedName","push","key","attrKey","attributes","type","attr","shortColumnName","longColumnName","shortIndexName","longIndexName"],"mappings":";;;AAOA,MAAMA,QAAQC,WAAY,CAAA,6BAAA,CAAA;MAgBbC,oCAAkD,GAAA;IAC7DC,IAAM,EAAA,iDAAA;IACN,MAAMC,EAAAA,CAAAA,CAAGC,IAAI,EAAEC,EAAE,EAAA;QACf,MAAMC,EAAAA,GAAKD,GAAGE,QAAQ;AAEtB,QAAA,MAAMC,QAAQC,SAAUH,CAAAA,EAAAA,CAAAA;;AAExB,QAAA,KAAK,MAAMI,SAAAA,IAAaF,KAAMG,CAAAA,OAAO,CAAE;YACrC,MAAMC,WAAAA,CAAYR,MAAMC,EAAIK,EAAAA,SAAAA,CAAAA;AAC9B;;AAGA,QAAA,KAAK,MAAMG,UAAAA,IAAcL,KAAMM,CAAAA,OAAO,CAAE;AACtC,YAAA,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAE,GAAGH,UAAAA;YACxB,MAAMI,SAAAA,GAAY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EC,OAAS,CAAA,CAAA;wBAC5BpC,UAAYyC,EAAAA;AACd;AACF,iBAAA,CAAA;AACF;AACF;;;AAIA,QAAA,IAAK,MAAML,OAAAA,IAAWP,QAASvC,CAAAA,OAAO,CAAE;AACtC,YAAA,MAAMoD,iBAAiBb,QAASvC,CAAAA,OAAO,CAAC8C,OAAAA,CAAQ,CAACvD,IAAI;YACrD,MAAM8D,aAAAA,GAAgBX,WAAYC,CAAAA,kBAAkB,CAACS,cAAAA,CAAAA;AACrD,YAAA,IAAI,CAACC,aAAe,EAAA;AAClB,gBAAA,MAAM,IAAInC,KAAAA,CAAM,CAAC,4BAA4B,EAAEkC,cAAgB,CAAA,CAAA,CAAA;AACjE;YAEA,IAAIA,cAAAA,IAAkBC,aAAiBD,IAAAA,cAAAA,KAAmBC,aAAe,EAAA;gBACvExD,KAAMG,CAAAA,OAAO,CAAC4C,IAAI,CAAC;oBACjBvC,KAAO,EAAA;AACLmC,wBAAAA,KAAAA;wBACAlC,SAAWmC,EAAAA,aAAAA;wBACXI,GAAK,EAAA,CAAC,QAAQ,EAAEC,OAAS,CAAA,CAAA;wBACzBvB,SAAW6B,EAAAA;AACb,qBAAA;oBACAhD,IAAM,EAAA;AACJoC,wBAAAA,KAAAA;wBACAlC,SAAWmC,EAAAA,aAAAA;wBACXI,GAAK,EAAA,CAAC,QAAQ,EAAEC,OAAS,CAAA,CAAA;wBACzBvB,SAAW8B,EAAAA;AACb;AACF,iBAAA,CAAA;AACF;AACF;AACF,KAAA,CAAA;IAEA,OAAOxD,KAAAA;AACT,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"5.0.0-01-convert-identifiers-long-than-max-length.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-01-convert-identifiers-long-than-max-length.ts"],"sourcesContent":["import type { Knex } from 'knex';\nimport createDebug from 'debug';\nimport type { Migration } from '../common';\nimport type { Metadata } from '../../metadata';\nimport { type Database } from '../..';\nimport { identifiers } from '../../utils/identifiers';\n\nconst debug = createDebug('strapi::database::migration');\n\ntype NameDiff<T> = {\n short: T;\n full: T;\n};\n\ntype IndexDiff = NameDiff<{ index: number; key: string; tableName: string; indexName: string }>;\n\n// key isn't really used except for debugging, but it's helpful to track down problems\ntype IdentifierDiffs = {\n indexes: IndexDiff[];\n tables: NameDiff<{ index: number; key: string; tableName: string }>[];\n columns: NameDiff<{ index: number; key: string; tableName: string; columnName: string }>[];\n};\n\nexport const renameIdentifiersLongerThanMaxLength: Migration = {\n name: '5.0.0-rename-identifiers-longer-than-max-length',\n async up(knex, db) {\n const md = db.metadata;\n\n const diffs = findDiffs(md);\n // migrate indexes before tables so we know to target the original tableName\n for (const indexDiff of diffs.indexes) {\n await renameIndex(knex, db, indexDiff);\n }\n\n // migrate columns before table names so we know to target the original tableName\n for (const columnDiff of diffs.columns) {\n const { full, short } = columnDiff;\n const tableName = full.tableName;\n\n const hasTable = await knex.schema.hasTable(tableName);\n\n if (hasTable) {\n // tablebuilder methods MUST be synchronous and so you cannot use async inside it, which is why we check the column here\n const hasColumn = await knex.schema.hasColumn(tableName, full.columnName);\n\n if (hasColumn) {\n await knex.schema.alterTable(tableName, async (table) => {\n debug(`renaming column ${full.columnName} to ${short.columnName}`);\n table.renameColumn(full.columnName, short.columnName);\n });\n }\n }\n }\n\n // migrate table names\n for (const tableDiff of diffs.tables) {\n const hasTable = await knex.schema.hasTable(tableDiff.full.tableName);\n\n if (hasTable) {\n debug(`renaming table ${tableDiff.full.tableName} to ${tableDiff.short.tableName}`);\n await knex.schema.renameTable(tableDiff.full.tableName, tableDiff.short.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n\nconst renameIndex = async (knex: Knex, db: Database, diff: IndexDiff) => {\n const client = db.config.connection.client;\n const short = diff.short;\n const full = diff.full;\n\n if (full.indexName === short.indexName) {\n debug(`not renaming index ${full.indexName} because name hasn't changed`);\n return;\n }\n\n // fk indexes can't be easily renamed, and will be recreated by db sync\n // if this misses something due to the loose string matching, it's not critical, it just means index will be rebuilt in db sync\n if (short.indexName.endsWith('fk') || full.indexName.endsWith('fk')) {\n return;\n }\n\n debug(`renaming index from ${full.indexName} to ${short.indexName}`);\n\n // If schema creation has never actually run before, none of these will exist, and they will throw an error\n // we have no way of running an \"if exists\" other than a per-dialect manual check, which we won't do\n // because even if it fails for some other reason, the schema sync will recreate them anyway\n // Therefore, we wrap this in a nested transaction (considering we are running this migration in a transaction)\n // so that we can suppress the error\n try {\n await knex.transaction(async (trx) => {\n if (client === 'mysql' || client === 'mariadb') {\n await knex\n .raw('ALTER TABLE ?? RENAME INDEX ?? TO ??', [\n full.tableName,\n full.indexName,\n short.indexName,\n ])\n .transacting(trx);\n } else if (client === 'pg' || client === 'postgres') {\n await knex\n .raw('ALTER INDEX ?? RENAME TO ??', [full.indexName, short.indexName])\n .transacting(trx);\n } else if (['sqlite', 'sqlite3', 'better-sqlite3'].includes(client as any)) {\n // SQLite doesn't support renaming, so rather than trying to drop/recreate we'll let db sync handle it\n debug(`SQLite does not support index renaming, not renaming index ${full.indexName}`);\n } else {\n debug(`No db client name matches, not renaming index ${full.indexName}`);\n }\n });\n } catch (err) {\n debug(`error creating index: ${JSON.stringify(err)}`);\n }\n};\n\nconst findDiffs = (shortMap: Metadata) => {\n const diffs = {\n tables: [],\n columns: [],\n indexes: [],\n } as IdentifierDiffs;\n\n const shortArr = Array.from(shortMap.entries());\n\n shortArr.forEach(([, shortObj], index) => {\n const fullTableName = identifiers.getUnshortenedName(shortObj.tableName);\n if (!fullTableName) {\n throw new Error(`Missing full table name for ${shortObj.tableName}`);\n }\n\n // find table name diffs\n if (shortObj.tableName !== fullTableName) {\n diffs.tables.push({\n full: {\n index,\n key: 'tableName',\n tableName: fullTableName,\n },\n short: {\n index,\n key: 'tableName',\n tableName: shortObj.tableName,\n },\n });\n }\n\n // find column name diffs\n // eslint-disable-next-line guard-for-in\n for (const attrKey in shortObj.attributes) {\n if (shortObj.attributes[attrKey].type === 'relation') {\n continue;\n }\n\n // TODO: add more type checks so we don't need any\n const attr = shortObj.attributes[attrKey] as any;\n const shortColumnName = attr.columnName;\n const longColumnName = identifiers.getUnshortenedName(shortColumnName);\n\n if (!shortColumnName || !longColumnName) {\n throw new Error(`missing column name(s) for attribute ${JSON.stringify(attr, null, 2)}`);\n }\n if (shortColumnName && longColumnName && shortColumnName !== longColumnName) {\n diffs.columns.push({\n short: {\n index,\n tableName: fullTableName, // NOTE: this means that we must rename columns before tables\n key: `attributes.${attrKey}`,\n columnName: shortColumnName,\n },\n full: {\n index,\n tableName: fullTableName,\n key: `attributes.${attrKey}`,\n columnName: longColumnName,\n },\n });\n }\n }\n\n // find index name diffs\n // eslint-disable-next-line guard-for-in\n for (const attrKey in shortObj.indexes) {\n const shortIndexName = shortObj.indexes[attrKey].name;\n const longIndexName = identifiers.getUnshortenedName(shortIndexName);\n if (!longIndexName) {\n throw new Error(`Missing full index name for ${shortIndexName}`);\n }\n\n if (shortIndexName && longIndexName && shortIndexName !== longIndexName) {\n diffs.indexes.push({\n short: {\n index,\n tableName: fullTableName, // NOTE: this means that we must rename columns before tables\n key: `indexes.${attrKey}`,\n indexName: shortIndexName,\n },\n full: {\n index,\n tableName: fullTableName,\n key: `indexes.${attrKey}`,\n indexName: longIndexName,\n },\n });\n }\n }\n });\n\n return diffs;\n};\n"],"names":["debug","createDebug","renameIdentifiersLongerThanMaxLength","name","up","knex","db","md","metadata","diffs","findDiffs","indexDiff","indexes","renameIndex","columnDiff","columns","full","short","tableName","hasTable","schema","hasColumn","columnName","alterTable","table","renameColumn","tableDiff","tables","renameTable","down","Error","diff","client","config","connection","indexName","endsWith","transaction","trx","raw","transacting","includes","err","JSON","stringify","shortMap","shortArr","Array","from","entries","forEach","shortObj","index","fullTableName","identifiers","getUnshortenedName","push","key","attrKey","attributes","type","attr","shortColumnName","longColumnName","shortIndexName","longIndexName"],"mappings":";;;AAOA,MAAMA,QAAQC,WAAAA,CAAY,6BAAA,CAAA;MAgBbC,oCAAAA,GAAkD;IAC7DC,IAAA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AA,EAAO;AACLmC,wBAAAA,KAAAA;wBACAlC,SAAAA,EAAWmC,aAAAA;wBACXI,GAAAA,EAAK,CAAC,QAAQ,EAAEC,OAAAA,CAAAA,CAAS;wBACzBvB,SAAAA,EAAW6B;AACb,qBAAA;oBACAhD,IAAAA,EAAM;AACJoC,wBAAAA,KAAAA;wBACAlC,SAAAA,EAAWmC,aAAAA;wBACXI,GAAAA,EAAK,CAAC,QAAQ,EAAEC,OAAAA,CAAAA,CAAS;wBACzBvB,SAAAA,EAAW8B;AACb;AACF,iBAAA,CAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA,CAAA,CAAA;IAEA,OAAOxD,KAAAA;AACT,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"5.0.0-02-document-id.js","sources":["../../../src/migrations/internal-migrations/5.0.0-02-document-id.ts"],"sourcesContent":["/**\n * NOTE: This migration avoids using the `identifiers` utility.\n * As the `5.0.0-01-convert-identifiers-long-than-max-length`\n * migration does not convert the `localizations` join tables, as they are not\n * tables that exist anymore in v5 and are not in the db metadata.\n *\n * This migration therefore relies on the fact that those tables still exist, and\n * references them directly.\n *\n * Database join table name: `categories_localizations_links`\n * Actual `identifiers` returned join table name: `categories_localizations_lnk`\n *\n */\nimport { createId } from '@paralleldrive/cuid2';\nimport { snakeCase } from 'lodash/fp';\nimport type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\nimport type { Database } from '../..';\nimport type { Meta } from '../../metadata';\n\ninterface Params {\n joinColumn: string;\n inverseJoinColumn: string;\n tableName: string;\n joinTableName: string;\n}\n\nconst QUERIES = {\n async postgres(knex: Knex, params: Params) {\n const res = await knex.raw(\n `\n SELECT :tableName:.id as id, string_agg(DISTINCT :inverseJoinColumn:::character varying, ',') as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :tableName:.id, :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n\n return res.rows;\n },\n async mysql(knex: Knex, params: Params) {\n const [res] = await knex.raw(\n `\n SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :tableName:.id, :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n\n return res;\n },\n async sqlite(knex: Knex, params: Params) {\n return knex.raw(\n `\n SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n },\n};\n\nconst getNextIdsToCreateDocumentId = async (\n db: Database,\n knex: Knex,\n {\n joinColumn,\n inverseJoinColumn,\n tableName,\n joinTableName,\n }: {\n joinColumn: string;\n inverseJoinColumn: string;\n tableName: string;\n joinTableName: string;\n }\n): Promise<number[]> => {\n const res = await QUERIES[db.dialect.client as keyof typeof QUERIES](knex, {\n joinColumn,\n inverseJoinColumn,\n tableName,\n joinTableName,\n });\n\n if (res.length > 0) {\n const row = res[0];\n const otherIds = row.other_ids\n ? row.other_ids.split(',').map((v: string) => parseInt(v, 10))\n : [];\n\n return [row.id, ...otherIds];\n }\n\n return [];\n};\n\n// Migrate document ids for tables that have localizations\nconst migrateDocumentIdsWithLocalizations = async (db: Database, knex: Knex, meta: Meta) => {\n const singularName = meta.singularName.toLowerCase();\n const joinColumn = snakeCase(`${singularName}_id`);\n const inverseJoinColumn = snakeCase(`inv_${singularName}_id`);\n let ids: number[];\n\n do {\n ids = await getNextIdsToCreateDocumentId(db, knex, {\n joinColumn,\n inverseJoinColumn,\n tableName: meta.tableName,\n joinTableName: snakeCase(`${meta.tableName}_localizations_links`),\n });\n\n if (ids.length > 0) {\n await knex(meta.tableName).update({ document_id: createId() }).whereIn('id', ids);\n }\n } while (ids.length > 0);\n};\n\n// Migrate document ids for tables that don't have localizations\nconst migrationDocumentIds = async (db: Database, knex: Knex, meta: Meta) => {\n let updatedRows: number;\n\n do {\n updatedRows = await knex(meta.tableName)\n .update({ document_id: createId() })\n .whereIn(\n 'id',\n knex(meta.tableName)\n .select('id')\n .from(knex(meta.tableName).select('id').whereNull('document_id').limit(1).as('sub_query'))\n );\n } while (updatedRows > 0);\n};\n\nconst createDocumentIdColumn = async (knex: Knex, tableName: string) => {\n await knex.schema.alterTable(tableName, (table) => {\n table.string('document_id');\n });\n};\n\nconst hasLocalizationsJoinTable = async (knex: Knex, tableName: string) => {\n const joinTableName = snakeCase(`${tableName}_localizations_links`);\n return knex.schema.hasTable(joinTableName);\n};\n\nexport const createdDocumentId: Migration = {\n name: '5.0.0-02-created-document-id',\n async up(knex, db) {\n // do sth\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n if ('documentId' in meta.attributes) {\n // add column if doesn't exist\n const hasDocumentIdColumn = await knex.schema.hasColumn(meta.tableName, 'document_id');\n\n if (hasDocumentIdColumn) {\n continue;\n }\n\n await createDocumentIdColumn(knex, meta.tableName);\n\n if (await hasLocalizationsJoinTable(knex, meta.tableName)) {\n await migrateDocumentIdsWithLocalizations(db, knex, meta);\n } else {\n await migrationDocumentIds(db, knex, meta);\n }\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["QUERIES","postgres","knex","params","res","raw","rows","mysql","sqlite","getNextIdsToCreateDocumentId","db","joinColumn","inverseJoinColumn","tableName","joinTableName","dialect","client","length","row","otherIds","other_ids","split","map","v","parseInt","id","migrateDocumentIdsWithLocalizations","meta","singularName","toLowerCase","snakeCase","ids","update","document_id","createId","whereIn","migrationDocumentIds","updatedRows","select","from","whereNull","limit","as","createDocumentIdColumn","schema","alterTable","table","string","hasLocalizationsJoinTable","hasTable","createdDocumentId","name","up","metadata","values","attributes","hasDocumentIdColumn","hasColumn","down","Error"],"mappings":";;;;;AA4BA,MAAMA,OAAU,GAAA;IACd,MAAMC,QAAAA,CAAAA,CAASC,IAAU,EAAEC,MAAc,EAAA;AACvC,QAAA,MAAMC,GAAM,GAAA,MAAMF,IAAKG,CAAAA,GAAG,CACxB;;;;;;;AAOJ,EAAA,CAAC,EACGF,MAAAA,CAAAA;AAGF,QAAA,OAAOC,IAAIE,IAAI;AACjB,KAAA;IACA,MAAMC,KAAAA,CAAAA,CAAML,IAAU,EAAEC,MAAc,EAAA;AACpC,QAAA,MAAM,CAACC,GAAI,CAAA,GAAG,MAAMF,IAAKG,CAAAA,GAAG,CAC1B;;;;;;;AAOJ,EAAA,CAAC,EACGF,MAAAA,CAAAA;QAGF,OAAOC,GAAAA;AACT,KAAA;IACA,MAAMI,MAAAA,CAAAA,CAAON,IAAU,EAAEC,MAAc,EAAA;QACrC,OAAOD,IAAAA,CAAKG,GAAG,CACb;;;;;;;AAOF,IAAA,CAAC,EACCF,MAAAA,CAAAA;AAEJ;AACF,CAAA;AAEA,MAAMM,4BAA+B,GAAA,OACnCC,EACAR,EAAAA,IAAAA,EACA,EACES,UAAU,EACVC,iBAAiB,EACjBC,SAAS,EACTC,aAAa,EAMd,GAAA;IAED,MAAMV,GAAAA,GAAM,MAAMJ,OAAO,CAACU,EAAAA,CAAGK,OAAO,CAACC,MAAM,CAAyB,CAACd,IAAM,EAAA;AACzES,QAAAA,UAAAA;AACAC,QAAAA,iBAAAA;AACAC,QAAAA,SAAAA;AACAC,QAAAA;AACF,KAAA,CAAA;IAEA,IAAIV,GAAAA,CAAIa,MAAM,GAAG,CAAG,EAAA;QAClB,MAAMC,GAAAA,GAAMd,GAAG,CAAC,CAAE,CAAA;AAClB,QAAA,MAAMe,WAAWD,GAAIE,CAAAA,SAAS,GAC1BF,GAAAA,CAAIE,SAAS,CAACC,KAAK,CAAC,GAAA,CAAA,CAAKC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A,MAAM,CAACK,QAAQ,CAACtB,KAAKd,SAAS,CAAA;AAE1D,YAAA,IAAI,CAACoC,QAAU,EAAA;AACb,gBAAA;AACF;YAEA,IAAI,YAAA,IAAgBtB,IAAK4B,CAAAA,UAAU,EAAE;;gBAEnC,MAAMC,mBAAAA,GAAsB,MAAMtD,IAAK0C,CAAAA,MAAM,CAACa,SAAS,CAAC9B,IAAKd,CAAAA,SAAS,EAAE,aAAA,CAAA;AAExE,gBAAA,IAAI2C,mBAAqB,EAAA;AACvB,oBAAA;AACF;gBAEA,MAAMb,sBAAAA,CAAuBzC,IAAMyB,EAAAA,IAAAA,CAAKd,SAAS,CAAA;AAEjD,gBAAA,IAAI,MAAMmC,yBAAAA,CAA0B9C,IAAMyB,EAAAA,IAAAA,CAAKd,SAAS,CAAG,EAAA;oBACzD,MAAMa,mCAAAA,CAAoChB,IAAIR,IAAMyB,EAAAA,IAAAA,CAAAA;iBAC/C,MAAA;oBACL,MAAMS,oBAAAA,CAAqB1B,IAAIR,IAAMyB,EAAAA,IAAAA,CAAAA;AACvC;AACF;AACF;AACF,KAAA;IACA,MAAM+B,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAM,CAAA,iBAAA,CAAA;AAClB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"5.0.0-02-document-id.js","sources":["../../../src/migrations/internal-migrations/5.0.0-02-document-id.ts"],"sourcesContent":["/**\n * NOTE: This migration avoids using the `identifiers` utility.\n * As the `5.0.0-01-convert-identifiers-long-than-max-length`\n * migration does not convert the `localizations` join tables, as they are not\n * tables that exist anymore in v5 and are not in the db metadata.\n *\n * This migration therefore relies on the fact that those tables still exist, and\n * references them directly.\n *\n * Database join table name: `categories_localizations_links`\n * Actual `identifiers` returned join table name: `categories_localizations_lnk`\n *\n */\nimport { createId } from '@paralleldrive/cuid2';\nimport { snakeCase } from 'lodash/fp';\nimport type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\nimport type { Database } from '../..';\nimport type { Meta } from '../../metadata';\n\ninterface Params {\n joinColumn: string;\n inverseJoinColumn: string;\n tableName: string;\n joinTableName: string;\n}\n\nconst QUERIES = {\n async postgres(knex: Knex, params: Params) {\n const res = await knex.raw(\n `\n SELECT :tableName:.id as id, string_agg(DISTINCT :inverseJoinColumn:::character varying, ',') as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :tableName:.id, :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n\n return res.rows;\n },\n async mysql(knex: Knex, params: Params) {\n const [res] = await knex.raw(\n `\n SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :tableName:.id, :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n\n return res;\n },\n async sqlite(knex: Knex, params: Params) {\n return knex.raw(\n `\n SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n },\n};\n\nconst getNextIdsToCreateDocumentId = async (\n db: Database,\n knex: Knex,\n {\n joinColumn,\n inverseJoinColumn,\n tableName,\n joinTableName,\n }: {\n joinColumn: string;\n inverseJoinColumn: string;\n tableName: string;\n joinTableName: string;\n }\n): Promise<number[]> => {\n const res = await QUERIES[db.dialect.client as keyof typeof QUERIES](knex, {\n joinColumn,\n inverseJoinColumn,\n tableName,\n joinTableName,\n });\n\n if (res.length > 0) {\n const row = res[0];\n const otherIds = row.other_ids\n ? row.other_ids.split(',').map((v: string) => parseInt(v, 10))\n : [];\n\n return [row.id, ...otherIds];\n }\n\n return [];\n};\n\n// Migrate document ids for tables that have localizations\nconst migrateDocumentIdsWithLocalizations = async (db: Database, knex: Knex, meta: Meta) => {\n const singularName = meta.singularName.toLowerCase();\n const joinColumn = snakeCase(`${singularName}_id`);\n const inverseJoinColumn = snakeCase(`inv_${singularName}_id`);\n let ids: number[];\n\n do {\n ids = await getNextIdsToCreateDocumentId(db, knex, {\n joinColumn,\n inverseJoinColumn,\n tableName: meta.tableName,\n joinTableName: snakeCase(`${meta.tableName}_localizations_links`),\n });\n\n if (ids.length > 0) {\n await knex(meta.tableName).update({ document_id: createId() }).whereIn('id', ids);\n }\n } while (ids.length > 0);\n};\n\n// Migrate document ids for tables that don't have localizations\nconst migrationDocumentIds = async (db: Database, knex: Knex, meta: Meta) => {\n let updatedRows: number;\n\n do {\n updatedRows = await knex(meta.tableName)\n .update({ document_id: createId() })\n .whereIn(\n 'id',\n knex(meta.tableName)\n .select('id')\n .from(knex(meta.tableName).select('id').whereNull('document_id').limit(1).as('sub_query'))\n );\n } while (updatedRows > 0);\n};\n\nconst createDocumentIdColumn = async (knex: Knex, tableName: string) => {\n await knex.schema.alterTable(tableName, (table) => {\n table.string('document_id');\n });\n};\n\nconst hasLocalizationsJoinTable = async (knex: Knex, tableName: string) => {\n const joinTableName = snakeCase(`${tableName}_localizations_links`);\n return knex.schema.hasTable(joinTableName);\n};\n\nexport const createdDocumentId: Migration = {\n name: '5.0.0-02-created-document-id',\n async up(knex, db) {\n // do sth\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n if ('documentId' in meta.attributes) {\n // add column if doesn't exist\n const hasDocumentIdColumn = await knex.schema.hasColumn(meta.tableName, 'document_id');\n\n if (hasDocumentIdColumn) {\n continue;\n }\n\n await createDocumentIdColumn(knex, meta.tableName);\n\n if (await hasLocalizationsJoinTable(knex, meta.tableName)) {\n await migrateDocumentIdsWithLocalizations(db, knex, meta);\n } else {\n await migrationDocumentIds(db, knex, meta);\n }\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["QUERIES","postgres","knex","params","res","raw","rows","mysql","sqlite","getNextIdsToCreateDocumentId","db","joinColumn","inverseJoinColumn","tableName","joinTableName","dialect","client","length","row","otherIds","other_ids","split","map","v","parseInt","id","migrateDocumentIdsWithLocalizations","meta","singularName","toLowerCase","snakeCase","ids","update","document_id","createId","whereIn","migrationDocumentIds","updatedRows","select","from","whereNull","limit","as","createDocumentIdColumn","schema","alterTable","table","string","hasLocalizationsJoinTable","hasTable","createdDocumentId","name","up","metadata","values","attributes","hasDocumentIdColumn","hasColumn","down","Error"],"mappings":";;;;;AA4BA,MAAMA,OAAAA,GAAU;IACd,MAAMC,QAAAA,CAAAA,CAASC,IAAU,EAAEC,MAAc,EAAA;AACvC,QAAA,MAAMC,GAAAA,GAAM,MAAMF,IAAAA,CAAKG,GAAG,CACxB;;;;;;;AAOJ,EAAA,CAAC,EACGF,MAAAA,CAAAA;AAGF,QAAA,OAAOC,IAAIE,IAAI;AACjB,IAAA,CAAA;IACA,MAAMC,KAAAA,CAAAA,CAAML,IAAU,EAAEC,MAAc,EAAA;AACpC,QAAA,MAAM,CAACC,GAAAA,CAAI,GAAG,MAAMF,IAAAA,CAAKG,GAAG,CAC1B;;;;;;;AAOJ,EAAA,CAAC,EACGF,MAAAA,CAAAA;QAGF,OAAOC,GAAAA;AACT,IAAA,CAAA;IACA,MAAMI,MAAAA,CAAAA,CAAON,IAAU,EAAEC,MAAc,EAAA;QACrC,OAAOD,IAAAA,CAAKG,GAAG,CACb;;;;;;;AAOF,IAAA,CAAC,EACCF,MAAAA,CAAAA;AAEJ,IAAA;AACF,CAAA;AAEA,MAAMM,4BAAAA,GAA+B,OACnCC,EAAAA,EACAR,IAAAA,EACA,EACES,UAAU,EACVC,iBAAiB,EACjBC,SAAS,EACTC,aAAa,EAMd,GAAA;IAED,MAAMV,GAAAA,GAAM,MAAMJ,OAAO,CAACU,EAAAA,CAA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
|
1
|
-
{"version":3,"file":"5.0.0-02-document-id.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-02-document-id.ts"],"sourcesContent":["/**\n * NOTE: This migration avoids using the `identifiers` utility.\n * As the `5.0.0-01-convert-identifiers-long-than-max-length`\n * migration does not convert the `localizations` join tables, as they are not\n * tables that exist anymore in v5 and are not in the db metadata.\n *\n * This migration therefore relies on the fact that those tables still exist, and\n * references them directly.\n *\n * Database join table name: `categories_localizations_links`\n * Actual `identifiers` returned join table name: `categories_localizations_lnk`\n *\n */\nimport { createId } from '@paralleldrive/cuid2';\nimport { snakeCase } from 'lodash/fp';\nimport type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\nimport type { Database } from '../..';\nimport type { Meta } from '../../metadata';\n\ninterface Params {\n joinColumn: string;\n inverseJoinColumn: string;\n tableName: string;\n joinTableName: string;\n}\n\nconst QUERIES = {\n async postgres(knex: Knex, params: Params) {\n const res = await knex.raw(\n `\n SELECT :tableName:.id as id, string_agg(DISTINCT :inverseJoinColumn:::character varying, ',') as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :tableName:.id, :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n\n return res.rows;\n },\n async mysql(knex: Knex, params: Params) {\n const [res] = await knex.raw(\n `\n SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :tableName:.id, :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n\n return res;\n },\n async sqlite(knex: Knex, params: Params) {\n return knex.raw(\n `\n SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n },\n};\n\nconst getNextIdsToCreateDocumentId = async (\n db: Database,\n knex: Knex,\n {\n joinColumn,\n inverseJoinColumn,\n tableName,\n joinTableName,\n }: {\n joinColumn: string;\n inverseJoinColumn: string;\n tableName: string;\n joinTableName: string;\n }\n): Promise<number[]> => {\n const res = await QUERIES[db.dialect.client as keyof typeof QUERIES](knex, {\n joinColumn,\n inverseJoinColumn,\n tableName,\n joinTableName,\n });\n\n if (res.length > 0) {\n const row = res[0];\n const otherIds = row.other_ids\n ? row.other_ids.split(',').map((v: string) => parseInt(v, 10))\n : [];\n\n return [row.id, ...otherIds];\n }\n\n return [];\n};\n\n// Migrate document ids for tables that have localizations\nconst migrateDocumentIdsWithLocalizations = async (db: Database, knex: Knex, meta: Meta) => {\n const singularName = meta.singularName.toLowerCase();\n const joinColumn = snakeCase(`${singularName}_id`);\n const inverseJoinColumn = snakeCase(`inv_${singularName}_id`);\n let ids: number[];\n\n do {\n ids = await getNextIdsToCreateDocumentId(db, knex, {\n joinColumn,\n inverseJoinColumn,\n tableName: meta.tableName,\n joinTableName: snakeCase(`${meta.tableName}_localizations_links`),\n });\n\n if (ids.length > 0) {\n await knex(meta.tableName).update({ document_id: createId() }).whereIn('id', ids);\n }\n } while (ids.length > 0);\n};\n\n// Migrate document ids for tables that don't have localizations\nconst migrationDocumentIds = async (db: Database, knex: Knex, meta: Meta) => {\n let updatedRows: number;\n\n do {\n updatedRows = await knex(meta.tableName)\n .update({ document_id: createId() })\n .whereIn(\n 'id',\n knex(meta.tableName)\n .select('id')\n .from(knex(meta.tableName).select('id').whereNull('document_id').limit(1).as('sub_query'))\n );\n } while (updatedRows > 0);\n};\n\nconst createDocumentIdColumn = async (knex: Knex, tableName: string) => {\n await knex.schema.alterTable(tableName, (table) => {\n table.string('document_id');\n });\n};\n\nconst hasLocalizationsJoinTable = async (knex: Knex, tableName: string) => {\n const joinTableName = snakeCase(`${tableName}_localizations_links`);\n return knex.schema.hasTable(joinTableName);\n};\n\nexport const createdDocumentId: Migration = {\n name: '5.0.0-02-created-document-id',\n async up(knex, db) {\n // do sth\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n if ('documentId' in meta.attributes) {\n // add column if doesn't exist\n const hasDocumentIdColumn = await knex.schema.hasColumn(meta.tableName, 'document_id');\n\n if (hasDocumentIdColumn) {\n continue;\n }\n\n await createDocumentIdColumn(knex, meta.tableName);\n\n if (await hasLocalizationsJoinTable(knex, meta.tableName)) {\n await migrateDocumentIdsWithLocalizations(db, knex, meta);\n } else {\n await migrationDocumentIds(db, knex, meta);\n }\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["QUERIES","postgres","knex","params","res","raw","rows","mysql","sqlite","getNextIdsToCreateDocumentId","db","joinColumn","inverseJoinColumn","tableName","joinTableName","dialect","client","length","row","otherIds","other_ids","split","map","v","parseInt","id","migrateDocumentIdsWithLocalizations","meta","singularName","toLowerCase","snakeCase","ids","update","document_id","createId","whereIn","migrationDocumentIds","updatedRows","select","from","whereNull","limit","as","createDocumentIdColumn","schema","alterTable","table","string","hasLocalizationsJoinTable","hasTable","createdDocumentId","name","up","metadata","values","attributes","hasDocumentIdColumn","hasColumn","down","Error"],"mappings":";;;AA4BA,MAAMA,OAAU,GAAA;IACd,MAAMC,QAAAA,CAAAA,CAASC,IAAU,EAAEC,MAAc,EAAA;AACvC,QAAA,MAAMC,GAAM,GAAA,MAAMF,IAAKG,CAAAA,GAAG,CACxB;;;;;;;AAOJ,EAAA,CAAC,EACGF,MAAAA,CAAAA;AAGF,QAAA,OAAOC,IAAIE,IAAI;AACjB,KAAA;IACA,MAAMC,KAAAA,CAAAA,CAAML,IAAU,EAAEC,MAAc,EAAA;AACpC,QAAA,MAAM,CAACC,GAAI,CAAA,GAAG,MAAMF,IAAKG,CAAAA,GAAG,CA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,IAAMyB,EAAAA,IAAAA,CAAKd,SAAS,CAAG,EAAA;oBACzD,MAAMa,mCAAAA,CAAoChB,IAAIR,IAAMyB,EAAAA,IAAAA,CAAAA;iBAC/C,MAAA;oBACL,MAAMS,oBAAAA,CAAqB1B,IAAIR,IAAMyB,EAAAA,IAAAA,CAAAA;AACvC;AACF;AACF;AACF,KAAA;IACA,MAAM+B,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAM,CAAA,iBAAA,CAAA;AAClB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"5.0.0-02-document-id.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-02-document-id.ts"],"sourcesContent":["/**\n * NOTE: This migration avoids using the `identifiers` utility.\n * As the `5.0.0-01-convert-identifiers-long-than-max-length`\n * migration does not convert the `localizations` join tables, as they are not\n * tables that exist anymore in v5 and are not in the db metadata.\n *\n * This migration therefore relies on the fact that those tables still exist, and\n * references them directly.\n *\n * Database join table name: `categories_localizations_links`\n * Actual `identifiers` returned join table name: `categories_localizations_lnk`\n *\n */\nimport { createId } from '@paralleldrive/cuid2';\nimport { snakeCase } from 'lodash/fp';\nimport type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\nimport type { Database } from '../..';\nimport type { Meta } from '../../metadata';\n\ninterface Params {\n joinColumn: string;\n inverseJoinColumn: string;\n tableName: string;\n joinTableName: string;\n}\n\nconst QUERIES = {\n async postgres(knex: Knex, params: Params) {\n const res = await knex.raw(\n `\n SELECT :tableName:.id as id, string_agg(DISTINCT :inverseJoinColumn:::character varying, ',') as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :tableName:.id, :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n\n return res.rows;\n },\n async mysql(knex: Knex, params: Params) {\n const [res] = await knex.raw(\n `\n SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :tableName:.id, :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n\n return res;\n },\n async sqlite(knex: Knex, params: Params) {\n return knex.raw(\n `\n SELECT :tableName:.id as id, group_concat(DISTINCT :inverseJoinColumn:) as other_ids\n FROM :tableName:\n LEFT JOIN :joinTableName: ON :tableName:.id = :joinTableName:.:joinColumn:\n WHERE :tableName:.document_id IS NULL\n GROUP BY :joinTableName:.:joinColumn:\n LIMIT 1;\n `,\n params\n );\n },\n};\n\nconst getNextIdsToCreateDocumentId = async (\n db: Database,\n knex: Knex,\n {\n joinColumn,\n inverseJoinColumn,\n tableName,\n joinTableName,\n }: {\n joinColumn: string;\n inverseJoinColumn: string;\n tableName: string;\n joinTableName: string;\n }\n): Promise<number[]> => {\n const res = await QUERIES[db.dialect.client as keyof typeof QUERIES](knex, {\n joinColumn,\n inverseJoinColumn,\n tableName,\n joinTableName,\n });\n\n if (res.length > 0) {\n const row = res[0];\n const otherIds = row.other_ids\n ? row.other_ids.split(',').map((v: string) => parseInt(v, 10))\n : [];\n\n return [row.id, ...otherIds];\n }\n\n return [];\n};\n\n// Migrate document ids for tables that have localizations\nconst migrateDocumentIdsWithLocalizations = async (db: Database, knex: Knex, meta: Meta) => {\n const singularName = meta.singularName.toLowerCase();\n const joinColumn = snakeCase(`${singularName}_id`);\n const inverseJoinColumn = snakeCase(`inv_${singularName}_id`);\n let ids: number[];\n\n do {\n ids = await getNextIdsToCreateDocumentId(db, knex, {\n joinColumn,\n inverseJoinColumn,\n tableName: meta.tableName,\n joinTableName: snakeCase(`${meta.tableName}_localizations_links`),\n });\n\n if (ids.length > 0) {\n await knex(meta.tableName).update({ document_id: createId() }).whereIn('id', ids);\n }\n } while (ids.length > 0);\n};\n\n// Migrate document ids for tables that don't have localizations\nconst migrationDocumentIds = async (db: Database, knex: Knex, meta: Meta) => {\n let updatedRows: number;\n\n do {\n updatedRows = await knex(meta.tableName)\n .update({ document_id: createId() })\n .whereIn(\n 'id',\n knex(meta.tableName)\n .select('id')\n .from(knex(meta.tableName).select('id').whereNull('document_id').limit(1).as('sub_query'))\n );\n } while (updatedRows > 0);\n};\n\nconst createDocumentIdColumn = async (knex: Knex, tableName: string) => {\n await knex.schema.alterTable(tableName, (table) => {\n table.string('document_id');\n });\n};\n\nconst hasLocalizationsJoinTable = async (knex: Knex, tableName: string) => {\n const joinTableName = snakeCase(`${tableName}_localizations_links`);\n return knex.schema.hasTable(joinTableName);\n};\n\nexport const createdDocumentId: Migration = {\n name: '5.0.0-02-created-document-id',\n async up(knex, db) {\n // do sth\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n if ('documentId' in meta.attributes) {\n // add column if doesn't exist\n const hasDocumentIdColumn = await knex.schema.hasColumn(meta.tableName, 'document_id');\n\n if (hasDocumentIdColumn) {\n continue;\n }\n\n await createDocumentIdColumn(knex, meta.tableName);\n\n if (await hasLocalizationsJoinTable(knex, meta.tableName)) {\n await migrateDocumentIdsWithLocalizations(db, knex, meta);\n } else {\n await migrationDocumentIds(db, knex, meta);\n }\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["QUERIES","postgres","knex","params","res","raw","rows","mysql","sqlite","getNextIdsToCreateDocumentId","db","joinColumn","inverseJoinColumn","tableName","joinTableName","dialect","client","length","row","otherIds","other_ids","split","map","v","parseInt","id","migrateDocumentIdsWithLocalizations","meta","singularName","toLowerCase","snakeCase","ids","update","document_id","createId","whereIn","migrationDocumentIds","updatedRows","select","from","whereNull","limit","as","createDocumentIdColumn","schema","alterTable","table","string","hasLocalizationsJoinTable","hasTable","createdDocumentId","name","up","metadata","values","attributes","hasDocumentIdColumn","hasColumn","down","Error"],"mappings":";;;AA4BA,MAAMA,OAAAA,GAAU;IACd,MAAMC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AU;AACb,gBAAA;AACF,YAAA;YAEA,IAAI,YAAA,IAAgBtB,IAAAA,CAAK4B,UAAU,EAAE;;gBAEnC,MAAMC,mBAAAA,GAAsB,MAAMtD,IAAAA,CAAK0C,MAAM,CAACa,SAAS,CAAC9B,IAAAA,CAAKd,SAAS,EAAE,aAAA,CAAA;AAExE,gBAAA,IAAI2C,mBAAAA,EAAqB;AACvB,oBAAA;AACF,gBAAA;gBAEA,MAAMb,sBAAAA,CAAuBzC,IAAAA,EAAMyB,IAAAA,CAAKd,SAAS,CAAA;AAEjD,gBAAA,IAAI,MAAMmC,yBAAAA,CAA0B9C,IAAAA,EAAMyB,IAAAA,CAAKd,SAAS,CAAA,EAAG;oBACzD,MAAMa,mCAAAA,CAAoChB,IAAIR,IAAAA,EAAMyB,IAAAA,CAAAA;gBACtD,CAAA,MAAO;oBACL,MAAMS,oBAAAA,CAAqB1B,IAAIR,IAAAA,EAAMyB,IAAAA,CAAAA;AACvC,gBAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA,CAAA;IACA,MAAM+B,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"5.0.0-03-locale.js","sources":["../../../src/migrations/internal-migrations/5.0.0-03-locale.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n/**\n * In v4, content types with disabled i18n did not have any locale column.\n * In v5, we need to add a `locale` column to all content types.\n * Other downstream migrations will make use of this column.\n *\n * This function creates the `locale` column if it doesn't exist.\n */\nconst createLocaleColumn = async (db: Knex, tableName: string) => {\n await db.schema.alterTable(tableName, (table) => {\n table.string('locale');\n });\n};\n\nexport const createdLocale: Migration = {\n name: '5.0.0-03-created-locale',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n // Ignore non-content types\n const uid = meta.uid;\n const model = strapi.getModel(uid);\n if (!model) {\n continue;\n }\n\n // Create locale column if it doesn't exist\n const hasLocaleColumn = await knex.schema.hasColumn(meta.tableName, 'locale');\n\n if (meta.attributes.locale && !hasLocaleColumn) {\n await createLocaleColumn(knex, meta.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createLocaleColumn","db","tableName","schema","alterTable","table","string","createdLocale","name","up","knex","meta","metadata","values","hasTable","uid","model","strapi","getModel","hasLocaleColumn","hasColumn","attributes","locale","down","Error"],"mappings":";;AAIA;;;;;;IAOA,MAAMA,
|
|
1
|
+
{"version":3,"file":"5.0.0-03-locale.js","sources":["../../../src/migrations/internal-migrations/5.0.0-03-locale.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n/**\n * In v4, content types with disabled i18n did not have any locale column.\n * In v5, we need to add a `locale` column to all content types.\n * Other downstream migrations will make use of this column.\n *\n * This function creates the `locale` column if it doesn't exist.\n */\nconst createLocaleColumn = async (db: Knex, tableName: string) => {\n await db.schema.alterTable(tableName, (table) => {\n table.string('locale');\n });\n};\n\nexport const createdLocale: Migration = {\n name: '5.0.0-03-created-locale',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n // Ignore non-content types\n const uid = meta.uid;\n const model = strapi.getModel(uid);\n if (!model) {\n continue;\n }\n\n // Create locale column if it doesn't exist\n const hasLocaleColumn = await knex.schema.hasColumn(meta.tableName, 'locale');\n\n if (meta.attributes.locale && !hasLocaleColumn) {\n await createLocaleColumn(knex, meta.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createLocaleColumn","db","tableName","schema","alterTable","table","string","createdLocale","name","up","knex","meta","metadata","values","hasTable","uid","model","strapi","getModel","hasLocaleColumn","hasColumn","attributes","locale","down","Error"],"mappings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03-locale.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-03-locale.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n/**\n * In v4, content types with disabled i18n did not have any locale column.\n * In v5, we need to add a `locale` column to all content types.\n * Other downstream migrations will make use of this column.\n *\n * This function creates the `locale` column if it doesn't exist.\n */\nconst createLocaleColumn = async (db: Knex, tableName: string) => {\n await db.schema.alterTable(tableName, (table) => {\n table.string('locale');\n });\n};\n\nexport const createdLocale: Migration = {\n name: '5.0.0-03-created-locale',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n // Ignore non-content types\n const uid = meta.uid;\n const model = strapi.getModel(uid);\n if (!model) {\n continue;\n }\n\n // Create locale column if it doesn't exist\n const hasLocaleColumn = await knex.schema.hasColumn(meta.tableName, 'locale');\n\n if (meta.attributes.locale && !hasLocaleColumn) {\n await createLocaleColumn(knex, meta.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createLocaleColumn","db","tableName","schema","alterTable","table","string","createdLocale","name","up","knex","meta","metadata","values","hasTable","uid","model","strapi","getModel","hasLocaleColumn","hasColumn","attributes","locale","down","Error"],"mappings":"AAIA;;;;;;IAOA,MAAMA,
|
|
1
|
+
{"version":3,"file":"5.0.0-03-locale.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-03-locale.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n/**\n * In v4, content types with disabled i18n did not have any locale column.\n * In v5, we need to add a `locale` column to all content types.\n * Other downstream migrations will make use of this column.\n *\n * This function creates the `locale` column if it doesn't exist.\n */\nconst createLocaleColumn = async (db: Knex, tableName: string) => {\n await db.schema.alterTable(tableName, (table) => {\n table.string('locale');\n });\n};\n\nexport const createdLocale: Migration = {\n name: '5.0.0-03-created-locale',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n // Ignore non-content types\n const uid = meta.uid;\n const model = strapi.getModel(uid);\n if (!model) {\n continue;\n }\n\n // Create locale column if it doesn't exist\n const hasLocaleColumn = await knex.schema.hasColumn(meta.tableName, 'locale');\n\n if (meta.attributes.locale && !hasLocaleColumn) {\n await createLocaleColumn(knex, meta.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createLocaleColumn","db","tableName","schema","alterTable","table","string","createdLocale","name","up","knex","meta","metadata","values","hasTable","uid","model","strapi","getModel","hasLocaleColumn","hasColumn","attributes","locale","down","Error"],"mappings":"AAIA;;;;;;IAOA,MAAMA,kBAAAA,GAAqB,OAAOC,EAAAA,EAAUC,SAAAA,GAAAA;AAC1C,IAAA,MAAMD,GAAGE,MAAM,CAACC,UAAU,CAACF,WAAW,CAACG,KAAAA,GAAAA;AACrCA,QAAAA,KAAAA,CAAMC,MAAM,CAAC,QAAA,CAAA;AACf,IAAA,CAAA,CAAA;AACF,CAAA;MAEaC,aAAAA,GAA2B;IACtCC,IAAAA,EAAM,yBAAA;IACN,MAAMC,EAAAA,CAAAA,CAAGC,IAAI,EAAET,EAAE,EAAA;AACf,QAAA,KAAK,MAAMU,IAAAA,IAAQV,EAAAA,CAAGW,QAAQ,CAACC,MAAM,EAAA,CAAI;YACvC,MAAMC,QAAAA,GAAW,MAAMJ,IAAAA,CAAKP,MAAM,CAACW,QAAQ,CAACH,KAAKT,SAAS,CAAA;AAE1D,YAAA,IAAI,CAACY,QAAAA,EAAU;AACb,gBAAA;AACF,YAAA;;YAGA,MAAMC,GAAAA,GAAMJ,KAAKI,GAAG;YACpB,MAAMC,KAAAA,GAAQC,MAAAA,CAAOC,QAAQ,CAACH,GAAAA,CAAAA;AAC9B,YAAA,IAAI,CAACC,KAAAA,EAAO;AACV,gBAAA;AACF,YAAA;;YAGA,MAAMG,eAAAA,GAAkB,MAAMT,IAAAA,CAAKP,MAAM,CAACiB,SAAS,CAACT,IAAAA,CAAKT,SAAS,EAAE,QAAA,CAAA;AAEpE,YAAA,IAAIS,KAAKU,UAAU,CAACC,MAAM,IAAI,CAACH,eAAAA,EAAiB;gBAC9C,MAAMnB,kBAAAA,CAAmBU,IAAAA,EAAMC,IAAAA,CAAKT,SAAS,CAAA;AAC/C,YAAA;AACF,QAAA;AACF,IAAA,CAAA;IACA,MAAMqB,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"5.0.0-04-published-at.js","sources":["../../../src/migrations/internal-migrations/5.0.0-04-published-at.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n/**\n * In v4, content types with disabled D&P did not have any `published_at` column.\n * In v5, we need to add a `published_at` column to all content types.\n * Other downstream migrations will make use of this column.\n *\n * This function creates the `published_at` column if it doesn't exist.\n */\nconst createPublishedAtColumn = async (db: Knex, tableName: string) => {\n await db.schema.alterTable(tableName, (table) => {\n table.string('published_at');\n });\n\n // Non DP content types should have their `published_at` column set to a date\n await db(tableName).update({ published_at: new Date() });\n};\n\nexport const createdPublishedAt: Migration = {\n name: '5.0.0-04-created-published-at',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n // Ignore non-content types\n const uid = meta.uid;\n const model = strapi.getModel(uid);\n if (!model) {\n continue;\n }\n\n // Create publishedAt column if it doesn't exist\n const hasPublishedAtColumn = await knex.schema.hasColumn(meta.tableName, 'published_at');\n\n if (meta.attributes.publishedAt && !hasPublishedAtColumn) {\n await createPublishedAtColumn(knex, meta.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createPublishedAtColumn","db","tableName","schema","alterTable","table","string","update","published_at","Date","createdPublishedAt","name","up","knex","meta","metadata","values","hasTable","uid","model","strapi","getModel","hasPublishedAtColumn","hasColumn","attributes","publishedAt","down","Error"],"mappings":";;AAIA;;;;;;IAOA,MAAMA,
|
|
1
|
+
{"version":3,"file":"5.0.0-04-published-at.js","sources":["../../../src/migrations/internal-migrations/5.0.0-04-published-at.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n/**\n * In v4, content types with disabled D&P did not have any `published_at` column.\n * In v5, we need to add a `published_at` column to all content types.\n * Other downstream migrations will make use of this column.\n *\n * This function creates the `published_at` column if it doesn't exist.\n */\nconst createPublishedAtColumn = async (db: Knex, tableName: string) => {\n await db.schema.alterTable(tableName, (table) => {\n table.string('published_at');\n });\n\n // Non DP content types should have their `published_at` column set to a date\n await db(tableName).update({ published_at: new Date() });\n};\n\nexport const createdPublishedAt: Migration = {\n name: '5.0.0-04-created-published-at',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n // Ignore non-content types\n const uid = meta.uid;\n const model = strapi.getModel(uid);\n if (!model) {\n continue;\n }\n\n // Create publishedAt column if it doesn't exist\n const hasPublishedAtColumn = await knex.schema.hasColumn(meta.tableName, 'published_at');\n\n if (meta.attributes.publishedAt && !hasPublishedAtColumn) {\n await createPublishedAtColumn(knex, meta.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createPublishedAtColumn","db","tableName","schema","alterTable","table","string","update","published_at","Date","createdPublishedAt","name","up","knex","meta","metadata","values","hasTable","uid","model","strapi","getModel","hasPublishedAtColumn","hasColumn","attributes","publishedAt","down","Error"],"mappings":";;AAIA;;;;;;IAOA,MAAMA,uBAAAA,GAA0B,OAAOC,EAAAA,EAAUC,SAAAA,GAAAA;AAC/C,IAAA,MAAMD,GAAGE,MAAM,CAACC,UAAU,CAACF,WAAW,CAACG,KAAAA,GAAAA;AAC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-migrations/5.0.0-04-published-at.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n/**\n * In v4, content types with disabled D&P did not have any `published_at` column.\n * In v5, we need to add a `published_at` column to all content types.\n * Other downstream migrations will make use of this column.\n *\n * This function creates the `published_at` column if it doesn't exist.\n */\nconst createPublishedAtColumn = async (db: Knex, tableName: string) => {\n await db.schema.alterTable(tableName, (table) => {\n table.string('published_at');\n });\n\n // Non DP content types should have their `published_at` column set to a date\n await db(tableName).update({ published_at: new Date() });\n};\n\nexport const createdPublishedAt: Migration = {\n name: '5.0.0-04-created-published-at',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n // Ignore non-content types\n const uid = meta.uid;\n const model = strapi.getModel(uid);\n if (!model) {\n continue;\n }\n\n // Create publishedAt column if it doesn't exist\n const hasPublishedAtColumn = await knex.schema.hasColumn(meta.tableName, 'published_at');\n\n if (meta.attributes.publishedAt && !hasPublishedAtColumn) {\n await createPublishedAtColumn(knex, meta.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createPublishedAtColumn","db","tableName","schema","alterTable","table","string","update","published_at","Date","createdPublishedAt","name","up","knex","meta","metadata","values","hasTable","uid","model","strapi","getModel","hasPublishedAtColumn","hasColumn","attributes","publishedAt","down","Error"],"mappings":"AAIA;;;;;;IAOA,MAAMA,
|
|
1
|
+
{"version":3,"file":"5.0.0-04-published-at.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-04-published-at.ts"],"sourcesContent":["import type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\n/**\n * In v4, content types with disabled D&P did not have any `published_at` column.\n * In v5, we need to add a `published_at` column to all content types.\n * Other downstream migrations will make use of this column.\n *\n * This function creates the `published_at` column if it doesn't exist.\n */\nconst createPublishedAtColumn = async (db: Knex, tableName: string) => {\n await db.schema.alterTable(tableName, (table) => {\n table.string('published_at');\n });\n\n // Non DP content types should have their `published_at` column set to a date\n await db(tableName).update({ published_at: new Date() });\n};\n\nexport const createdPublishedAt: Migration = {\n name: '5.0.0-04-created-published-at',\n async up(knex, db) {\n for (const meta of db.metadata.values()) {\n const hasTable = await knex.schema.hasTable(meta.tableName);\n\n if (!hasTable) {\n continue;\n }\n\n // Ignore non-content types\n const uid = meta.uid;\n const model = strapi.getModel(uid);\n if (!model) {\n continue;\n }\n\n // Create publishedAt column if it doesn't exist\n const hasPublishedAtColumn = await knex.schema.hasColumn(meta.tableName, 'published_at');\n\n if (meta.attributes.publishedAt && !hasPublishedAtColumn) {\n await createPublishedAtColumn(knex, meta.tableName);\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["createPublishedAtColumn","db","tableName","schema","alterTable","table","string","update","published_at","Date","createdPublishedAt","name","up","knex","meta","metadata","values","hasTable","uid","model","strapi","getModel","hasPublishedAtColumn","hasColumn","attributes","publishedAt","down","Error"],"mappings":"AAIA;;;;;;IAOA,MAAMA,uBAAAA,GAA0B,OAAOC,EAAAA,EAAUC,SAAAA,GAAAA;AAC/C,IAAA,MAAMD,GAAGE,MAAM,CAACC,UAAU,CAACF,WAAW,CAACG,KAAAA,GAAAA;AACrCA,QAAAA,KAAAA,CAAMC,MAAM,CAAC,cAAA,CAAA;AACf,IAAA,CAAA,CAAA;;IAGA,MAAML,EAAAA,CAAGC,SAAAA,CAAAA,CAAWK,MAAM,CAAC;AAAEC,QAAAA,YAAAA,EAAc,IAAIC,IAAAA;AAAO,KAAA,CAAA;AACxD,CAAA;MAEaC,kBAAAA,GAAgC;IAC3CC,IAAAA,EAAM,+BAAA;IACN,MAAMC,EAAAA,CAAAA,CAAGC,IAAI,EAAEZ,EAAE,EAAA;AACf,QAAA,KAAK,MAAMa,IAAAA,IAAQb,EAAAA,CAAGc,QAAQ,CAACC,MAAM,EAAA,CAAI;YACvC,MAAMC,QAAAA,GAAW,MAAMJ,IAAAA,CAAKV,MAAM,CAACc,QAAQ,CAACH,KAAKZ,SAAS,CAAA;AAE1D,YAAA,IAAI,CAACe,QAAAA,EAAU;AACb,gBAAA;AACF,YAAA;;YAGA,MAAMC,GAAAA,GAAMJ,KAAKI,GAAG;YACpB,MAAMC,KAAAA,GAAQC,MAAAA,CAAOC,QAAQ,CAACH,GAAAA,CAAAA;AAC9B,YAAA,IAAI,CAACC,KAAAA,EAAO;AACV,gBAAA;AACF,YAAA;;YAGA,MAAMG,oBAAAA,GAAuB,MAAMT,IAAAA,CAAKV,MAAM,CAACoB,SAAS,CAACT,IAAAA,CAAKZ,SAAS,EAAE,cAAA,CAAA;AAEzE,YAAA,IAAIY,KAAKU,UAAU,CAACC,WAAW,IAAI,CAACH,oBAAAA,EAAsB;gBACxD,MAAMtB,uBAAAA,CAAwBa,IAAAA,EAAMC,IAAAA,CAAKZ,SAAS,CAAA;AACpD,YAAA;AACF,QAAA;AACF,IAAA,CAAA;IACA,MAAMwB,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"5.0.0-05-drop-slug-unique-index.js","sources":["../../../src/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.ts"],"sourcesContent":["/**\n * In V4 slug fields contained a unique index.\n * In V5 slug fields should not have a unique index.\n *\n * This migration drops existing unique indexes from slug fields so downstream migrations\n * can work on the data without violating the unique index.\n */\nimport type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\nconst dropIndex = async (knex: Knex, tableName: string, columnName: string) => {\n try {\n await knex.schema.alterTable(tableName, (table) => {\n // NOTE: Can not use \"identifiers\" utility, as the 5.0.0-01 migration does not rename this particular index\n // to `tableName_columnName_uq`.\n table.dropUnique([columnName], `${tableName}_${columnName}_unique`);\n });\n } catch (error) {\n // If unique index does not exist, do nothing\n }\n};\n\nexport const dropSlugFieldsIndex: Migration = {\n name: '5.0.0-05-drop-slug-fields-index',\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 for (const attribute of Object.values(meta.attributes)) {\n if (attribute.type === 'uid' && attribute.columnName) {\n await dropIndex(knex, meta.tableName, attribute.columnName);\n }\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["dropIndex","knex","tableName","columnName","schema","alterTable","table","dropUnique","error","dropSlugFieldsIndex","name","up","db","meta","metadata","values","hasTable","attribute","Object","attributes","type","down","Error"],"mappings":";;AAAA;;;;;;AAMC,IAKD,MAAMA,SAAAA,GAAY,OAAOC,IAAAA,EAAYC,
|
|
1
|
+
{"version":3,"file":"5.0.0-05-drop-slug-unique-index.js","sources":["../../../src/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.ts"],"sourcesContent":["/**\n * In V4 slug fields contained a unique index.\n * In V5 slug fields should not have a unique index.\n *\n * This migration drops existing unique indexes from slug fields so downstream migrations\n * can work on the data without violating the unique index.\n */\nimport type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\nconst dropIndex = async (knex: Knex, tableName: string, columnName: string) => {\n try {\n await knex.schema.alterTable(tableName, (table) => {\n // NOTE: Can not use \"identifiers\" utility, as the 5.0.0-01 migration does not rename this particular index\n // to `tableName_columnName_uq`.\n table.dropUnique([columnName], `${tableName}_${columnName}_unique`);\n });\n } catch (error) {\n // If unique index does not exist, do nothing\n }\n};\n\nexport const dropSlugFieldsIndex: Migration = {\n name: '5.0.0-05-drop-slug-fields-index',\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 for (const attribute of Object.values(meta.attributes)) {\n if (attribute.type === 'uid' && attribute.columnName) {\n await dropIndex(knex, meta.tableName, attribute.columnName);\n }\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["dropIndex","knex","tableName","columnName","schema","alterTable","table","dropUnique","error","dropSlugFieldsIndex","name","up","db","meta","metadata","values","hasTable","attribute","Object","attributes","type","down","Error"],"mappings":";;AAAA;;;;;;AAMC,IAKD,MAAMA,SAAAA,GAAY,OAAOC,IAAAA,EAAYC,SAAAA,EAAmBC,UAAAA,GAAAA;IACtD,IAAI;AACF,QAAA,MAAMF,KAAKG,MAAM,CAACC,UAAU,CAACH,WAAW,CAACI,KAAAA,GAAAA;;;AAGvCA,YAAAA,KAAAA,CAAMC,UAAU,CAAC;AAACJ,gBAAAA;AAAW,aAAA,EAAE,GAAGD,SAAAA,CAAU,CAAC,EAAEC,UAAAA,CAAW,OAAO,CAAC,CAAA;AACpE,QAAA,CAAA,CAAA;AACF,IAAA,CAAA,CAAE,OAAOK,KAAAA,EAAO;;AAEhB,IAAA;AACF,CAAA;MAEaC,mBAAAA,GAAiC;IAC5CC,IAAAA,EAAM,iCAAA;IACN,MAAMC,EAAAA,CAAAA,CAAGV,IAAI,EAAEW,EAAE,EAAA;AACf,QAAA,KAAK,MAAMC,IAAAA,IAAQD,EAAAA,CAAGE,QAAQ,CAACC,MAAM,EAAA,CAAI;YACvC,MAAMC,QAAAA,GAAW,MAAMf,IAAAA,CAAKG,MAAM,CAACY,QAAQ,CAACH,KAAKX,SAAS,CAAA;AAC1D,YAAA,IAAI,CAACc,QAAAA,EAAU;AACb,gBAAA;AACF,YAAA;AAEA,YAAA,KAAK,MAAMC,SAAAA,IAAaC,MAAAA,CAAOH,MAAM,CAACF,IAAAA,CAAKM,UAAU,CAAA,CAAG;AACtD,gBAAA,IAAIF,UAAUG,IAAI,KAAK,KAAA,IAASH,SAAAA,CAAUd,UAAU,EAAE;AACpD,oBAAA,MAAMH,UAAUC,IAAAA,EAAMY,IAAAA,CAAKX,SAAS,EAAEe,UAAUd,UAAU,CAAA;AAC5D,gBAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA,CAAA;IACA,MAAMkB,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"5.0.0-05-drop-slug-unique-index.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.ts"],"sourcesContent":["/**\n * In V4 slug fields contained a unique index.\n * In V5 slug fields should not have a unique index.\n *\n * This migration drops existing unique indexes from slug fields so downstream migrations\n * can work on the data without violating the unique index.\n */\nimport type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\nconst dropIndex = async (knex: Knex, tableName: string, columnName: string) => {\n try {\n await knex.schema.alterTable(tableName, (table) => {\n // NOTE: Can not use \"identifiers\" utility, as the 5.0.0-01 migration does not rename this particular index\n // to `tableName_columnName_uq`.\n table.dropUnique([columnName], `${tableName}_${columnName}_unique`);\n });\n } catch (error) {\n // If unique index does not exist, do nothing\n }\n};\n\nexport const dropSlugFieldsIndex: Migration = {\n name: '5.0.0-05-drop-slug-fields-index',\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 for (const attribute of Object.values(meta.attributes)) {\n if (attribute.type === 'uid' && attribute.columnName) {\n await dropIndex(knex, meta.tableName, attribute.columnName);\n }\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["dropIndex","knex","tableName","columnName","schema","alterTable","table","dropUnique","error","dropSlugFieldsIndex","name","up","db","meta","metadata","values","hasTable","attribute","Object","attributes","type","down","Error"],"mappings":"AAAA;;;;;;AAMC,IAKD,MAAMA,SAAAA,GAAY,OAAOC,IAAAA,EAAYC,
|
|
1
|
+
{"version":3,"file":"5.0.0-05-drop-slug-unique-index.mjs","sources":["../../../src/migrations/internal-migrations/5.0.0-05-drop-slug-unique-index.ts"],"sourcesContent":["/**\n * In V4 slug fields contained a unique index.\n * In V5 slug fields should not have a unique index.\n *\n * This migration drops existing unique indexes from slug fields so downstream migrations\n * can work on the data without violating the unique index.\n */\nimport type { Knex } from 'knex';\n\nimport type { Migration } from '../common';\n\nconst dropIndex = async (knex: Knex, tableName: string, columnName: string) => {\n try {\n await knex.schema.alterTable(tableName, (table) => {\n // NOTE: Can not use \"identifiers\" utility, as the 5.0.0-01 migration does not rename this particular index\n // to `tableName_columnName_uq`.\n table.dropUnique([columnName], `${tableName}_${columnName}_unique`);\n });\n } catch (error) {\n // If unique index does not exist, do nothing\n }\n};\n\nexport const dropSlugFieldsIndex: Migration = {\n name: '5.0.0-05-drop-slug-fields-index',\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 for (const attribute of Object.values(meta.attributes)) {\n if (attribute.type === 'uid' && attribute.columnName) {\n await dropIndex(knex, meta.tableName, attribute.columnName);\n }\n }\n }\n },\n async down() {\n throw new Error('not implemented');\n },\n};\n"],"names":["dropIndex","knex","tableName","columnName","schema","alterTable","table","dropUnique","error","dropSlugFieldsIndex","name","up","db","meta","metadata","values","hasTable","attribute","Object","attributes","type","down","Error"],"mappings":"AAAA;;;;;;AAMC,IAKD,MAAMA,SAAAA,GAAY,OAAOC,IAAAA,EAAYC,SAAAA,EAAmBC,UAAAA,GAAAA;IACtD,IAAI;AACF,QAAA,MAAMF,KAAKG,MAAM,CAACC,UAAU,CAACH,WAAW,CAACI,KAAAA,GAAAA;;;AAGvCA,YAAAA,KAAAA,CAAMC,UAAU,CAAC;AAACJ,gBAAAA;AAAW,aAAA,EAAE,GAAGD,SAAAA,CAAU,CAAC,EAAEC,UAAAA,CAAW,OAAO,CAAC,CAAA;AACpE,QAAA,CAAA,CAAA;AACF,IAAA,CAAA,CAAE,OAAOK,KAAAA,EAAO;;AAEhB,IAAA;AACF,CAAA;MAEaC,mBAAAA,GAAiC;IAC5CC,IAAAA,EAAM,iCAAA;IACN,MAAMC,EAAAA,CAAAA,CAAGV,IAAI,EAAEW,EAAE,EAAA;AACf,QAAA,KAAK,MAAMC,IAAAA,IAAQD,EAAAA,CAAGE,QAAQ,CAACC,MAAM,EAAA,CAAI;YACvC,MAAMC,QAAAA,GAAW,MAAMf,IAAAA,CAAKG,MAAM,CAACY,QAAQ,CAACH,KAAKX,SAAS,CAAA;AAC1D,YAAA,IAAI,CAACc,QAAAA,EAAU;AACb,gBAAA;AACF,YAAA;AAEA,YAAA,KAAK,MAAMC,SAAAA,IAAaC,MAAAA,CAAOH,MAAM,CAACF,IAAAA,CAAKM,UAAU,CAAA,CAAG;AACtD,gBAAA,IAAIF,UAAUG,IAAI,KAAK,KAAA,IAASH,SAAAA,CAAUd,UAAU,EAAE;AACpD,oBAAA,MAAMH,UAAUC,IAAAA,EAAMY,IAAAA,CAAKX,SAAS,EAAEe,UAAUd,UAAU,CAAA;AAC5D,gBAAA;AACF,YAAA;AACF,QAAA;AACF,IAAA,CAAA;IACA,MAAMkB,IAAAA,CAAAA,GAAAA;AACJ,QAAA,MAAM,IAAIC,KAAAA,CAAM,iBAAA,CAAA;AAClB,IAAA;AACF;;;;"}
|
|
@@ -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,
|
|
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,G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AEtD,IAAA,CAAA,MAAO,IAAIc,SAAAA,EAAW;QACpB,MAAMhB,WAAAA,CACJC,MACAC,SAAAA,EACA;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 +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,
|
|
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,IAAA,CAAA,CAAE,OAAOQ,KAAAA,EAAO;;AAEhB,IAAA;AACF,CAAA;AAEA,MAAMC,kBAAAA,GAAqB,OAAOZ,IAAAA,EAAYC,SAAAA,GAAAA;;AAE5C,IAAA,MAAMY,gBAAgB,MAAMb,IAAAA,CAAKK,MAAM,CAACS,SAAS,CAACb,SAAAA,EAAW,aAAA,CAAA;AAC7D,IAAA,IAAI,CAACY,aAAAA,EAAe;AAClB,QAAA;AACF,IAAA;AAEA,IAAA,MAAME,YAAY,MAAMf,IAAAA,CAAKK,MAAM,CAACS,SAAS,CAACb,SAAAA,EAAW,QAAA,CAAA;AACzD,IAAA,MAAMe,iBAAiB,MAAMhB,IAAAA,CAAKK,MAAM,CAACS,SAAS,CAACb,SAAAA,EAAW,cAAA,CAAA;;IAG9D,MAAMF,WAAAA,CAAYC,MAAMC,SA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;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/migrations/internal-migrations/index.ts"],"sourcesContent":["import type { Migration } from '../common';\nimport { createdDocumentId } from './5.0.0-02-document-id';\nimport { renameIdentifiersLongerThanMaxLength } from './5.0.0-01-convert-identifiers-long-than-max-length';\nimport { createdLocale } from './5.0.0-03-locale';\nimport { createdPublishedAt } from './5.0.0-04-published-at';\nimport { dropSlugFieldsIndex } from './5.0.0-05-drop-slug-unique-index';\nimport { addDocumentIdIndexes } from './5.0.0-06-add-document-id-indexes';\n\n/**\n * List of all the internal migrations. The array order will be the order in which they are executed.\n *\n * {\n * name: 'some-name',\n * async up(knex: Knex, db: Database) {},\n * async down(knex: Knex, db: Database) {},\n * },\n */\nexport const internalMigrations: Migration[] = [\n renameIdentifiersLongerThanMaxLength,\n createdDocumentId,\n createdLocale,\n createdPublishedAt,\n dropSlugFieldsIndex,\n addDocumentIdIndexes,\n];\n"],"names":["internalMigrations","renameIdentifiersLongerThanMaxLength","createdDocumentId","createdLocale","createdPublishedAt","dropSlugFieldsIndex","addDocumentIdIndexes"],"mappings":";;;;;;;;;AAQA;;;;;;;;UASaA,
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/migrations/internal-migrations/index.ts"],"sourcesContent":["import type { Migration } from '../common';\nimport { createdDocumentId } from './5.0.0-02-document-id';\nimport { renameIdentifiersLongerThanMaxLength } from './5.0.0-01-convert-identifiers-long-than-max-length';\nimport { createdLocale } from './5.0.0-03-locale';\nimport { createdPublishedAt } from './5.0.0-04-published-at';\nimport { dropSlugFieldsIndex } from './5.0.0-05-drop-slug-unique-index';\nimport { addDocumentIdIndexes } from './5.0.0-06-add-document-id-indexes';\n\n/**\n * List of all the internal migrations. The array order will be the order in which they are executed.\n *\n * {\n * name: 'some-name',\n * async up(knex: Knex, db: Database) {},\n * async down(knex: Knex, db: Database) {},\n * },\n */\nexport const internalMigrations: Migration[] = [\n renameIdentifiersLongerThanMaxLength,\n createdDocumentId,\n createdLocale,\n createdPublishedAt,\n dropSlugFieldsIndex,\n addDocumentIdIndexes,\n];\n"],"names":["internalMigrations","renameIdentifiersLongerThanMaxLength","createdDocumentId","createdLocale","createdPublishedAt","dropSlugFieldsIndex","addDocumentIdIndexes"],"mappings":";;;;;;;;;AAQA;;;;;;;;UASaA,kBAAAA,GAAkC;AAC7CC,IAAAA,gFAAAA;AACAC,IAAAA,oCAAAA;AACAC,IAAAA,4BAAAA;AACAC,IAAAA,sCAAAA;AACAC,IAAAA,+CAAAA;AACAC,IAAAA;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/migrations/internal-migrations/index.ts"],"sourcesContent":["import type { Migration } from '../common';\nimport { createdDocumentId } from './5.0.0-02-document-id';\nimport { renameIdentifiersLongerThanMaxLength } from './5.0.0-01-convert-identifiers-long-than-max-length';\nimport { createdLocale } from './5.0.0-03-locale';\nimport { createdPublishedAt } from './5.0.0-04-published-at';\nimport { dropSlugFieldsIndex } from './5.0.0-05-drop-slug-unique-index';\nimport { addDocumentIdIndexes } from './5.0.0-06-add-document-id-indexes';\n\n/**\n * List of all the internal migrations. The array order will be the order in which they are executed.\n *\n * {\n * name: 'some-name',\n * async up(knex: Knex, db: Database) {},\n * async down(knex: Knex, db: Database) {},\n * },\n */\nexport const internalMigrations: Migration[] = [\n renameIdentifiersLongerThanMaxLength,\n createdDocumentId,\n createdLocale,\n createdPublishedAt,\n dropSlugFieldsIndex,\n addDocumentIdIndexes,\n];\n"],"names":["internalMigrations","renameIdentifiersLongerThanMaxLength","createdDocumentId","createdLocale","createdPublishedAt","dropSlugFieldsIndex","addDocumentIdIndexes"],"mappings":";;;;;;;AAQA;;;;;;;;UASaA,
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/migrations/internal-migrations/index.ts"],"sourcesContent":["import type { Migration } from '../common';\nimport { createdDocumentId } from './5.0.0-02-document-id';\nimport { renameIdentifiersLongerThanMaxLength } from './5.0.0-01-convert-identifiers-long-than-max-length';\nimport { createdLocale } from './5.0.0-03-locale';\nimport { createdPublishedAt } from './5.0.0-04-published-at';\nimport { dropSlugFieldsIndex } from './5.0.0-05-drop-slug-unique-index';\nimport { addDocumentIdIndexes } from './5.0.0-06-add-document-id-indexes';\n\n/**\n * List of all the internal migrations. The array order will be the order in which they are executed.\n *\n * {\n * name: 'some-name',\n * async up(knex: Knex, db: Database) {},\n * async down(knex: Knex, db: Database) {},\n * },\n */\nexport const internalMigrations: Migration[] = [\n renameIdentifiersLongerThanMaxLength,\n createdDocumentId,\n createdLocale,\n createdPublishedAt,\n dropSlugFieldsIndex,\n addDocumentIdIndexes,\n];\n"],"names":["internalMigrations","renameIdentifiersLongerThanMaxLength","createdDocumentId","createdLocale","createdPublishedAt","dropSlugFieldsIndex","addDocumentIdIndexes"],"mappings":";;;;;;;AAQA;;;;;;;;UASaA,kBAAAA,GAAkC;AAC7CC,IAAAA,oCAAAA;AACAC,IAAAA,iBAAAA;AACAC,IAAAA,aAAAA;AACAC,IAAAA,kBAAAA;AACAC,IAAAA,mBAAAA;AACAC,IAAAA;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sources":["../../src/migrations/internal.ts"],"sourcesContent":["import { Umzug } from 'umzug';\n\nimport { wrapTransaction } from './common';\nimport { internalMigrations } from './internal-migrations';\nimport { createStorage } from './storage';\nimport { transformLogMessage } from './logger';\n\nimport type { InternalMigrationProvider, Migration } from './common';\nimport type { Database } from '..';\n\nexport const createInternalMigrationProvider = (db: Database): InternalMigrationProvider => {\n const context = { db };\n const migrations: Migration[] = [...internalMigrations];\n\n const umzugProvider = new Umzug({\n storage: createStorage({ db, tableName: 'strapi_migrations_internal' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.debug(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: () =>\n migrations.map((migration) => {\n return {\n name: migration.name,\n up: wrapTransaction(context.db)(migration.up),\n down: wrapTransaction(context.db)(migration.down),\n };\n }),\n });\n\n return {\n async register(migration: Migration) {\n migrations.push(migration);\n },\n async shouldRun() {\n const pendingMigrations = await umzugProvider.pending();\n return pendingMigrations.length > 0;\n },\n async up() {\n await umzugProvider.up();\n },\n async down() {\n await umzugProvider.down();\n },\n };\n};\n"],"names":["createInternalMigrationProvider","db","context","migrations","internalMigrations","umzugProvider","Umzug","storage","createStorage","tableName","logger","info","message","debug","transformLogMessage","warn","error","map","migration","name","up","wrapTransaction","down","register","push","shouldRun","pendingMigrations","pending","length"],"mappings":";;;;;;;;AAUO,MAAMA,kCAAkC,CAACC,EAAAA,GAAAA;AAC9C,IAAA,MAAMC,
|
|
1
|
+
{"version":3,"file":"internal.js","sources":["../../src/migrations/internal.ts"],"sourcesContent":["import { Umzug } from 'umzug';\n\nimport { wrapTransaction } from './common';\nimport { internalMigrations } from './internal-migrations';\nimport { createStorage } from './storage';\nimport { transformLogMessage } from './logger';\n\nimport type { InternalMigrationProvider, Migration } from './common';\nimport type { Database } from '..';\n\nexport const createInternalMigrationProvider = (db: Database): InternalMigrationProvider => {\n const context = { db };\n const migrations: Migration[] = [...internalMigrations];\n\n const umzugProvider = new Umzug({\n storage: createStorage({ db, tableName: 'strapi_migrations_internal' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.debug(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: () =>\n migrations.map((migration) => {\n return {\n name: migration.name,\n up: wrapTransaction(context.db)(migration.up),\n down: wrapTransaction(context.db)(migration.down),\n };\n }),\n });\n\n return {\n async register(migration: Migration) {\n migrations.push(migration);\n },\n async shouldRun() {\n const pendingMigrations = await umzugProvider.pending();\n return pendingMigrations.length > 0;\n },\n async up() {\n await umzugProvider.up();\n },\n async down() {\n await umzugProvider.down();\n },\n };\n};\n"],"names":["createInternalMigrationProvider","db","context","migrations","internalMigrations","umzugProvider","Umzug","storage","createStorage","tableName","logger","info","message","debug","transformLogMessage","warn","error","map","migration","name","up","wrapTransaction","down","register","push","shouldRun","pendingMigrations","pending","length"],"mappings":";;;;;;;;AAUO,MAAMA,kCAAkC,CAACC,EAAAA,GAAAA;AAC9C,IAAA,MAAMC,OAAAA,GAAU;AAAED,QAAAA;AAAG,KAAA;AACrB,IAAA,MAAME,UAAAA,GAA0B;AAAIC,QAAAA,GAAAA;AAAmB,KAAA;IAEvD,MAAMC,aAAAA,GAAgB,IAAIC,WAAAA,CAAM;AAC9BC,QAAAA,OAAAA,EAASC,qBAAAA,CAAc;AAAEP,YAAAA,EAAAA;YAAIQ,SAAAA,EAAW;AAA6B,SAAA,CAAA;QACrEC,MAAAA,EAAQ;AACNC,YAAAA,IAAAA,CAAAA,CAAKC,OAAO,EAAA;;AAEVX,gBAAAA,EAAAA,CAAGS,MAAM,CAACG,KAAK,CAACC,2BAAoB,MAAA,EAAQF,OAAAA,CAAAA,CAAAA;AAC9C,YAAA,CAAA;AACAG,YAAAA,IAAAA,CAAAA,CAAKH,OAAO,EAAA;AACVX,gBAAAA,EAAAA,CAAGS,MAAM,CAACK,IAAI,CAACD,2BAAoB,MAAA,EAAQF,OAAAA,CAAAA,CAAAA;AAC7C,YAAA,CAAA;AACAI,YAAAA,KAAAA,CAAAA,CAAMJ,OAAO,EAAA;AACXX,gBAAAA,EAAAA,CAAGS,MAAM,CAACM,KAAK,CAACF,2BAAoB,OAAA,EAASF,OAAAA,CAAAA,CAAAA;AAC/C,YAAA,CAAA;AACAC,YAAAA,KAAAA,CAAAA,CAAMD,OAAO,EAAA;AACXX,gBAAAA,EAAAA,CAAGS,MAAM,CAACG,KAAK,CAACC,2BAAoB,OAAA,EAASF,OAAAA,CAAAA,CAAAA;AAC/C,YAAA;AACF,SAAA;AACAV,QAAAA,OAAAA;AACAC,QAAAA,UAAAA,EAAY,IACVA,UAAAA,CAAWc,GAAG,CAAC,CAACC,SAAAA,GAAAA;gBACd,OAAO;AACLC,oBAAAA,IAAAA,EAAMD,UAAUC,IAAI;AACpBC,oBAAAA,EAAAA,EAAIC,sBAAAA,CAAgBnB,OAAAA,CAAQD,EAAE,CAAA,CAAEiB,UAAUE,EAAE,CAAA;AAC5CE,oBAAAA,IAAAA,EAAMD,sBAAAA,CAAgBnB,OAAAA,CAAQD,EAAE,CAAA,CAAEiB,UAAUI,IAAI;AAClD,iBAAA;AACF,YAAA,CAAA;AACJ,KAAA,CAAA;IAEA,OAAO;AACL,QAAA,MAAMC,UAASL,SAAoB,EAAA;AACjCf,YAAAA,UAAAA,CAAWqB,IAAI,CAACN,SAAAA,CAAAA;AAClB,QAAA,CAAA;QACA,MAAMO,SAAAA,CAAAA,GAAAA;YACJ,MAAMC,iBAAAA,GAAoB,MAAMrB,aAAAA,CAAcsB,OAAO,EAAA;YACrD,OAAOD,iBAAAA,CAAkBE,MAAM,GAAG,CAAA;AACpC,QAAA,CAAA;QACA,MAAMR,EAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMf,cAAce,EAAE,EAAA;AACxB,QAAA,CAAA;QACA,MAAME,IAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMjB,cAAciB,IAAI,EAAA;AAC1B,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.mjs","sources":["../../src/migrations/internal.ts"],"sourcesContent":["import { Umzug } from 'umzug';\n\nimport { wrapTransaction } from './common';\nimport { internalMigrations } from './internal-migrations';\nimport { createStorage } from './storage';\nimport { transformLogMessage } from './logger';\n\nimport type { InternalMigrationProvider, Migration } from './common';\nimport type { Database } from '..';\n\nexport const createInternalMigrationProvider = (db: Database): InternalMigrationProvider => {\n const context = { db };\n const migrations: Migration[] = [...internalMigrations];\n\n const umzugProvider = new Umzug({\n storage: createStorage({ db, tableName: 'strapi_migrations_internal' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.debug(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: () =>\n migrations.map((migration) => {\n return {\n name: migration.name,\n up: wrapTransaction(context.db)(migration.up),\n down: wrapTransaction(context.db)(migration.down),\n };\n }),\n });\n\n return {\n async register(migration: Migration) {\n migrations.push(migration);\n },\n async shouldRun() {\n const pendingMigrations = await umzugProvider.pending();\n return pendingMigrations.length > 0;\n },\n async up() {\n await umzugProvider.up();\n },\n async down() {\n await umzugProvider.down();\n },\n };\n};\n"],"names":["createInternalMigrationProvider","db","context","migrations","internalMigrations","umzugProvider","Umzug","storage","createStorage","tableName","logger","info","message","debug","transformLogMessage","warn","error","map","migration","name","up","wrapTransaction","down","register","push","shouldRun","pendingMigrations","pending","length"],"mappings":";;;;;;AAUO,MAAMA,kCAAkC,CAACC,EAAAA,GAAAA;AAC9C,IAAA,MAAMC,
|
|
1
|
+
{"version":3,"file":"internal.mjs","sources":["../../src/migrations/internal.ts"],"sourcesContent":["import { Umzug } from 'umzug';\n\nimport { wrapTransaction } from './common';\nimport { internalMigrations } from './internal-migrations';\nimport { createStorage } from './storage';\nimport { transformLogMessage } from './logger';\n\nimport type { InternalMigrationProvider, Migration } from './common';\nimport type { Database } from '..';\n\nexport const createInternalMigrationProvider = (db: Database): InternalMigrationProvider => {\n const context = { db };\n const migrations: Migration[] = [...internalMigrations];\n\n const umzugProvider = new Umzug({\n storage: createStorage({ db, tableName: 'strapi_migrations_internal' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.debug(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: () =>\n migrations.map((migration) => {\n return {\n name: migration.name,\n up: wrapTransaction(context.db)(migration.up),\n down: wrapTransaction(context.db)(migration.down),\n };\n }),\n });\n\n return {\n async register(migration: Migration) {\n migrations.push(migration);\n },\n async shouldRun() {\n const pendingMigrations = await umzugProvider.pending();\n return pendingMigrations.length > 0;\n },\n async up() {\n await umzugProvider.up();\n },\n async down() {\n await umzugProvider.down();\n },\n };\n};\n"],"names":["createInternalMigrationProvider","db","context","migrations","internalMigrations","umzugProvider","Umzug","storage","createStorage","tableName","logger","info","message","debug","transformLogMessage","warn","error","map","migration","name","up","wrapTransaction","down","register","push","shouldRun","pendingMigrations","pending","length"],"mappings":";;;;;;AAUO,MAAMA,kCAAkC,CAACC,EAAAA,GAAAA;AAC9C,IAAA,MAAMC,OAAAA,GAAU;AAAED,QAAAA;AAAG,KAAA;AACrB,IAAA,MAAME,UAAAA,GAA0B;AAAIC,QAAAA,GAAAA;AAAmB,KAAA;IAEvD,MAAMC,aAAAA,GAAgB,IAAIC,KAAAA,CAAM;AAC9BC,QAAAA,OAAAA,EAASC,aAAAA,CAAc;AAAEP,YAAAA,EAAAA;YAAIQ,SAAAA,EAAW;AAA6B,SAAA,CAAA;QACrEC,MAAAA,EAAQ;AACNC,YAAAA,IAAAA,CAAAA,CAAKC,OAAO,EAAA;;AAEVX,gBAAAA,EAAAA,CAAGS,MAAM,CAACG,KAAK,CAACC,oBAAoB,MAAA,EAAQF,OAAAA,CAAAA,CAAAA;AAC9C,YAAA,CAAA;AACAG,YAAAA,IAAAA,CAAAA,CAAKH,OAAO,EAAA;AACVX,gBAAAA,EAAAA,CAAGS,MAAM,CAACK,IAAI,CAACD,oBAAoB,MAAA,EAAQF,OAAAA,CAAAA,CAAAA;AAC7C,YAAA,CAAA;AAC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
|
|
1
|
-
{"version":3,"file":"logger.js","sources":["../../src/migrations/logger.ts"],"sourcesContent":["export const transformLogMessage = (level: string, message: unknown) => {\n if (typeof message === 'string') {\n return { level, message };\n }\n\n if (typeof message === 'object' && message !== null) {\n if ('event' in message && 'name' in message) {\n return {\n level,\n message: `[internal migration]: ${message.event} ${message?.name}`,\n timestamp: Date.now(),\n };\n }\n }\n\n // NOTE: the message typing are too loose so in practice we should never arrive here.\n return '';\n};\n"],"names":["transformLogMessage","level","message","event","name","timestamp","Date","now"],"mappings":";;AAAO,MAAMA,
|
|
1
|
+
{"version":3,"file":"logger.js","sources":["../../src/migrations/logger.ts"],"sourcesContent":["export const transformLogMessage = (level: string, message: unknown) => {\n if (typeof message === 'string') {\n return { level, message };\n }\n\n if (typeof message === 'object' && message !== null) {\n if ('event' in message && 'name' in message) {\n return {\n level,\n message: `[internal migration]: ${message.event} ${message?.name}`,\n timestamp: Date.now(),\n };\n }\n }\n\n // NOTE: the message typing are too loose so in practice we should never arrive here.\n return '';\n};\n"],"names":["transformLogMessage","level","message","event","name","timestamp","Date","now"],"mappings":";;AAAO,MAAMA,mBAAAA,GAAsB,CAACC,KAAAA,EAAeC,OAAAA,GAAAA;IACjD,IAAI,OAAOA,YAAY,QAAA,EAAU;QAC/B,OAAO;AAAED,YAAAA,KAAAA;AAAOC,YAAAA;AAAQ,SAAA;AAC1B,IAAA;AAEA,IAAA,IAAI,OAAOA,OAAAA,KAAY,QAAA,IAAYA,OAAAA,KAAY,IAAA,EAAM;QACnD,IAAI,OAAA,IAAWA,OAAAA,IAAW,MAAA,IAAUA,OAAAA,EAAS;YAC3C,OAAO;AACLD,gBAAAA,KAAAA;gBACAC,OAAAA,EAAS,CAAC,sBAAsB,EAAEA,OAAAA,CAAQC,KAAK,CAAC,CAAC,EAAED,OAAAA,EAASE,IAAAA,CAAAA,CAAM;AAClEC,gBAAAA,SAAAA,EAAWC,KAAKC,GAAG;AACrB,aAAA;AACF,QAAA;AACF,IAAA;;IAGA,OAAO,EAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.mjs","sources":["../../src/migrations/logger.ts"],"sourcesContent":["export const transformLogMessage = (level: string, message: unknown) => {\n if (typeof message === 'string') {\n return { level, message };\n }\n\n if (typeof message === 'object' && message !== null) {\n if ('event' in message && 'name' in message) {\n return {\n level,\n message: `[internal migration]: ${message.event} ${message?.name}`,\n timestamp: Date.now(),\n };\n }\n }\n\n // NOTE: the message typing are too loose so in practice we should never arrive here.\n return '';\n};\n"],"names":["transformLogMessage","level","message","event","name","timestamp","Date","now"],"mappings":"AAAO,MAAMA,
|
|
1
|
+
{"version":3,"file":"logger.mjs","sources":["../../src/migrations/logger.ts"],"sourcesContent":["export const transformLogMessage = (level: string, message: unknown) => {\n if (typeof message === 'string') {\n return { level, message };\n }\n\n if (typeof message === 'object' && message !== null) {\n if ('event' in message && 'name' in message) {\n return {\n level,\n message: `[internal migration]: ${message.event} ${message?.name}`,\n timestamp: Date.now(),\n };\n }\n }\n\n // NOTE: the message typing are too loose so in practice we should never arrive here.\n return '';\n};\n"],"names":["transformLogMessage","level","message","event","name","timestamp","Date","now"],"mappings":"AAAO,MAAMA,mBAAAA,GAAsB,CAACC,KAAAA,EAAeC,OAAAA,GAAAA;IACjD,IAAI,OAAOA,YAAY,QAAA,EAAU;QAC/B,OAAO;AAAED,YAAAA,KAAAA;AAAOC,YAAAA;AAAQ,SAAA;AAC1B,IAAA;AAEA,IAAA,IAAI,OAAOA,OAAAA,KAAY,QAAA,IAAYA,OAAAA,KAAY,IAAA,EAAM;QACnD,IAAI,OAAA,IAAWA,OAAAA,IAAW,MAAA,IAAUA,OAAAA,EAAS;YAC3C,OAAO;AACLD,gBAAAA,KAAAA;gBACAC,OAAAA,EAAS,CAAC,sBAAsB,EAAEA,OAAAA,CAAQC,KAAK,CAAC,CAAC,EAAED,OAAAA,EAASE,IAAAA,CAAAA,CAAM;AAClEC,gBAAAA,SAAAA,EAAWC,KAAKC,GAAG;AACrB,aAAA;AACF,QAAA;AACF,IAAA;;IAGA,OAAO,EAAA;AACT;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sources":["../../src/migrations/storage.ts"],"sourcesContent":["import type { Database } from '..';\n\nexport interface Options {\n db: Database;\n tableName: string;\n}\n\nexport const createStorage = (opts: Options) => {\n const { db, tableName } = opts;\n\n const hasMigrationTable = () => db.getSchemaConnection().hasTable(tableName);\n\n const createMigrationTable = () => {\n return db.getSchemaConnection().createTable(tableName, (table) => {\n table.increments('id');\n table.string('name');\n table.datetime('time', { useTz: false });\n });\n };\n\n return {\n async logMigration({ name }: { name: string }) {\n await db\n .getConnection()\n .insert({\n name,\n time: new Date(),\n })\n .into(tableName);\n },\n\n async unlogMigration({ name }: { name: string }) {\n await db.getConnection(tableName).del().where({ name });\n },\n\n async executed() {\n if (!(await hasMigrationTable())) {\n await createMigrationTable();\n return [];\n }\n\n const logs = await db.getConnection(tableName).select().from(tableName).orderBy('time');\n\n return logs.map((log: { name: string }) => log.name);\n },\n };\n};\n"],"names":["createStorage","opts","db","tableName","hasMigrationTable","getSchemaConnection","hasTable","createMigrationTable","createTable","table","increments","string","datetime","useTz","logMigration","name","getConnection","insert","time","Date","into","unlogMigration","del","where","executed","logs","select","from","orderBy","map","log"],"mappings":";;AAOO,MAAMA,gBAAgB,CAACC,IAAAA,GAAAA;AAC5B,IAAA,MAAM,EAAEC,EAAE,EAAEC,SAAS,EAAE,GAAGF,IAAAA;AAE1B,IAAA,MAAMG,oBAAoB,IAAMF,EAAAA,CAAGG,mBAAmB,EAAA,CAAGC,QAAQ,CAACH,SAAAA,CAAAA;AAElE,IAAA,MAAMI,
|
|
1
|
+
{"version":3,"file":"storage.js","sources":["../../src/migrations/storage.ts"],"sourcesContent":["import type { Database } from '..';\n\nexport interface Options {\n db: Database;\n tableName: string;\n}\n\nexport const createStorage = (opts: Options) => {\n const { db, tableName } = opts;\n\n const hasMigrationTable = () => db.getSchemaConnection().hasTable(tableName);\n\n const createMigrationTable = () => {\n return db.getSchemaConnection().createTable(tableName, (table) => {\n table.increments('id');\n table.string('name');\n table.datetime('time', { useTz: false });\n });\n };\n\n return {\n async logMigration({ name }: { name: string }) {\n await db\n .getConnection()\n .insert({\n name,\n time: new Date(),\n })\n .into(tableName);\n },\n\n async unlogMigration({ name }: { name: string }) {\n await db.getConnection(tableName).del().where({ name });\n },\n\n async executed() {\n if (!(await hasMigrationTable())) {\n await createMigrationTable();\n return [];\n }\n\n const logs = await db.getConnection(tableName).select().from(tableName).orderBy('time');\n\n return logs.map((log: { name: string }) => log.name);\n },\n };\n};\n"],"names":["createStorage","opts","db","tableName","hasMigrationTable","getSchemaConnection","hasTable","createMigrationTable","createTable","table","increments","string","datetime","useTz","logMigration","name","getConnection","insert","time","Date","into","unlogMigration","del","where","executed","logs","select","from","orderBy","map","log"],"mappings":";;AAOO,MAAMA,gBAAgB,CAACC,IAAAA,GAAAA;AAC5B,IAAA,MAAM,EAAEC,EAAE,EAAEC,SAAS,EAAE,GAAGF,IAAAA;AAE1B,IAAA,MAAMG,oBAAoB,IAAMF,EAAAA,CAAGG,mBAAmB,EAAA,CAAGC,QAAQ,CAACH,SAAAA,CAAAA;AAElE,IAAA,MAAMI,oBAAAA,GAAuB,IAAA;AAC3B,QAAA,OAAOL,GAAGG,mBAAmB,EAAA,CAAGG,WAAW,CAACL,WAAW,CAACM,KAAAA,GAAAA;AACtDA,YAAAA,KAAAA,CAAMC,UAAU,CAAC,IAAA,CAAA;AACjBD,YAAAA,KAAAA,CAAME,MAAM,CAAC,MAAA,CAAA;YACbF,KAAAA,CAAMG,QAAQ,CAAC,MAAA,EAAQ;gBAAEC,KAAAA,EAAO;AAAM,aAAA,CAAA;AACxC,QAAA,CAAA,CAAA;AACF,IAAA,CAAA;IAEA,OAAO;QACL,MAAMC,YAAAA,CAAAA,CAAa,EAAEC,IAAI,EAAoB,EAAA;AAC3C,YAAA,MAAMb,EAAAA,CACHc,aAAa,EAAA,CACbC,MAAM,CAAC;AACNF,gBAAAA,IAAAA;AACAG,gBAAAA,IAAAA,EAAM,IAAIC,IAAAA;AACZ,aAAA,CAAA,CACCC,IAAI,CAACjB,SAAAA,CAAAA;AACV,QAAA,CAAA;QAEA,MAAMkB,cAAAA,CAAAA,CAAe,EAAEN,IAAI,EAAoB,EAAA;AAC7C,YAAA,MAAMb,GAAGc,aAAa,CAACb,WAAWmB,GAAG,EAAA,CAAGC,KAAK,CAAC;AAAER,gBAAAA;AAAK,aAAA,CAAA;AACvD,QAAA,CAAA;QAEA,MAAMS,QAAAA,CAAAA,GAAAA;YACJ,IAAI,CAAE,MAAMpB,iBAAAA,EAAAA,EAAsB;gBAChC,MAAMG,oBAAAA,EAAAA;AACN,gBAAA,OAAO,EAAE;AACX,YAAA;AAEA,YAAA,MAAMkB,IAAAA,GAAO,MAAMvB,EAAAA,CAAGc,aAAa,CAACb,SAAAA,CAAAA,CAAWuB,MAAM,EAAA,CAAGC,IAAI,CAACxB,SAAAA,CAAAA,CAAWyB,OAAO,CAAC,MAAA,CAAA;AAEhF,YAAA,OAAOH,KAAKI,GAAG,CAAC,CAACC,GAAAA,GAA0BA,IAAIf,IAAI,CAAA;AACrD,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.mjs","sources":["../../src/migrations/storage.ts"],"sourcesContent":["import type { Database } from '..';\n\nexport interface Options {\n db: Database;\n tableName: string;\n}\n\nexport const createStorage = (opts: Options) => {\n const { db, tableName } = opts;\n\n const hasMigrationTable = () => db.getSchemaConnection().hasTable(tableName);\n\n const createMigrationTable = () => {\n return db.getSchemaConnection().createTable(tableName, (table) => {\n table.increments('id');\n table.string('name');\n table.datetime('time', { useTz: false });\n });\n };\n\n return {\n async logMigration({ name }: { name: string }) {\n await db\n .getConnection()\n .insert({\n name,\n time: new Date(),\n })\n .into(tableName);\n },\n\n async unlogMigration({ name }: { name: string }) {\n await db.getConnection(tableName).del().where({ name });\n },\n\n async executed() {\n if (!(await hasMigrationTable())) {\n await createMigrationTable();\n return [];\n }\n\n const logs = await db.getConnection(tableName).select().from(tableName).orderBy('time');\n\n return logs.map((log: { name: string }) => log.name);\n },\n };\n};\n"],"names":["createStorage","opts","db","tableName","hasMigrationTable","getSchemaConnection","hasTable","createMigrationTable","createTable","table","increments","string","datetime","useTz","logMigration","name","getConnection","insert","time","Date","into","unlogMigration","del","where","executed","logs","select","from","orderBy","map","log"],"mappings":"AAOO,MAAMA,gBAAgB,CAACC,IAAAA,GAAAA;AAC5B,IAAA,MAAM,EAAEC,EAAE,EAAEC,SAAS,EAAE,GAAGF,IAAAA;AAE1B,IAAA,MAAMG,oBAAoB,IAAMF,EAAAA,CAAGG,mBAAmB,EAAA,CAAGC,QAAQ,CAACH,SAAAA,CAAAA;AAElE,IAAA,MAAMI,
|
|
1
|
+
{"version":3,"file":"storage.mjs","sources":["../../src/migrations/storage.ts"],"sourcesContent":["import type { Database } from '..';\n\nexport interface Options {\n db: Database;\n tableName: string;\n}\n\nexport const createStorage = (opts: Options) => {\n const { db, tableName } = opts;\n\n const hasMigrationTable = () => db.getSchemaConnection().hasTable(tableName);\n\n const createMigrationTable = () => {\n return db.getSchemaConnection().createTable(tableName, (table) => {\n table.increments('id');\n table.string('name');\n table.datetime('time', { useTz: false });\n });\n };\n\n return {\n async logMigration({ name }: { name: string }) {\n await db\n .getConnection()\n .insert({\n name,\n time: new Date(),\n })\n .into(tableName);\n },\n\n async unlogMigration({ name }: { name: string }) {\n await db.getConnection(tableName).del().where({ name });\n },\n\n async executed() {\n if (!(await hasMigrationTable())) {\n await createMigrationTable();\n return [];\n }\n\n const logs = await db.getConnection(tableName).select().from(tableName).orderBy('time');\n\n return logs.map((log: { name: string }) => log.name);\n },\n };\n};\n"],"names":["createStorage","opts","db","tableName","hasMigrationTable","getSchemaConnection","hasTable","createMigrationTable","createTable","table","increments","string","datetime","useTz","logMigration","name","getConnection","insert","time","Date","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AA,MAAMkB,IAAAA,GAAO,MAAMvB,EAAAA,CAAGc,aAAa,CAACb,SAAAA,CAAAA,CAAWuB,MAAM,EAAA,CAAGC,IAAI,CAACxB,SAAAA,CAAAA,CAAWyB,OAAO,CAAC,MAAA,CAAA;AAEhF,YAAA,OAAOH,KAAKI,GAAG,CAAC,CAACC,GAAAA,GAA0BA,IAAIf,IAAI,CAAA;AACrD,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.js","sources":["../../src/migrations/users.ts"],"sourcesContent":["import fse from 'fs-extra';\nimport { Umzug } from 'umzug';\n\nimport { createStorage } from './storage';\nimport { wrapTransaction } from './common';\nimport { transformLogMessage } from './logger';\n\nimport type { MigrationResolver, UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\n// TODO: check multiple commands in one sql statement\nconst migrationResolver: MigrationResolver = ({ name, path, context }) => {\n const { db } = context;\n\n if (!path) {\n throw new Error(`Migration ${name} has no path`);\n }\n\n // if sql file run with knex raw\n if (path.match(/\\.sql$/)) {\n const sql = fse.readFileSync(path, 'utf8');\n\n return {\n name,\n up: wrapTransaction(db)((knex) => knex.raw(sql)),\n async down() {\n throw new Error('Down migration is not supported for sql files');\n },\n };\n }\n\n // NOTE: we can add some ts register if we want to handle ts migration files at some point\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const migration = require(path);\n return {\n name,\n up: wrapTransaction(db)(migration.up),\n down: wrapTransaction(db)(migration.down),\n };\n};\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n const umzugProvider = new Umzug({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.info(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: {\n glob: ['*.{js,sql}', { cwd: dir }],\n resolve: migrationResolver,\n },\n });\n\n return {\n async shouldRun() {\n const pendingMigrations = await umzugProvider.pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await umzugProvider.up();\n },\n async down() {\n await umzugProvider.down();\n },\n };\n};\n"],"names":["migrationResolver","name","path","context","db","Error","match","sql","fse","readFileSync","up","wrapTransaction","knex","raw","down","migration","require","createUserMigrationProvider","dir","config","settings","migrations","ensureDirSync","umzugProvider","Umzug","storage","createStorage","tableName","logger","info","message","transformLogMessage","warn","error","debug","glob","cwd","resolve","shouldRun","pendingMigrations","pending","length","runMigrations"],"mappings":";;;;;;;;AAUA;AACA,MAAMA,iBAAAA,GAAuC,CAAC,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAA;IACnE,MAAM,EAAEC,EAAE,EAAE,GAAGD,OAAAA;AAEf,IAAA,IAAI,CAACD,
|
|
1
|
+
{"version":3,"file":"users.js","sources":["../../src/migrations/users.ts"],"sourcesContent":["import fse from 'fs-extra';\nimport { Umzug } from 'umzug';\n\nimport { createStorage } from './storage';\nimport { wrapTransaction } from './common';\nimport { transformLogMessage } from './logger';\n\nimport type { MigrationResolver, UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\n// TODO: check multiple commands in one sql statement\nconst migrationResolver: MigrationResolver = ({ name, path, context }) => {\n const { db } = context;\n\n if (!path) {\n throw new Error(`Migration ${name} has no path`);\n }\n\n // if sql file run with knex raw\n if (path.match(/\\.sql$/)) {\n const sql = fse.readFileSync(path, 'utf8');\n\n return {\n name,\n up: wrapTransaction(db)((knex) => knex.raw(sql)),\n async down() {\n throw new Error('Down migration is not supported for sql files');\n },\n };\n }\n\n // NOTE: we can add some ts register if we want to handle ts migration files at some point\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const migration = require(path);\n return {\n name,\n up: wrapTransaction(db)(migration.up),\n down: wrapTransaction(db)(migration.down),\n };\n};\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n const umzugProvider = new Umzug({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.info(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: {\n glob: ['*.{js,sql}', { cwd: dir }],\n resolve: migrationResolver,\n },\n });\n\n return {\n async shouldRun() {\n const pendingMigrations = await umzugProvider.pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await umzugProvider.up();\n },\n async down() {\n await umzugProvider.down();\n },\n };\n};\n"],"names":["migrationResolver","name","path","context","db","Error","match","sql","fse","readFileSync","up","wrapTransaction","knex","raw","down","migration","require","createUserMigrationProvider","dir","config","settings","migrations","ensureDirSync","umzugProvider","Umzug","storage","createStorage","tableName","logger","info","message","transformLogMessage","warn","error","debug","glob","cwd","resolve","shouldRun","pendingMigrations","pending","length","runMigrations"],"mappings":";;;;;;;;AAUA;AACA,MAAMA,iBAAAA,GAAuC,CAAC,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAA;IACnE,MAAM,EAAEC,EAAE,EAAE,GAAGD,OAAAA;AAEf,IAAA,IAAI,CAACD,IAAAA,EAAM;AACT,QAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,UAAU,EAAEJ,IAAAA,CAAK,YAAY,CAAC,CAAA;AACjD,IAAA;;IAGA,IAAIC,IAAAA,CAAKI,KAAK,CAAC,QAAA,CAAA,EAAW;AACxB,QAAA,MAAMC,GAAAA,GAAMC,GAAAA,CAAIC,YAAY,C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,gBAAAA,EAAAA,CAAGwB,MAAM,CAACI,IAAI,CAACD,2BAAoB,MAAA,EAAQD,OAAAA,CAAAA,CAAAA;AAC7C,YAAA,CAAA;AACAG,YAAAA,KAAAA,CAAAA,CAAMH,OAAO,EAAA;AACX1B,gBAAAA,EAAAA,CAAGwB,MAAM,CAACK,KAAK,CAACF,2BAAoB,OAAA,EAASD,OAAAA,CAAAA,CAAAA;AAC/C,YAAA,CAAA;AACAI,YAAAA,KAAAA,CAAAA,CAAMJ,OAAO,EAAA;AACX1B,gBAAAA,EAAAA,CAAGwB,MAAM,CAACM,KAAK,CAACH,2BAAoB,OAAA,EAASD,OAAAA,CAAAA,CAAAA;AAC/C,YAAA;AACF,SAAA;AACA3B,QAAAA,OAAAA;QACAkB,UAAAA,EAAY;YACVc,IAAAA,EAAM;AAAC,gBAAA,YAAA;AAAc,gBAAA;oBAAEC,GAAAA,EAAKlB;AAAI;AAAE,aAAA;YAClCmB,OAAAA,EAASrC;AACX;AACF,KAAA,CAAA;IAEA,OAAO;QACL,MAAMsC,SAAAA,CAAAA,GAAAA;YACJ,MAAMC,iBAAAA,GAAoB,MAAMhB,aAAAA,CAAciB,OAAO,EAAA;YACrD,OAAOD,iBAAAA,CAAkBE,MAAM,GAAG,CAAA,IAAKrC,GAAGe,MAAM,EAAEC,UAAUsB,aAAAA,KAAkB,IAAA;AAChF,QAAA,CAAA;QACA,MAAMhC,EAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMa,cAAcb,EAAE,EAAA;AACxB,QAAA,CAAA;QACA,MAAMI,IAAAA,CAAAA,GAAAA;AACJ,YAAA,MAAMS,cAAcT,IAAI,EAAA;AAC1B,QAAA;AACF,KAAA;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"users.mjs","sources":["../../src/migrations/users.ts"],"sourcesContent":["import fse from 'fs-extra';\nimport { Umzug } from 'umzug';\n\nimport { createStorage } from './storage';\nimport { wrapTransaction } from './common';\nimport { transformLogMessage } from './logger';\n\nimport type { MigrationResolver, UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\n// TODO: check multiple commands in one sql statement\nconst migrationResolver: MigrationResolver = ({ name, path, context }) => {\n const { db } = context;\n\n if (!path) {\n throw new Error(`Migration ${name} has no path`);\n }\n\n // if sql file run with knex raw\n if (path.match(/\\.sql$/)) {\n const sql = fse.readFileSync(path, 'utf8');\n\n return {\n name,\n up: wrapTransaction(db)((knex) => knex.raw(sql)),\n async down() {\n throw new Error('Down migration is not supported for sql files');\n },\n };\n }\n\n // NOTE: we can add some ts register if we want to handle ts migration files at some point\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const migration = require(path);\n return {\n name,\n up: wrapTransaction(db)(migration.up),\n down: wrapTransaction(db)(migration.down),\n };\n};\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n const umzugProvider = new Umzug({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.info(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: {\n glob: ['*.{js,sql}', { cwd: dir }],\n resolve: migrationResolver,\n },\n });\n\n return {\n async shouldRun() {\n const pendingMigrations = await umzugProvider.pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await umzugProvider.up();\n },\n async down() {\n await umzugProvider.down();\n },\n };\n};\n"],"names":["migrationResolver","name","path","context","db","Error","match","sql","fse","readFileSync","up","wrapTransaction","knex","raw","down","migration","require","createUserMigrationProvider","dir","config","settings","migrations","ensureDirSync","umzugProvider","Umzug","storage","createStorage","tableName","logger","info","message","transformLogMessage","warn","error","debug","glob","cwd","resolve","shouldRun","pendingMigrations","pending","length","runMigrations"],"mappings":";;;;;;AAUA;AACA,MAAMA,iBAAAA,GAAuC,CAAC,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAA;IACnE,MAAM,EAAEC,EAAE,EAAE,GAAGD,OAAAA;AAEf,IAAA,IAAI,CAACD,
|
|
1
|
+
{"version":3,"file":"users.mjs","sources":["../../src/migrations/users.ts"],"sourcesContent":["import fse from 'fs-extra';\nimport { Umzug } from 'umzug';\n\nimport { createStorage } from './storage';\nimport { wrapTransaction } from './common';\nimport { transformLogMessage } from './logger';\n\nimport type { MigrationResolver, UserMigrationProvider } from './common';\nimport type { Database } from '..';\n\n// TODO: check multiple commands in one sql statement\nconst migrationResolver: MigrationResolver = ({ name, path, context }) => {\n const { db } = context;\n\n if (!path) {\n throw new Error(`Migration ${name} has no path`);\n }\n\n // if sql file run with knex raw\n if (path.match(/\\.sql$/)) {\n const sql = fse.readFileSync(path, 'utf8');\n\n return {\n name,\n up: wrapTransaction(db)((knex) => knex.raw(sql)),\n async down() {\n throw new Error('Down migration is not supported for sql files');\n },\n };\n }\n\n // NOTE: we can add some ts register if we want to handle ts migration files at some point\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const migration = require(path);\n return {\n name,\n up: wrapTransaction(db)(migration.up),\n down: wrapTransaction(db)(migration.down),\n };\n};\n\nexport const createUserMigrationProvider = (db: Database): UserMigrationProvider => {\n const dir = db.config.settings.migrations.dir;\n\n fse.ensureDirSync(dir);\n\n const context = { db };\n\n const umzugProvider = new Umzug({\n storage: createStorage({ db, tableName: 'strapi_migrations' }),\n logger: {\n info(message) {\n // NOTE: only log internal migration in debug mode\n db.logger.info(transformLogMessage('info', message));\n },\n warn(message) {\n db.logger.warn(transformLogMessage('warn', message));\n },\n error(message) {\n db.logger.error(transformLogMessage('error', message));\n },\n debug(message) {\n db.logger.debug(transformLogMessage('debug', message));\n },\n },\n context,\n migrations: {\n glob: ['*.{js,sql}', { cwd: dir }],\n resolve: migrationResolver,\n },\n });\n\n return {\n async shouldRun() {\n const pendingMigrations = await umzugProvider.pending();\n return pendingMigrations.length > 0 && db.config?.settings?.runMigrations === true;\n },\n async up() {\n await umzugProvider.up();\n },\n async down() {\n await umzugProvider.down();\n },\n };\n};\n"],"names":["migrationResolver","name","path","context","db","Error","match","sql","fse","readFileSync","up","wrapTransaction","knex","raw","down","migration","require","createUserMigrationProvider","dir","config","settings","migrations","ensureDirSync","umzugProvider","Umzug","storage","createStorage","tableName","logger","info","message","transformLogMessage","warn","error","debug","glob","cwd","resolve","shouldRun","pendingMigrations","pending","length","runMigrations"],"mappings":";;;;;;AAUA;AACA,MAAMA,iBAAAA,GAAuC,CAAC,EAAEC,IAAI,EAAEC,IAAI,EAAEC,OAAO,EAAE,GAAA;IACnE,MAAM,EAAEC,EAAE,EAAE,GAAGD,OAAAA;AAEf,IAAA,IAAI,CAACD,IAAAA,EAAM;AACT,QAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,UAAU,EAAEJ,IAAAA,CAAK,YAAY,CAAC,CAAA;AACjD,IAAA;;IAGA,IAAIC,IAAAA,CAAKI,KAAK,CAAC,QAAA,CAAA,EAAW;AACxB,QAAA,MAAMC,GAAAA,GAAMC,GAAAA,CAAIC,YAAY,CAACP,IAAAA,EAAM,MAAA,CAAA;QAEnC,OAAO;AACLD,YAAAA,IAAAA;AACAS,YAAAA,EAAAA,EAAIC,gBAAgBP,EAAAA,CAAAA,CAAI,CAACQ,IAAAA,GAASA,IAAAA,CAAKC,GAAG,CAACN,GAAAA,CAAAA,CAAAA;YAC3C,MAAMO,IAAAA,CAAAA,GAAAA;AACJ,gBAAA,MAAM,IAAIT,KAAAA,CAAM,+CAAA,CAAA;AAClB,YAAA;AACF,SAAA;AACF,IAAA;;;AAIA,IAAA,MAAMU,YAAYC,OAAAA,CAAQd,IAAAA,CAAAA;IAC1B,OAAO;AACLD,QAAAA,IAAAA;QACAS,EAAAA,EAAIC,eAAAA,CAAgBP,EAAAA,CA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