Skip to content

Commit

Permalink
only render fkc0 for MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
janpio committed Dec 2, 2023
1 parent 9c5d3b0 commit d89fa01
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ pub(crate) fn render_script(
// some steps don't render anything.
let mut is_first_step = true;

if let Some(fkc0) = flavour.render_foreign_key_checks_0() {
script.push_str(fkc0);
script.push('\n');
}

if let Some(begin) = flavour.render_begin_transaction() {
script.push_str(begin);
script.push('\n');
Expand Down
2 changes: 0 additions & 2 deletions schema-engine/connectors/sql-schema-connector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,6 @@ async fn best_effort_reset_impl(
flavour,
)?;

migration = format!("SET foreign_key_checks = 0;{}\n", migration);

flavour.raw_cmd(&migration).await?;

Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ pub(crate) trait SqlRenderer {
None
}

/// Render a foreign key checks = 0.
fn render_foreign_key_checks_0(&self) -> Option<&'static str> {
None
}

/// Render a `RenameForeignKey` step.
fn render_rename_foreign_key(&self, fks: MigrationPair<ForeignKeyWalker<'_>>) -> String;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ impl SqlRenderer for MysqlFlavour {
fn render_rename_foreign_key(&self, _fks: MigrationPair<ForeignKeyWalker<'_>>) -> String {
unreachable!("render RenameForeignKey on MySQL")
}

fn render_commit_transaction(&self) -> Option<&'static str> {
let sql = indoc! { r#"
SET foreign_key_checks = 0;
"# };

Some(sql)
}
}

fn render_mysql_modify(
Expand Down

0 comments on commit d89fa01

Please sign in to comment.