@@ -2954,6 +2954,7 @@ for (const dialect of DIALECTS) {
29542954 . createTable ( 'test' )
29552955 . addColumn ( 'varchar_col' , 'varchar(255)' )
29562956 . addColumn ( 'integer_col' , 'integer' )
2957+ . addColumn ( 'different_col' , 'text' )
29572958 . execute ( )
29582959 } )
29592960
@@ -3397,6 +3398,29 @@ for (const dialect of DIALECTS) {
33973398 await builder . execute ( )
33983399 } )
33993400
3401+ if ( sqlSpec === 'postgres' || sqlSpec === 'mssql' ) {
3402+ it ( 'should drop a column if it exists' , async ( ) => {
3403+ const builder = ctx . db . schema
3404+ . alterTable ( 'test' )
3405+ . dropColumn ( 'varchar_col' , ( col ) => col . ifExists ( ) )
3406+
3407+ testSql ( builder , dialect , {
3408+ postgres : {
3409+ sql : 'alter table "test" drop column if exists "varchar_col"' ,
3410+ parameters : [ ] ,
3411+ } ,
3412+ mysql : NOT_SUPPORTED ,
3413+ mssql : {
3414+ sql : 'alter table "test" drop column if exists "varchar_col"' ,
3415+ parameters : [ ] ,
3416+ } ,
3417+ sqlite : NOT_SUPPORTED ,
3418+ } )
3419+
3420+ await builder . execute ( )
3421+ } )
3422+ }
3423+
34003424 if (
34013425 sqlSpec === 'postgres' ||
34023426 sqlSpec === 'mysql' ||
@@ -3434,7 +3458,7 @@ for (const dialect of DIALECTS) {
34343458 sql : [
34353459 'alter table "test"' ,
34363460 'drop column "varchar_col",' ,
3437- '"text_col"' ,
3461+ 'column "text_col"' ,
34383462 ] ,
34393463 parameters : [ ] ,
34403464 } ,
@@ -3453,6 +3477,41 @@ for (const dialect of DIALECTS) {
34533477 }
34543478 } )
34553479
3480+ if ( sqlSpec === 'postgres' || sqlSpec === 'mssql' ) {
3481+ it ( 'should drop multiple columns if it exists' , async ( ) => {
3482+ const builder = ctx . db . schema
3483+ . alterTable ( 'test' )
3484+ . dropColumn ( 'varchar_col' )
3485+ . dropColumn ( 'not_exist_col' , ( col ) => col . ifExists ( ) )
3486+ . dropColumn ( 'different_col' )
3487+
3488+ testSql ( builder , dialect , {
3489+ postgres : {
3490+ sql : [
3491+ 'alter table "test"' ,
3492+ 'drop column "varchar_col",' ,
3493+ 'drop column if exists "not_exist_col",' ,
3494+ 'drop column "different_col"' ,
3495+ ] ,
3496+ parameters : [ ] ,
3497+ } ,
3498+ mysql : NOT_SUPPORTED ,
3499+ mssql : {
3500+ sql : [
3501+ 'alter table "test"' ,
3502+ 'drop column "varchar_col",' ,
3503+ 'column if exists "not_exist_col",' ,
3504+ 'column "different_col"' ,
3505+ ] ,
3506+ parameters : [ ] ,
3507+ } ,
3508+ sqlite : NOT_SUPPORTED ,
3509+ } )
3510+
3511+ await builder . execute ( )
3512+ } )
3513+ }
3514+
34563515 if (
34573516 sqlSpec === 'postgres' ||
34583517 sqlSpec === 'mysql' ||
0 commit comments