mirror of
https://github.com/matt-fidd/stratos.git
synced 2026-01-01 22:59:28 +00:00
Rewrite cleanDb to be more dynamic
This commit is contained in:
@@ -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) {
|
async function cleanDb(dbConnectionPool) {
|
||||||
/*
|
// Remove records from tables in reverse order to which they depend on
|
||||||
Cleans the database of any existing records that will
|
// each other
|
||||||
conflict with the test data
|
for (const table of Object.keys(data).reverse())
|
||||||
|
|
||||||
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)
|
|
||||||
await dbConnectionPool.runQuery(`DELETE FROM ${table};`);
|
await dbConnectionPool.runQuery(`DELETE FROM ${table};`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user