Repository: sequelize/sequelize
File: packages/core/src/sequelize.js (JavaScript)

Code before:
      models.reverse();

      // Topologically sort by foreign key constraints to give us an appropriate
      // creation order
      for (const model of models) {
        await model.sync(options);
      }
    }

    if (options.hooks) {
      await this.hooks.runAsync('afterBulkSync', options);
    }

    return this;
  }

  /**
   * Used instead of sync() when two models reference each-other, so their foreign keys cannot be created immediately.
   *
   * @param {object} options - sync options
   * @private
   */
  async _syncModelsWithCyclicReferences(options) {
    if (this.dialect.name === 'sqlite') {
      // eslint-disable-next-line import/no-extraneous-dependencies -- only import when needed
      const { withSqliteForeignKeysOff } = await import('@sequelize/sqlite');
      // Optimisation: no need to do this in two passes in SQLite because we can temporarily disable foreign keys
      await withSqliteForeignKeysOff(this, options, async () => {
        for (const model of this.models) {
          await model.sync(options);
        }
      });

      return;
    }

    // create all tables, but don't create foreign key constraints
    for (const model of this.models) {
      await model.sync({ ...options, withoutForeignKeyConstraints: true });
    }

    // add foreign key constraints
    for (const model of this.models) {
      await model.sync({ ...options, force: false, alter: true });
    }
  }

  /**
   * Drop all tables defined through this sequelize instance.
   * This is done by calling {@link Model.drop} on each model.
   *

Review comment (suggestion):
This is not ideal however if the `@sequelize/sqlite` package becomes a dependency, we end up with having cyclic dependencies.

Code after:
      // reverse to start with the one model that does not depend on anything
      models.reverse();

      // Topologically sort by foreign key constraints to give us an appropriate
      // creation order
      for (const model of models) {
        await model.sync(options);
      }
    }

    if (options.hooks) {
      await this.hooks.runAsync('afterBulkSync', options);
    }

    return this;
  }

  /**
   * Used instead of sync() when two models reference each-other, so their foreign keys cannot be created immediately.
   *
   * @param {object} options - sync options
   * @private
   */
  async _syncModelsWithCyclicReferences(options) {
    if (this.dialect.name === 'sqlite') {
      // Optimisation: no need to do this in two passes in SQLite because we can temporarily disable foreign keys
      await withSqliteForeignKeysOff(this, options, async () => {
        for (const model of this.models) {
          await model.sync(options);
        }
      });

      return;
    }

    // create all tables, but don't create foreign key constraints
    for (const model of this.models) {
      await model.sync({ ...options, withoutForeignKeyConstraints: true });
    }

    // add foreign key constraints
    for (const model of this.models) {
      await model.sync({ ...options, force: false, alter: true });
    }
  }

  /**
   * Drop all tables defined through this sequelize instance.
   * This is done by calling {@link Model.drop} on each model.
   *
   * @param {object} [options] The options passed to each call to Model.drop