Skip to content

Commit d9418a0

Browse files
committed
feat: support drop constraint in pg
1 parent 3f6cd18 commit d9418a0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

pegjs/postgresql.pegjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,6 +1890,7 @@ alter_action_list
18901890
alter_action
18911891
= ALTER_ADD_COLUMN
18921892
/ ALTER_ADD_CONSTRAINT
1893+
/ ALTER_DROP_CONSTRAINT
18931894
/ ALTER_DROP_COLUMN
18941895
/ ALTER_ADD_INDEX_OR_KEY
18951896
/ ALTER_ADD_FULLETXT_SPARITAL_INDEX
@@ -1964,6 +1965,24 @@ ALTER_ADD_CONSTRAINT
19641965
}
19651966
}
19661967

1968+
ALTER_DROP_CONSTRAINT
1969+
= KW_DROP __ kc:'CONSTRAINT'i __ c:ident {
1970+
/* => {
1971+
action: 'drop';
1972+
constraint: ident,
1973+
keyword: 'constraint',
1974+
resource: 'constraint',
1975+
type: 'alter';
1976+
} */
1977+
return {
1978+
action: 'drop',
1979+
constraint: c,
1980+
keyword: kc.toLowerCase(),
1981+
resource: 'constraint',
1982+
type: 'alter',
1983+
}
1984+
}
1985+
19671986
ALTER_ADD_INDEX_OR_KEY
19681987
= KW_ADD __
19691988
id:create_index_definition

test/postgres.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,6 +1929,20 @@ describe('Postgres', () => {
19291929
'SELECT * FROM "table_name" WHERE foo.bar.baz.qux = FALSE'
19301930
]
19311931
},
1932+
{
1933+
title: 'drop constraint',
1934+
sql: [
1935+
`ALTER TABLE "test" DROP CONSTRAINT "test_constraint";`,
1936+
'ALTER TABLE "test" DROP CONSTRAINT "test_constraint"'
1937+
]
1938+
},
1939+
{
1940+
title: 'add constraint',
1941+
sql: [
1942+
'ALTER TABLE "configuration" ADD CONSTRAINT "configuration_pk" PRIMARY KEY("something","something_else","something_something_else");',
1943+
'ALTER TABLE "configuration" ADD CONSTRAINT "configuration_pk" PRIMARY KEY ("something", "something_else", "something_something_else")',
1944+
]
1945+
},
19321946
]
19331947
function neatlyNestTestedSQL(sqlList){
19341948
sqlList.forEach(sqlInfo => {

0 commit comments

Comments
 (0)