Skip to content

Sequelize#sync({ force: true, schema }) drops tables in the default schema #18423

Open

Description

@wikirik-agent

Sequelize#sync calls this.drop({ ...options }) (sequelize.js:487) before syncing each model. Sequelize#drop (:557) calls model.drop(options) → queryInterface.dropTable(model), which uses the model's own table and ignores options.schema.

With two models and sequelize.sync({ force: true, schema: 'tenant' }) on postgres:

DROP TABLE IF EXISTS "Us" CASCADE          <- default schema
DROP TABLE IF EXISTS "Ts" CASCADE
...
DROP TABLE IF EXISTS "tenant"."Us" CASCADE <- correct, from Model.sync
CREATE TABLE IF NOT EXISTS "tenant"."Us" (...)

schema is documented SyncOptions API (sequelize.d.ts:64), so this destroys default-schema tables during what should be a tenant-scoped sync.

#18406 fixes the equivalent bug in Model.sync but not this one. The fix needs care: the bulk drop exists for foreign-key topological ordering, so it can't simply be skipped when schema is set.

Activity

  1. added
    pending-approval
    on Sep 18, 2026
  2. Yahiro025 commented on Sep 22, 2026

    @Yahiro025

    I'll work on a fix for this — sequelize.sync({ force: true, schema }) still drops default-schema tables via the bulk drop path that #18406 didn't cover. Opening a PR shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pending-approval

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions