Cleaned up constraints a little.
This commit is contained in:
@@ -23,7 +23,7 @@ impl From<sqlx::Error> for DatabaseError {
|
|||||||
let constraint = db_err
|
let constraint = db_err
|
||||||
.constraint()
|
.constraint()
|
||||||
.map(Constraint::from)
|
.map(Constraint::from)
|
||||||
.unwrap_or(Constraint::Unknown(None));
|
.unwrap_or(Constraint::Unnamed);
|
||||||
|
|
||||||
DatabaseError::ForeignKeyViolation {
|
DatabaseError::ForeignKeyViolation {
|
||||||
constraint,
|
constraint,
|
||||||
@@ -37,14 +37,17 @@ impl From<sqlx::Error> for DatabaseError {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
|
||||||
pub enum Constraint {
|
pub enum Constraint {
|
||||||
#[error("recurring transaction source account constraint violation")]
|
#[error("recurring transaction source account constraint")]
|
||||||
RecurringTransactionSourceAccount,
|
RecurringTransactionSourceAccount,
|
||||||
|
|
||||||
#[error("recurring transaction destination account constraint violation")]
|
#[error("recurring transaction destination account constraint")]
|
||||||
RecurringTransactionDestinationAccount,
|
RecurringTransactionDestinationAccount,
|
||||||
|
|
||||||
#[error("unknown constraint violation: {0:?}")]
|
#[error("unknown constraint ({0:?})")]
|
||||||
Unknown(Option<String>),
|
Unknown(String),
|
||||||
|
|
||||||
|
#[error("unnamed constraint")]
|
||||||
|
Unnamed,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&str> for Constraint {
|
impl From<&str> for Constraint {
|
||||||
@@ -56,7 +59,7 @@ impl From<&str> for Constraint {
|
|||||||
"fk_recurring_transactions_destination_account" => {
|
"fk_recurring_transactions_destination_account" => {
|
||||||
Constraint::RecurringTransactionDestinationAccount
|
Constraint::RecurringTransactionDestinationAccount
|
||||||
}
|
}
|
||||||
_ => Constraint::Unknown(Some(constraint.to_string())),
|
_ => Constraint::Unknown(constraint.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn keeps_unknown_account_delete_foreign_keys_generic() {
|
fn keeps_unknown_account_delete_foreign_keys_generic() {
|
||||||
let error = classify_delete_error(foreign_key_violation(Constraint::Unknown(None)));
|
let error = classify_delete_error(foreign_key_violation(Constraint::Unnamed));
|
||||||
|
|
||||||
assert!(matches!(error, RepositoryError::Database(_)));
|
assert!(matches!(error, RepositoryError::Database(_)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn keeps_unknown_upsert_foreign_keys_generic() {
|
fn keeps_unknown_upsert_foreign_keys_generic() {
|
||||||
let error = classify_upsert_error(foreign_key_violation(Constraint::Unknown(None)));
|
let error = classify_upsert_error(foreign_key_violation(Constraint::Unnamed));
|
||||||
|
|
||||||
assert!(matches!(error, RepositoryError::Database(_)));
|
assert!(matches!(error, RepositoryError::Database(_)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user