Skip to content

Commit

Permalink
Merge pull request #916 from BlackDex/issue-759
Browse files Browse the repository at this point in the history
Fixing issue #759 by disabling Foreign Key Checks.
  • Loading branch information
dani-garcia authored Mar 18, 2020
2 parents dce054e + 35f3008 commit b85d548
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down

0 comments on commit b85d548

Please sign in to comment.