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/postgres.tsmodified+10-0
Changes to packages/bun-query-builder/src/drivers/postgres.ts
@@ -186,6 +186,16 @@ export class PostgresDriver implements DialectDriver {
186186 parts.push(defaultValue)
187187 }
188188
189 // PostgreSQL FKs are added via a separate `ALTER TABLE … ADD
190 // CONSTRAINT FOREIGN KEY` pass (see migrations.ts), NOT inline.
191 // Postgres strictly requires the referenced table to exist
192 // before CREATE TABLE with an inline FK, so the deferred-ALTER
193 // form sidesteps dependency-ordering questions when
194 // `plan.tables` is iterated in (e.g.) alphabetical order.
195 // SQLite is the only driver where the inline path is forced —
196 // it doesn't support ALTER TABLE ADD CONSTRAINT and is lenient
197 // about forward-reference targets.
198
189199 return parts.join(' ')
190200 }
191201}