1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 23:19:29 +00:00

Rewrite cleanDb to be more dynamic

This commit is contained in:
2022-02-24 23:16:24 +00:00
parent e6b260613e
commit 187c3a8b64

View File

@@ -357,28 +357,18 @@ const relationships = {
] ]
}; };
async function cleanDb(dbConnectionPool) { /**
/* * cleanDb() Removes all records from the tables in the database to be inserted
Cleans the database of any existing records that will * into
conflict with the test data *
* @param {dbConnectionPool} [dbConnectionPool] - The database connection
Arguments: *
- database connection object * @return {void}
*/ */
async function cleanDb(dbConnectionPool) {
// List of table names to be cleared // Remove records from tables in reverse order to which they depend on
const deletionList = [ // each other
'studentParentLink', for (const table of Object.keys(data).reverse())
'studentClassLink',
'accountClassLink',
'class',
'subject',
'parent',
'student',
'account'
];
for (const table of deletionList)
await dbConnectionPool.runQuery(`DELETE FROM ${table};`); await dbConnectionPool.runQuery(`DELETE FROM ${table};`);
} }