Skip to content

Commit 0ef123b

Browse files
rsslldnphyclaude
andcommitted
Don't create extensions inside a transaction
Extensions created inside a transaction don't make their objects (functions, types, etc.) available to subsequent statements in that transaction, which causes `db push` to fail when tables reference extension-provided defaults like `uuid_generate_v4()`. Move schema and extension creation before the transaction so their objects are available when tables are created. Closes #332 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e1120da commit 0ef123b

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

packages/orm-migrate/src/push.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ export const push = async (db: Orm) => {
1313
);
1414
console.log(`Pushing schemas ${toSentence(schemas)} to database`);
1515

16-
await db.transact(async (db) => {
17-
for (const schema of schemas.values()) {
18-
console.log(` - Creating schema "${schema}"`);
19-
await db.query(createSchemaSql(schema));
16+
for (const schema of schemas.values()) {
17+
console.log(` - Creating schema "${schema}"`);
18+
await db.query(createSchemaSql(schema));
19+
}
20+
for (const extension of db.config.extensions) {
21+
console.log(` - Creating extension "${extension}"`);
22+
for (const schema of schemas) {
23+
await db.query(createExtensionsSql(schema, extension));
2024
}
21-
for (const extension of db.config.extensions) {
22-
console.log(` - Creating extension "${extension}"`);
23-
for (const schema of schemas) {
24-
await db.query(createExtensionsSql(schema, extension));
25-
}
2625

27-
if (!schemas.has("public")) {
28-
await db.query(createExtensionsSql("public", extension));
29-
}
26+
if (!schemas.has("public")) {
27+
await db.query(createExtensionsSql("public", extension));
3028
}
29+
}
30+
31+
await db.transact(async (db) => {
3132
for (const model of Object.values(db.config.models)) {
3233
console.log(` - Creating table "${model.schema}"."${model.table}"`);
3334
await db.query(createTableSql(model));

0 commit comments

Comments
 (0)