fix(mysql, singlestore): scope migration table lookup to current database#5503
Open
Shay12tg wants to merge 1 commit intodrizzle-team:betafrom
Open
fix(mysql, singlestore): scope migration table lookup to current database#5503Shay12tg wants to merge 1 commit intodrizzle-team:betafrom
Shay12tg wants to merge 1 commit intodrizzle-team:betafrom
Conversation
There was a problem hiding this comment.
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.tableslookup withWHERE table_schema = DATABASE()in MySQL/SingleStoreupgradeIfNeeded(). - Scope
information_schema.columnslookup withWHERE table_schema = DATABASE()in MySQL/SingleStoreupgradeIfNeeded().
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_migrationstable — even though Drizzle is supposed to create itautomatically.
The
upgradeIfNeededfunction checksinformation_schema.tablesfor themigrations table, but doesn't filter by
table_schema. This means it findsthe 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 thatdoesn'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 equivalentfilter.
Fix
Add
WHERE table_schema = DATABASE()to bothinformation_schemaqueries inthe MySQL and SingleStore
upgradeIfNeededfunctions.DATABASE()returns thecurrently selected database name — the MySQL equivalent of Postgres's schema
scoping.
2 files changed, 4 lines added:
drizzle-orm/src/up-migrations/mysql.tsdrizzle-orm/src/up-migrations/singlestore.ts