ReviewOS

also looking at this

stacks/bun-query-builder

fix(schema): emit inline FOREIGN KEY on SQLite CREATE TABLE (#1019)

#1020
Merged glennmichael123 wants to merge fix/inline-foreign-keys into main
6 files +239 -10
packages/bun-query-builder/src/drivers/mysql.tsmodified+11-0
Changes to packages/bun-query-builder/src/drivers/mysql.ts
@@ -205,6 +205,17 @@ export class MySQLDriver implements DialectDriver {
205205 parts.push(defaultValue)
206206 }
207207
208 // MySQL FKs are added via a separate `ALTER TABLE … ADD
209 // CONSTRAINT FOREIGN KEY` pass (see migrations.ts), NOT inline.
210 // MySQL strictly requires the referenced table to exist before
211 // CREATE TABLE with an inline FK, which makes inline FKs in the
212 // initial-migration pass fragile when `plan.tables` is
213 // alphabetically ordered (e.g. `comments` before `users`). The
214 // deferred-ALTER form sidesteps the dependency order entirely.
215 // SQLite is the only driver where the inline path is forced —
216 // it doesn't support ALTER TABLE ADD CONSTRAINT and is lenient
217 // about forward-reference targets.
218
208219 return parts.join(' ')
209220 }
210221}