Skip to content

Commit 434d006

Browse files
committed
fix: check constraint in mysql
1 parent 6767b6b commit 434d006

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

pegjs/mariadb.pegjs

+13
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,7 @@ create_constraint_definition
12431243
= create_constraint_primary
12441244
/ create_constraint_unique
12451245
/ create_constraint_foreign
1246+
/ create_constraint_check
12461247

12471248
constraint_name
12481249
= kc:KW_CONSTRAINT __
@@ -1289,6 +1290,18 @@ create_constraint_unique
12891290
}
12901291
}
12911292

1293+
create_constraint_check
1294+
= kc:constraint_name? __ u:'CHECK'i __ nfr:('NOT'i __ 'FOR'i __ 'REPLICATION'i __)? LPAREN __ c:or_and_expr __ RPAREN {
1295+
return {
1296+
constraint_type: u.toLowerCase(),
1297+
keyword: kc && kc.keyword,
1298+
constraint: kc && kc.constraint,
1299+
index_type: nfr && { keyword: 'not for replication' },
1300+
definition: [c],
1301+
resource: 'constraint',
1302+
}
1303+
}
1304+
12921305
create_constraint_foreign
12931306
= kc:constraint_name? __
12941307
p:('FOREIGN KEY'i) __

pegjs/mysql.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,7 @@ create_constraint_unique
15131513
}
15141514

15151515
create_constraint_check
1516-
= kc:constraint_name? __ u:'CHECK'i __ nfr:('NOT'i __ 'FOR'i __ 'REPLICATION'i __)? LPAREN __ c:expr __ RPAREN {
1516+
= kc:constraint_name? __ u:'CHECK'i __ nfr:('NOT'i __ 'FOR'i __ 'REPLICATION'i __)? LPAREN __ c:or_and_expr __ RPAREN {
15171517
return {
15181518
constraint_type: u.toLowerCase(),
15191519
keyword: kc && kc.keyword,

test/mysql-mariadb.spec.js

+7
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,13 @@ describe('mysql', () => {
995995
"ALTER TABLE `product` MODIFY COLUMN `type` ENUM('one', 'two') NOT NULL AFTER `name`"
996996
]
997997
},
998+
{
999+
title: 'create table with check constraint',
1000+
sql: [
1001+
'CREATE TABLE `Pattern` (`IsInterpolated` INT NOT NULL, `Value` DOUBLE, CONSTRAINT `CHK_Value_IsInterpolated` CHECK ((`Value` IS NOT NULL) OR (`IsInterpolated` = 0)));',
1002+
'CREATE TABLE `Pattern` (`IsInterpolated` INT NOT NULL, `Value` DOUBLE, CONSTRAINT `CHK_Value_IsInterpolated` CHECK ((`Value` IS NOT NULL) OR (`IsInterpolated` = 0)))'
1003+
]
1004+
},
9981005
]
9991006
SQL_LIST.forEach(sqlInfo => {
10001007
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)