Skip to content

Commit 45f021e

Browse files
committed
drop tables afterEach for PG, clean up relation tables too
1 parent 8e1069c commit 45f021e

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

spec/helper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ afterEach(function(done) {
170170
if (Object.keys(openConnections).length > 0) {
171171
fail('There were open connections to the server left after the test finished');
172172
}
173-
done();
173+
on_db('postgres', () => {
174+
TestUtils.destroyAllDataPermanently().then(done, done);
175+
}, done);
174176
};
175177
Parse.Cloud._removeAllHooks();
176178
databaseAdapter.getAllClasses()

src/Adapters/Storage/Postgres/PostgresStorageAdapter.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,17 @@ export class PostgresStorageAdapter {
417417

418418
// Delete all data known to this adapter. Used for testing.
419419
deleteAllClasses() {
420-
return this._client.any('SELECT "className" FROM "_SCHEMA"')
420+
return this._client.any('SELECT * FROM "_SCHEMA"')
421421
.then(results => {
422-
const classes = ['_SCHEMA','_PushStatus','_Hooks','_GlobalConfig', ...results.map(result => result.className)];
422+
let joins = results.reduce((list, schema) => {
423+
Object.keys(schema.schema.fields).forEach((field) => {
424+
if (schema.schema.fields[field].type === 'Relation') {
425+
list.push(`_Join:${field}:${schema.className}`);
426+
}
427+
})
428+
return list;
429+
}, []);
430+
const classes = ['_SCHEMA','_PushStatus','_Hooks','_GlobalConfig', ...results.map(result => result.className), ...joins];
423431
return this._client.tx(t=>t.batch(classes.map(className=>t.none('DROP TABLE IF EXISTS $<className:name>', { className }))));
424432
}, error => {
425433
if (error.code === PostgresRelationDoesNotExistError) {

0 commit comments

Comments
 (0)