@strapi/database 5.0.0-beta.4 → 5.0.0-beta.6

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/index.mjs CHANGED
@@ -5856,7 +5856,7 @@ const createStorage = (opts) => {
5856
5856
  };
5857
5857
  };
5858
5858
  const wrapTransaction = (db) => (fn) => () => {
5859
- return db.connection.transaction((trx) => Promise.resolve(fn(trx, db)));
5859
+ return db.transaction(({ trx }) => Promise.resolve(fn(trx, db)));
5860
5860
  };
5861
5861
  const migrationResolver = ({ name, path: path2, context }) => {
5862
5862
  const { db } = context;
@@ -5986,15 +5986,13 @@ const migrateDocumentIdsWithLocalizations = async (db, knex2, meta) => {
5986
5986
  } while (ids.length > 0);
5987
5987
  };
5988
5988
  const migrationDocumentIds = async (db, knex2, meta) => {
5989
- let run = true;
5989
+ let updatedRows;
5990
5990
  do {
5991
- const updatedRows = await knex2(meta.tableName).update({ document_id: createId() }).whereIn("id", (builder) => {
5992
- return builder.whereNull("document_id").select("id").limit(1);
5993
- });
5994
- if (updatedRows <= 0) {
5995
- run = false;
5996
- }
5997
- } while (run);
5991
+ updatedRows = await knex2(meta.tableName).update({ document_id: createId() }).whereIn(
5992
+ "id",
5993
+ knex2(meta.tableName).select("id").from(knex2(meta.tableName).select("id").whereNull("document_id").limit(1).as("sub_query"))
5994
+ );
5995
+ } while (updatedRows > 0);
5998
5996
  };
5999
5997
  const createDocumentIdColumn = async (knex2, tableName) => {
6000
5998
  await knex2.schema.alterTable(tableName, (table) => {
@@ -6182,11 +6180,12 @@ const internalMigrations = [
6182
6180
  ];
6183
6181
  const createInternalMigrationProvider = (db) => {
6184
6182
  const context = { db };
6183
+ const migrations = [...internalMigrations];
6185
6184
  const umzugProvider = new Umzug({
6186
6185
  storage: createStorage({ db, tableName: "strapi_migrations_internal" }),
6187
6186
  logger: console,
6188
6187
  context,
6189
- migrations: internalMigrations.map((migration) => {
6188
+ migrations: () => migrations.map((migration) => {
6190
6189
  return {
6191
6190
  name: migration.name,
6192
6191
  up: wrapTransaction(context.db)(migration.up),
@@ -6195,6 +6194,9 @@ const createInternalMigrationProvider = (db) => {
6195
6194
  })
6196
6195
  });
6197
6196
  return {
6197
+ async register(migration) {
6198
+ migrations.push(migration);
6199
+ },
6198
6200
  async shouldRun() {
6199
6201
  const pendingMigrations = await umzugProvider.pending();
6200
6202
  return pendingMigrations.length > 0;
@@ -6208,8 +6210,13 @@ const createInternalMigrationProvider = (db) => {
6208
6210
  };
6209
6211
  };
6210
6212
  const createMigrationsProvider = (db) => {
6211
- const providers = [createUserMigrationProvider(db), createInternalMigrationProvider(db)];
6213
+ const userProvider = createUserMigrationProvider(db);
6214
+ const internalProvider = createInternalMigrationProvider(db);
6215
+ const providers = [userProvider, internalProvider];
6212
6216
  return {
6217
+ providers: {
6218
+ internal: internalProvider
6219
+ },
6213
6220
  async shouldRun() {
6214
6221
  const shouldRunResponses = await Promise.all(
6215
6222
  providers.map((provider) => provider.shouldRun())