aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel GarcĂ­a <[email protected]>2020-03-18 18:48:08 +0100
committerGitHub <[email protected]>2020-03-18 18:48:08 +0100
commitb85d548879204858325088fa1048e0b6b185600c (patch)
tree9508c23a5ae95ed9ae7da3ea9a66dcf2485d64ca
parentdce054e63245161155d446d19f0463a588b46730 (diff)
parent35f30088b2fd4f97c39b4af6c4aadecaecffe5a4 (diff)
downloadvaultwarden-b85d548879204858325088fa1048e0b6b185600c.tar.gz
vaultwarden-b85d548879204858325088fa1048e0b6b185600c.zip
Merge pull request #916 from BlackDex/issue-759
Fixing issue #759 by disabling Foreign Key Checks.
-rw-r--r--src/main.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs
index c098ad7d..85e9d286 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -323,6 +323,16 @@ mod migrations {
let connection = crate::db::get_connection().expect("Can't connect to DB");
use std::io::stdout;
+
+ // Disable Foreign Key Checks during migration
+ use diesel::RunQueryDsl;
+ #[cfg(feature = "postgres")]
+ diesel::sql_query("SET CONSTRAINTS ALL DEFERRED").execute(&connection).expect("Failed to disable Foreign Key Checks during migrations");
+ #[cfg(feature = "mysql")]
+ diesel::sql_query("SET FOREIGN_KEY_CHECKS = 0").execute(&connection).expect("Failed to disable Foreign Key Checks during migrations");
+ #[cfg(feature = "sqlite")]
+ diesel::sql_query("PRAGMA defer_foreign_keys = ON").execute(&connection).expect("Failed to disable Foreign Key Checks during migrations");
+
embedded_migrations::run_with_output(&connection, &mut stdout()).expect("Can't run migrations");
}
}