Added a function to delete all data before inserting sample data.
Build and Test API / Build-and-test-API (push) Successful in 53s
Details
Build and Test API / Build-and-test-API (push) Successful in 53s
Details
This commit is contained in:
parent
b5808d68f2
commit
84d4f0abbe
|
@ -3,6 +3,7 @@ module sample_data;
|
|||
import ddbc;
|
||||
import db;
|
||||
import data_utils;
|
||||
import slf4d;
|
||||
|
||||
import std.random;
|
||||
import std.algorithm;
|
||||
|
@ -40,6 +41,8 @@ void insertSampleData() {
|
|||
conn.close();
|
||||
}
|
||||
|
||||
deleteAllData(conn);
|
||||
|
||||
addUser(conn, "sample-user-A", "test", false, false);
|
||||
addUser(conn, "sample-user-B", "test", true, false);
|
||||
addUser(conn, "sample-user-C", "test", false, false);
|
||||
|
@ -84,6 +87,7 @@ void insertSampleData() {
|
|||
}
|
||||
}
|
||||
}
|
||||
info("Inserted sample data.");
|
||||
}
|
||||
|
||||
ulong addUser(Connection conn, string username, string password, bool locked, bool admin) {
|
||||
|
@ -143,3 +147,21 @@ void addEntry(
|
|||
}
|
||||
ps.executeUpdate();
|
||||
}
|
||||
|
||||
void deleteAllData(Connection conn) {
|
||||
Statement stmt = conn.createStatement();
|
||||
scope(exit) stmt.close();
|
||||
|
||||
const tables = [
|
||||
"announcement",
|
||||
"classroom_compliance_class_note",
|
||||
"classroom_compliance_entry",
|
||||
"classroom_compliance_student",
|
||||
"classroom_compliance_class",
|
||||
"auth_user"
|
||||
];
|
||||
foreach (tableName; tables) {
|
||||
int rows = stmt.executeUpdate("DELETE FROM " ~ tableName);
|
||||
infoF!"Deleted %d rows from %s."(rows, tableName);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue