1
0
mirror of https://github.com/matt-fidd/stratos.git synced 2026-01-01 22:39:26 +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 = {
]
};
/**
* cleanDb() Removes all records from the tables in the database to be inserted
* into
*
* @param {dbConnectionPool} [dbConnectionPool] - The database connection
*
* @return {void}
*/
async function cleanDb(dbConnectionPool) {
/*
Cleans the database of any existing records that will
conflict with the test data
Arguments:
- database connection object
*/
// List of table names to be cleared
const deletionList = [
'studentParentLink',
'studentClassLink',
'accountClassLink',
'class',
'subject',
'parent',
'student',
'account'
];
for (const table of deletionList)
// Remove records from tables in reverse order to which they depend on
// each other
for (const table of Object.keys(data).reverse())
await dbConnectionPool.runQuery(`DELETE FROM ${table};`);
}