Update PostgresStorageAdapter.js (#4094)
* proper use of the connections * proper integrity: creating tables within a single transaction.
This commit is contained in:
committed by
Florent Vilmart
parent
c6546218f4
commit
2b4c7570ea
@@ -668,10 +668,12 @@ export class PostgresStorageAdapter {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// Create the relation tables
|
return conn.tx('create-relation-tables', t => {
|
||||||
return Promise.all(relations.map((fieldName) => {
|
const queries = relations.map((fieldName) => {
|
||||||
return conn.none('CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )', {joinTable: `_Join:${fieldName}:${className}`});
|
return t.none('CREATE TABLE IF NOT EXISTS $<joinTable:name> ("relatedId" varChar(120), "owningId" varChar(120), PRIMARY KEY("relatedId", "owningId") )', {joinTable: `_Join:${fieldName}:${className}`});
|
||||||
}));
|
});
|
||||||
|
return t.batch(queries);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user