Skip to content

fix(mysql, singlestore): scope migration table lookup to current database#5503

Open
Shay12tg wants to merge 1 commit intodrizzle-team:betafrom
Shay12tg:fix/mysql-migration-table-schema
Open

fix(mysql, singlestore): scope migration table lookup to current database#5503
Shay12tg wants to merge 1 commit intodrizzle-team:betafrom
Shay12tg:fix/mysql-migration-table-schema

Conversation

@Shay12tg
Copy link

Problem

When running Drizzle migrations against multiple databases on the same MySQL
server, migrate() fails on any database that doesn't already have the
__drizzle_migrations table — even though Drizzle is supposed to create it
automatically.

The upgradeIfNeeded function checks information_schema.tables for the
migrations table, but doesn't filter by table_schema. This means it finds
the table in a different database, concludes the current database isn't new,
skips CREATE TABLE, and then fails when it tries to read from a table that
doesn't exist in the current database.

Postgres, CockroachDB, and MSSQL don't have this problem because they already
filter by migrationsSchema. MySQL and SingleStore were missing the equivalent
filter.

Fix

Add WHERE table_schema = DATABASE() to both information_schema queries in
the MySQL and SingleStore upgradeIfNeeded functions. DATABASE() returns the
currently selected database name — the MySQL equivalent of Postgres's schema
scoping.

2 files changed, 4 lines added:

  • drizzle-orm/src/up-migrations/mysql.ts
  • drizzle-orm/src/up-migrations/singlestore.ts

Copilot AI review requested due to automatic review settings March 17, 2026 15:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes MySQL/SingleStore migration bootstrapping when multiple databases exist on the same server by ensuring __drizzle_migrations existence/shape checks are scoped to the currently selected database.

Changes:

  • Scope information_schema.tables lookup with WHERE table_schema = DATABASE() in MySQL/SingleStore upgradeIfNeeded().
  • Scope information_schema.columns lookup with WHERE table_schema = DATABASE() in MySQL/SingleStore upgradeIfNeeded().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
drizzle-orm/src/up-migrations/mysql.ts Restricts migration table existence/column queries to the active MySQL database via DATABASE().
drizzle-orm/src/up-migrations/singlestore.ts Applies the same current-database scoping for SingleStore’s information_schema checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants