mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-09-02 19:23:49 +00:00
Removing an existing deferrable constraint, and fail test if any constraint is deferrable. (#5806)
* Removing an existing deferrable constraint. - Also adding a check to make sure the final dump contains no DEFERs. * Spelling error
This commit is contained in:
parent
fb762a3f9b
commit
e07e251ada
4 changed files with 20 additions and 2 deletions
|
@ -13,7 +13,7 @@ use std::{
|
||||||
|
|
||||||
/// Returns almost all things currently in the database, represented as SQL statements that would
|
/// Returns almost all things currently in the database, represented as SQL statements that would
|
||||||
/// recreate them.
|
/// recreate them.
|
||||||
pub fn get_dump() -> String {
|
pub(crate) fn get_dump() -> String {
|
||||||
let db_url = SETTINGS.get_database_url();
|
let db_url = SETTINGS.get_database_url();
|
||||||
let output = Command::new("pg_dump")
|
let output = Command::new("pg_dump")
|
||||||
.args([
|
.args([
|
||||||
|
@ -58,7 +58,7 @@ pub fn get_dump() -> String {
|
||||||
/// not `dumps[1]` to `dumps[0]`. This requires the two `dumps` elements being in an order that fits
|
/// not `dumps[1]` to `dumps[0]`. This requires the two `dumps` elements being in an order that fits
|
||||||
/// with `label_of_change_from_0_to_1`. This does not necessarily match the order in which the dumps
|
/// with `label_of_change_from_0_to_1`. This does not necessarily match the order in which the dumps
|
||||||
/// were created.
|
/// were created.
|
||||||
pub fn check_dump_diff(dumps: [&str; 2], label_of_change_from_0_to_1: &str) {
|
pub(crate) fn check_dump_diff(dumps: [&str; 2], label_of_change_from_0_to_1: &str) {
|
||||||
let [sorted_statements_in_0, sorted_statements_in_1] = dumps.map(|dump| {
|
let [sorted_statements_in_0, sorted_statements_in_1] = dumps.map(|dump| {
|
||||||
dump
|
dump
|
||||||
.split("\n\n")
|
.split("\n\n")
|
||||||
|
@ -195,6 +195,13 @@ fn display_change([before, after]: [&str; 2]) -> impl Iterator<Item = &str> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Makes sure the after dump does not contain any DEFERRABLE constraints.
|
||||||
|
pub(crate) fn deferr_constraint_check(dump: &str) {
|
||||||
|
if dump.contains(" DEFERR") {
|
||||||
|
panic!("Schema should not have DEFER constraints.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// `#[cfg(test)]` would be redundant here
|
// `#[cfg(test)]` would be redundant here
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -234,6 +234,8 @@ pub fn run(options: Options) -> LemmyResult<Branch> {
|
||||||
let after = diff_check::get_dump();
|
let after = diff_check::get_dump();
|
||||||
|
|
||||||
diff_check::check_dump_diff([&before, &after], "The code in crates/db_schema/replaceable_schema incorrectly created or modified things outside of the `r` schema, causing these changes to be left behind after dropping the schema:");
|
diff_check::check_dump_diff([&before, &after], "The code in crates/db_schema/replaceable_schema incorrectly created or modified things outside of the `r` schema, causing these changes to be left behind after dropping the schema:");
|
||||||
|
|
||||||
|
diff_check::deferr_constraint_check(&after);
|
||||||
}
|
}
|
||||||
|
|
||||||
run_replaceable_schema(&mut conn)?;
|
run_replaceable_schema(&mut conn)?;
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
ALTER TABLE community
|
||||||
|
ALTER CONSTRAINT community_instance_id_fkey DEFERRABLE INITIALLY DEFERRED;
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
-- We should remove existing deferrable constraints, as they're potentially dangerous.
|
||||||
|
--
|
||||||
|
-- This is the only one I could find after doing a DB dump.
|
||||||
|
ALTER TABLE community
|
||||||
|
ALTER CONSTRAINT community_instance_id_fkey NOT DEFERRABLE;
|
||||||
|
|
Loading…
Reference in a new issue