Skip to main content

build_replace_constraint

Function build_replace_constraint 

Source
pub fn build_replace_constraint(
    backend: &DatabaseBackend,
    table: &str,
    from: &TableConstraint,
    to: &TableConstraint,
    current_schema: &[TableDef],
    pending_constraints: &[TableConstraint],
) -> Result<Vec<BuiltQuery>, QueryError>
Expand description

Build SQL queries to replace a constraint in-place.

For PostgreSQL/MySQL: DROP old FK + ADD new FK (two ALTER TABLE statements). For SQLite: single temp table recreation with the new constraint swapped in.

This avoids the double table recreation that would occur with separate RemoveConstraint + AddConstraint on SQLite.