Implement election candidate table readiness check in character deletion process: Added a new SQL query to verify the existence of the election candidate table before attempting to delete associated records. Updated the deletion logic in both EventsWorker and UserCharacterWorker to conditionally execute the deletion of election candidates based on the table's readiness, improving robustness and preventing errors in environments where the table may not exist.
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 1m39s
All checks were successful
Deploy yourpart (blue-green) / deploy (push) Successful in 1m39s
This commit is contained in:
@@ -48,6 +48,7 @@ use crate::worker::sql::{
|
||||
QUERY_DELETE_CHILD_RELATION_BY_PARENT,
|
||||
QUERY_DELETE_DEBTORS_PRISM,
|
||||
QUERY_DELETE_CHARACTER,
|
||||
QUERY_ELECTION_CANDIDATE_TABLE_READY,
|
||||
QUERY_DELETE_ELECTION_CANDIDATE,
|
||||
QUERY_DELETE_KNOWLEDGE,
|
||||
QUERY_DELETE_POLITICAL_OFFICE,
|
||||
@@ -1936,11 +1937,20 @@ impl EventsWorker {
|
||||
conn.prepare("delete_knowledge", QUERY_DELETE_KNOWLEDGE)?;
|
||||
conn.prepare("delete_debtors_prism", QUERY_DELETE_DEBTORS_PRISM)?;
|
||||
conn.prepare("delete_political_office", QUERY_DELETE_POLITICAL_OFFICE)?;
|
||||
conn.prepare("delete_election_candidate", QUERY_DELETE_ELECTION_CANDIDATE)?;
|
||||
conn.execute("delete_knowledge", &[&character_id])?;
|
||||
conn.execute("delete_debtors_prism", &[&character_id])?;
|
||||
conn.execute("delete_political_office", &[&character_id])?;
|
||||
conn.execute("delete_election_candidate", &[&character_id])?;
|
||||
conn.prepare("election_candidate_table_ready", QUERY_ELECTION_CANDIDATE_TABLE_READY)?;
|
||||
let election_ready_rows = conn.execute("election_candidate_table_ready", &[])?;
|
||||
let election_ready = election_ready_rows
|
||||
.first()
|
||||
.and_then(|r| r.get("ready"))
|
||||
.map(|v| v == "t" || v == "true")
|
||||
.unwrap_or(false);
|
||||
if election_ready {
|
||||
conn.prepare("delete_election_candidate", QUERY_DELETE_ELECTION_CANDIDATE)?;
|
||||
conn.execute("delete_election_candidate", &[&character_id])?;
|
||||
}
|
||||
|
||||
// 6) Charakter löschen
|
||||
conn.prepare("delete_character", QUERY_DELETE_CHARACTER)?;
|
||||
|
||||
@@ -2577,6 +2577,16 @@ pub const QUERY_DELETE_ELECTION_CANDIDATE: &str = r#"
|
||||
WHERE character_id = $1;
|
||||
"#;
|
||||
|
||||
/// Legacy-/Migrationsschutz: Tabelle existiert nicht in allen Umgebungen.
|
||||
pub const QUERY_ELECTION_CANDIDATE_TABLE_READY: &str = r#"
|
||||
SELECT EXISTS (
|
||||
SELECT 1
|
||||
FROM information_schema.tables
|
||||
WHERE table_schema = 'falukant_data'
|
||||
AND table_name = 'election_candidate'
|
||||
) AS ready;
|
||||
"#;
|
||||
|
||||
pub const QUERY_GET_STOCK_TYPE_ID: &str = r#"
|
||||
SELECT id FROM falukant_type.stock WHERE label_tr = $1 LIMIT 1;
|
||||
"#;
|
||||
|
||||
@@ -54,6 +54,7 @@ use crate::worker::sql::{
|
||||
QUERY_DELETE_DEBTORS_PRISM,
|
||||
QUERY_DELETE_POLITICAL_OFFICE,
|
||||
QUERY_DELETE_ELECTION_CANDIDATE,
|
||||
QUERY_ELECTION_CANDIDATE_TABLE_READY,
|
||||
};
|
||||
|
||||
/// Vereinfachtes Abbild eines Characters aus `QUERY_GET_USERS_TO_UPDATE`.
|
||||
@@ -853,7 +854,6 @@ impl UserCharacterWorker {
|
||||
conn.prepare("delete_knowledge", QUERY_DELETE_KNOWLEDGE)?;
|
||||
conn.prepare("delete_debtors_prism", QUERY_DELETE_DEBTORS_PRISM)?;
|
||||
conn.prepare("delete_political_office", QUERY_DELETE_POLITICAL_OFFICE)?;
|
||||
conn.prepare("delete_election_candidate", QUERY_DELETE_ELECTION_CANDIDATE)?;
|
||||
conn.prepare("insert_notification", QUERY_INSERT_NOTIFICATION)?;
|
||||
|
||||
let dir_result = conn.execute("delete_director", &[&character_id])?;
|
||||
@@ -923,7 +923,17 @@ impl UserCharacterWorker {
|
||||
conn.execute("delete_knowledge", &[&character_id])?;
|
||||
conn.execute("delete_debtors_prism", &[&character_id])?;
|
||||
conn.execute("delete_political_office", &[&character_id])?;
|
||||
conn.execute("delete_election_candidate", &[&character_id])?;
|
||||
conn.prepare("election_candidate_table_ready", QUERY_ELECTION_CANDIDATE_TABLE_READY)?;
|
||||
let election_ready_rows = conn.execute("election_candidate_table_ready", &[])?;
|
||||
let election_ready = election_ready_rows
|
||||
.first()
|
||||
.and_then(|r| r.get("ready"))
|
||||
.map(|v| v == "t" || v == "true")
|
||||
.unwrap_or(false);
|
||||
if election_ready {
|
||||
conn.prepare("delete_election_candidate", QUERY_DELETE_ELECTION_CANDIDATE)?;
|
||||
conn.execute("delete_election_candidate", &[&character_id])?;
|
||||
}
|
||||
|
||||
// Character selbst löschen
|
||||
conn.prepare(
|
||||
|
||||
Reference in New Issue
Block a user