File tree Expand file tree Collapse file tree 5 files changed +402
-327
lines changed
Expand file tree Collapse file tree 5 files changed +402
-327
lines changed Original file line number Diff line number Diff line change 11**v1.0.4**
22### Improvements
3- 1. Support functions with schema prefix in `DEFAULT` and `CHECK` statements.
3+ 1. Support functions with schema prefix in `DEFAULT` and `CHECK` statements. https://github.com/xnuinside/simple-ddl-parser/issues/240
4+ 2. Fix for REFERENCES NOT NULL - https://github.com/xnuinside/simple-ddl-parser/issues/239
45
56**v1.0.3**
67### Improvements
Original file line number Diff line number Diff line change 55
66
77class Snowflake :
8-
98 def p_clone (self , p : List ) -> None :
109 """clone : CLONE id"""
1110 p_list = list (p )
@@ -34,11 +33,16 @@ def p_multi_id_or_string(self, p: List) -> None:
3433 p [0 ] = value
3534
3635 def p_fmt_equals (self , p : List ) -> None :
37- """fmt_equals : id LP multi_id_or_string RP
38- """
39- fmt_split = re .compile (r"\w+\s*=\s*\w+|\w+\s*=\s*'.'|\w+\s*=\s*'..'|\w+\s*=\s*\('.+'\)|\w+\s*=\(\)" )
36+ """fmt_equals : id LP multi_id_or_string RP"""
37+ fmt_split = re .compile (
38+ r"\w+\s*=\s*\w+|\w+\s*=\s*'.'|\w+\s*=\s*'..'|\w+\s*=\s*\('.+'\)|\w+\s*=\(\)"
39+ )
4040 p_list = list (p )
41- p [0 ] = {f .split ('=' )[0 ].strip (): f .split ('=' )[1 ].strip () for f in fmt_split .findall (p_list [3 ]) if '=' in f }
41+ p [0 ] = {
42+ f .split ("=" )[0 ].strip (): f .split ("=" )[1 ].strip ()
43+ for f in fmt_split .findall (p_list [3 ])
44+ if "=" in f
45+ }
4246
4347 def p_table_property_equals (self , p : List ) -> None :
4448 """table_property_equals : id id id_or_string
@@ -92,8 +96,7 @@ def p_expression_change_tracking(self, p: List) -> None:
9296 p [0 ]["change_tracking" ] = p_list [- 1 ]
9397
9498 def p_comment_equals (self , p : List ) -> None :
95- """expr : expr option_comment
96- """
99+ """expr : expr option_comment"""
97100 p [0 ] = p [1 ]
98101 if p [2 ]:
99102 p [0 ].update (p [2 ])
Original file line number Diff line number Diff line change @@ -395,7 +395,6 @@ def p_autoincrement(self, p: List) -> None:
395395 def p_defcolumn (self , p : List ) -> None :
396396 """defcolumn : column
397397 | defcolumn comment
398- | defcolumn null
399398 | defcolumn encode
400399 | defcolumn PRIMARY KEY
401400 | defcolumn UNIQUE KEY
@@ -405,6 +404,8 @@ def p_defcolumn(self, p: List) -> None:
405404 | defcolumn collate
406405 | defcolumn enforced
407406 | defcolumn ref
407+ | defcolumn null
408+ | defcolumn ref null
408409 | defcolumn foreign ref
409410 | defcolumn encrypt
410411 | defcolumn generated
Load Diff Large diffs are not rendered by default.
Original file line number Diff line number Diff line change @@ -3335,3 +3335,72 @@ def test_create_empty_table_with_parentheses():
33353335 "types" : [],
33363336 }
33373337 assert result == expected
3338+
3339+
3340+ def test_reference_not_null ():
3341+
3342+ ddl = """CREATE TABLE a
3343+ (
3344+ id UUID PRIMARY KEY
3345+ );
3346+
3347+ CREATE TABLE b
3348+ (
3349+ id UUID PRIMARY KEY,
3350+ a_id UUID REFERENCES a(id) NOT NULL
3351+ );
3352+
3353+ """
3354+ result = DDLParser (ddl ).run (group_by_type = True )
3355+ expected = {'ddl_properties' : [],
3356+ 'domains' : [],
3357+ 'schemas' : [],
3358+ 'sequences' : [],
3359+ 'tables' : [{'alter' : {},
3360+ 'checks' : [],
3361+ 'columns' : [{'check' : None ,
3362+ 'default' : None ,
3363+ 'name' : 'id' ,
3364+ 'nullable' : False ,
3365+ 'references' : None ,
3366+ 'size' : None ,
3367+ 'type' : 'UUID' ,
3368+ 'unique' : False }],
3369+ 'index' : [],
3370+ 'partitioned_by' : [],
3371+ 'primary_key' : ['id' ],
3372+ 'schema' : None ,
3373+ 'table_name' : 'a' ,
3374+ 'tablespace' : None },
3375+ {'alter' : {},
3376+ 'checks' : [],
3377+ 'columns' : [{'check' : None ,
3378+ 'default' : None ,
3379+ 'name' : 'id' ,
3380+ 'nullable' : False ,
3381+ 'references' : None ,
3382+ 'size' : None ,
3383+ 'type' : 'UUID' ,
3384+ 'unique' : False },
3385+ {'check' : None ,
3386+ 'default' : None ,
3387+ 'name' : 'a_id' ,
3388+ 'nullable' : False ,
3389+ 'references' : {'columns' : ['id' ],
3390+ 'deferrable_initially' : None ,
3391+ 'on_delete' : None ,
3392+ 'on_update' : None ,
3393+ 'schema' : None ,
3394+ 'table' : 'a' },
3395+ 'size' : None ,
3396+ 'type' : 'UUID' ,
3397+ 'unique' : False }],
3398+ 'index' : [],
3399+ 'partitioned_by' : [],
3400+ 'primary_key' : ['id' ],
3401+ 'schema' : None ,
3402+ 'table_name' : 'b' ,
3403+ 'tablespace' : None }],
3404+ 'types' : []}
3405+
3406+ assert expected == result
You can’t perform that action at this time.
0 commit comments