Skip to content

Commit 2b4c757

Browse files
vitaly-tflovilmart
authored andcommitted
Update PostgresStorageAdapter.js (#4094)
* proper use of the connections * proper integrity: creating tables within a single transaction.
1 parent c654621 commit 2b4c757

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,12 @@ export class PostgresStorageAdapter {
668668
throw error;
669669
}
670670
}).then(() => {
671-
// Create the relation tables
672-
return Promise.all(relations.map((fieldName) => {
673-
return conn.none('CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )', {joinTable: `_Join:${fieldName}:${className}`});
674-
}));
671+
return conn.tx('create-relation-tables', t => {
672+
const queries = relations.map((fieldName) => {
673+
return t.none('CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )', {joinTable: `_Join:${fieldName}:${className}`});
674+
});
675+
return t.batch(queries);
676+
});
675677
});
676678
}
677679

0 commit comments

Comments
 (0)