@@ -76,11 +76,11 @@ pub fn build_action_queries(
7676 MigrationAction :: RawSql { sql } => Ok ( vec ! [ build_raw_sql( sql. clone( ) ) ] ) ,
7777
7878 MigrationAction :: AddConstraint { table, constraint } => {
79- build_add_constraint ( table, constraint)
79+ build_add_constraint ( backend , table, constraint, current_schema )
8080 }
8181
8282 MigrationAction :: RemoveConstraint { table, constraint } => {
83- build_remove_constraint ( table, constraint)
83+ build_remove_constraint ( backend , table, constraint, current_schema )
8484 }
8585 }
8686}
@@ -152,6 +152,46 @@ mod tests {
152152 DatabaseBackend :: Postgres ,
153153 & [ "DEFAULT" , "'active'" ]
154154 ) ]
155+ #[ case:: create_table_with_default_mysql(
156+ "create_table_with_default_mysql" ,
157+ MigrationAction :: CreateTable {
158+ table: "users" . into( ) ,
159+ columns: vec![ ColumnDef {
160+ name: "status" . into( ) ,
161+ r#type: ColumnType :: Simple ( SimpleColumnType :: Text ) ,
162+ nullable: true ,
163+ default : Some ( "'active'" . into( ) ) ,
164+ comment: None ,
165+ primary_key: None ,
166+ unique: None ,
167+ index: None ,
168+ foreign_key: None ,
169+ } ] ,
170+ constraints: vec![ ] ,
171+ } ,
172+ DatabaseBackend :: Postgres ,
173+ & [ "DEFAULT" , "'active'" ]
174+ ) ]
175+ #[ case:: create_table_with_default_sqlite(
176+ "create_table_with_default_sqlite" ,
177+ MigrationAction :: CreateTable {
178+ table: "users" . into( ) ,
179+ columns: vec![ ColumnDef {
180+ name: "status" . into( ) ,
181+ r#type: ColumnType :: Simple ( SimpleColumnType :: Text ) ,
182+ nullable: true ,
183+ default : Some ( "'active'" . into( ) ) ,
184+ comment: None ,
185+ primary_key: None ,
186+ unique: None ,
187+ index: None ,
188+ foreign_key: None ,
189+ } ] ,
190+ constraints: vec![ ] ,
191+ } ,
192+ DatabaseBackend :: Postgres ,
193+ & [ "DEFAULT" , "'active'" ]
194+ ) ]
155195 #[ case:: create_table_with_inline_primary_key_postgres(
156196 "create_table_with_inline_primary_key_postgres" ,
157197 MigrationAction :: CreateTable {
@@ -172,6 +212,46 @@ mod tests {
172212 DatabaseBackend :: Postgres ,
173213 & [ "PRIMARY KEY" ]
174214 ) ]
215+ #[ case:: create_table_with_inline_primary_key_mysql(
216+ "create_table_with_inline_primary_key_mysql" ,
217+ MigrationAction :: CreateTable {
218+ table: "users" . into( ) ,
219+ columns: vec![ ColumnDef {
220+ name: "id" . into( ) ,
221+ r#type: ColumnType :: Simple ( SimpleColumnType :: Integer ) ,
222+ nullable: false ,
223+ default : None ,
224+ comment: None ,
225+ primary_key: Some ( PrimaryKeySyntax :: Bool ( true ) ) ,
226+ unique: None ,
227+ index: None ,
228+ foreign_key: None ,
229+ } ] ,
230+ constraints: vec![ ] ,
231+ } ,
232+ DatabaseBackend :: Postgres ,
233+ & [ "PRIMARY KEY" ]
234+ ) ]
235+ #[ case:: create_table_with_inline_primary_key_sqlite(
236+ "create_table_with_inline_primary_key_sqlite" ,
237+ MigrationAction :: CreateTable {
238+ table: "users" . into( ) ,
239+ columns: vec![ ColumnDef {
240+ name: "id" . into( ) ,
241+ r#type: ColumnType :: Simple ( SimpleColumnType :: Integer ) ,
242+ nullable: false ,
243+ default : None ,
244+ comment: None ,
245+ primary_key: Some ( PrimaryKeySyntax :: Bool ( true ) ) ,
246+ unique: None ,
247+ index: None ,
248+ foreign_key: None ,
249+ } ] ,
250+ constraints: vec![ ] ,
251+ } ,
252+ DatabaseBackend :: Postgres ,
253+ & [ "PRIMARY KEY" ]
254+ ) ]
175255 #[ case:: create_table_with_fk_postgres(
176256 "create_table_with_fk_postgres" ,
177257 MigrationAction :: CreateTable {
@@ -192,6 +272,46 @@ mod tests {
192272 DatabaseBackend :: Postgres ,
193273 & [ "REFERENCES \" users\" (\" id\" )" , "ON DELETE CASCADE" , "ON UPDATE RESTRICT" ]
194274 ) ]
275+ #[ case:: create_table_with_fk_mysql(
276+ "create_table_with_fk_mysql" ,
277+ MigrationAction :: CreateTable {
278+ table: "posts" . into( ) ,
279+ columns: vec![
280+ col( "id" , ColumnType :: Simple ( SimpleColumnType :: Integer ) ) ,
281+ col( "user_id" , ColumnType :: Simple ( SimpleColumnType :: Integer ) ) ,
282+ ] ,
283+ constraints: vec![ TableConstraint :: ForeignKey {
284+ name: Some ( "fk_user" . into( ) ) ,
285+ columns: vec![ "user_id" . into( ) ] ,
286+ ref_table: "users" . into( ) ,
287+ ref_columns: vec![ "id" . into( ) ] ,
288+ on_delete: Some ( ReferenceAction :: Cascade ) ,
289+ on_update: Some ( ReferenceAction :: Restrict ) ,
290+ } ] ,
291+ } ,
292+ DatabaseBackend :: Postgres ,
293+ & [ "REFERENCES \" users\" (\" id\" )" , "ON DELETE CASCADE" , "ON UPDATE RESTRICT" ]
294+ ) ]
295+ #[ case:: create_table_with_fk_sqlite(
296+ "create_table_with_fk_sqlite" ,
297+ MigrationAction :: CreateTable {
298+ table: "posts" . into( ) ,
299+ columns: vec![
300+ col( "id" , ColumnType :: Simple ( SimpleColumnType :: Integer ) ) ,
301+ col( "user_id" , ColumnType :: Simple ( SimpleColumnType :: Integer ) ) ,
302+ ] ,
303+ constraints: vec![ TableConstraint :: ForeignKey {
304+ name: Some ( "fk_user" . into( ) ) ,
305+ columns: vec![ "user_id" . into( ) ] ,
306+ ref_table: "users" . into( ) ,
307+ ref_columns: vec![ "id" . into( ) ] ,
308+ on_delete: Some ( ReferenceAction :: Cascade ) ,
309+ on_update: Some ( ReferenceAction :: Restrict ) ,
310+ } ] ,
311+ } ,
312+ DatabaseBackend :: Postgres ,
313+ & [ "REFERENCES \" users\" (\" id\" )" , "ON DELETE CASCADE" , "ON UPDATE RESTRICT" ]
314+ ) ]
195315 fn test_build_migration_action (
196316 #[ case] title : & str ,
197317 #[ case] action : MigrationAction ,
0 commit comments