@@ -1645,10 +1645,52 @@ def test_transform(db_path, args, expected_schema):
16451645 assert schema == expected_schema
16461646
16471647
1648- def test_transform_drop_foreign_key (db_path ):
1648+ @pytest .mark .parametrize (
1649+ "extra_args,expected_schema" ,
1650+ (
1651+ (
1652+ ["--drop-foreign-key" , "country" ],
1653+ (
1654+ 'CREATE TABLE "places" (\n '
1655+ " [id] INTEGER PRIMARY KEY,\n "
1656+ " [name] TEXT,\n "
1657+ " [country] INTEGER,\n "
1658+ " [city] INTEGER REFERENCES [city]([id]),\n "
1659+ " [continent] INTEGER\n "
1660+ ")"
1661+ ),
1662+ ),
1663+ (
1664+ ["--drop-foreign-key" , "country" , "--drop-foreign-key" , "city" ],
1665+ (
1666+ 'CREATE TABLE "places" (\n '
1667+ " [id] INTEGER PRIMARY KEY,\n "
1668+ " [name] TEXT,\n "
1669+ " [country] INTEGER,\n "
1670+ " [city] INTEGER,\n "
1671+ " [continent] INTEGER\n "
1672+ ")"
1673+ ),
1674+ ),
1675+ (
1676+ ["--add-foreign-key" , "continent" , "continent" , "id" ],
1677+ (
1678+ 'CREATE TABLE "places" (\n '
1679+ " [id] INTEGER PRIMARY KEY,\n "
1680+ " [name] TEXT,\n "
1681+ " [country] INTEGER REFERENCES [country]([id]),\n "
1682+ " [city] INTEGER REFERENCES [city]([id]),\n "
1683+ " [continent] INTEGER REFERENCES [continent]([id])\n "
1684+ ")"
1685+ ),
1686+ ),
1687+ ),
1688+ )
1689+ def test_transform_add_or_drop_foreign_key (db_path , extra_args , expected_schema ):
16491690 db = Database (db_path )
16501691 with db .conn :
16511692 # Create table with three foreign keys so we can drop two of them
1693+ db ["continent" ].insert ({"id" : 1 , "name" : "Europe" }, pk = "id" )
16521694 db ["country" ].insert ({"id" : 1 , "name" : "France" }, pk = "id" )
16531695 db ["city" ].insert ({"id" : 24 , "name" : "Paris" }, pk = "id" )
16541696 db ["places" ].insert (
@@ -1657,6 +1699,7 @@ def test_transform_drop_foreign_key(db_path):
16571699 "name" : "Caveau de la Huchette" ,
16581700 "country" : 1 ,
16591701 "city" : 24 ,
1702+ "continent" : 1 ,
16601703 },
16611704 foreign_keys = ("country" , "city" ),
16621705 pk = "id" ,
@@ -1667,21 +1710,12 @@ def test_transform_drop_foreign_key(db_path):
16671710 "transform" ,
16681711 db_path ,
16691712 "places" ,
1670- "--drop-foreign-key" ,
1671- "country" ,
1672- ],
1713+ ]
1714+ + extra_args ,
16731715 )
1674- print (result .output )
16751716 assert result .exit_code == 0
16761717 schema = db ["places" ].schema
1677- assert schema == (
1678- 'CREATE TABLE "places" (\n '
1679- " [id] INTEGER PRIMARY KEY,\n "
1680- " [name] TEXT,\n "
1681- " [country] INTEGER,\n "
1682- " [city] INTEGER REFERENCES [city]([id])\n "
1683- ")"
1684- )
1718+ assert schema == expected_schema
16851719
16861720
16871721_common_other_schema = (
0 commit comments