Skip to content

Commit c285470

Browse files
committed
release 0.22.6 with bug fixies
1 parent b6bd012 commit c285470

File tree

8 files changed

+214
-9
lines changed

8 files changed

+214
-9
lines changed

docs/README.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,6 @@ TODO in next Releases (if you don't see feature that you need - open the issue)
412412
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
413413

414414

415-
416-
417415
#. Add support for ALTER TABLE ... ADD COLUMN
418416
#. Add more support for CREATE type IS TABLE (example: CREATE OR REPLACE TYPE budget_tbl_typ IS TABLE OF NUMBER(8,2);
419417
#. Add support (ignore correctly) ALTER TABLE ... DROP CONSTRAINT ..., ALTER TABLE ... DROP INDEX ...

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "simple-ddl-parser"
3-
version = "0.22.5"
3+
version = "0.22.6"
44
description = "Simple DDL Parser to parse SQL & dialects like HQL, TSQL (MSSQL), Oracle, AWS Redshift, Snowflake, MySQL, PostgreSQL, etc ddl files to json/python dict with full information about columns: types, defaults, primary keys, etc.; sequences, alters, custom types & other entities from ddl."
55
authors = ["Iuliia Volkova <[email protected]>"]
66
license = "MIT"

simple_ddl_parser/dialects/bigquery.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ def p_multiple_options(self, p):
88
"""multiple_options : options
99
| multiple_options options
1010
"""
11-
print(list(p), "\n")
1211
if len(p) > 2:
1312
p[1]["options"].extend(p[2]["options"])
1413
p[0] = p[1]

simple_ddl_parser/dialects/sql.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,19 +838,27 @@ def p_expression_seq(self, p: List) -> None:
838838
| expr START id
839839
| expr START id id
840840
| expr MINVALUE id
841+
| expr NO MINVALUE
842+
| expr NO MAXVALUE
841843
| expr MAXVALUE id
842844
| expr CACHE id
843845
| expr CACHE
844846
"""
845847
# get schema & table name
846848
p_list = list(p)
847849
p[0] = p[1]
850+
value = None
848851
if len(p) == 4:
849-
p[0].update({p[2].lower(): int(p_list[-1])})
850-
if len(p) == 3:
851-
p[0].update({p[2].lower(): True})
852+
if p[2] == "NO":
853+
value = {p_list[-1].lower(): False}
854+
else:
855+
value = {p[2].lower(): int(p_list[-1])}
856+
elif len(p) == 3:
857+
value = {p[2].lower(): True}
852858
elif len(p) == 5:
853-
p[0].update({f"{p[2].lower()}_{p[3].lower()}": int(p_list[-1])})
859+
value = {f"{p[2].lower()}_{p[3].lower()}": int(p_list[-1])}
860+
if value:
861+
p[0].update(value)
854862

855863
def p_seq_name(self, p: List) -> None:
856864
"""seq_name : create_seq id DOT id

simple_ddl_parser/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def parse_data(self): # noqa: C901 need to refactor this
174174
statement = line
175175
else:
176176
statement += f" {line}"
177-
print(statement)
177+
178178
if final_line or new_statement:
179179
# end of sql operation, remove ; from end of line
180180
statement = statement[:-1]

simple_ddl_parser/tokens.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"MINVALUE": "MINVALUE",
9393
"MAXVALUE": "MAXVALUE",
9494
"CACHE": "CACHE",
95+
"NO": "NO",
9596
}
9697

9798

tests/test_ddl_settings.py

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
from simple_ddl_parser import DDLParser
2+
3+
4+
def test_sets_with_dot_and_comma():
5+
ddl = """
6+
--
7+
-- PostgreSQL database dump
8+
--
9+
10+
-- Dumped from database version 11.6 (Debian 11.6-1.pgdg90+1)
11+
-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-0ubuntu0.20.04.1)
12+
13+
SET statement_timeout = 0;
14+
SET lock_timeout = 0;
15+
SET idle_in_transaction_session_timeout = 0;
16+
SET client_encoding = 'UTF8';
17+
SET standard_conforming_strings = on;
18+
SELECT pg_catalog.set_config('search_path', '', false);
19+
SET check_function_bodies = false;
20+
SET xmloption = content;
21+
SET client_min_messages = warning;
22+
SET row_security = off;
23+
24+
SET default_tablespace = '';
25+
26+
--
27+
-- Name: accounts; Type: TABLE; Schema: public; Owner: myapp
28+
--
29+
30+
31+
"""
32+
result = DDLParser(ddl).run(group_by_type=True, output_mode="bigquery")
33+
expected = {
34+
"ddl_properties": [
35+
{"name": "statement_timeout", "value": "0"},
36+
{"name": "lock_timeout", "value": "0"},
37+
{"name": "idle_in_transaction_session_timeout", "value": "0"},
38+
{"name": "client_encoding", "value": "'UTF8'"},
39+
{"name": "standard_conforming_strings", "value": "on"},
40+
{"name": "check_function_bodies", "value": "false"},
41+
{"name": "xmloption", "value": "content"},
42+
{"name": "client_min_messages", "value": "warning"},
43+
{"name": "row_security", "value": "off"},
44+
{"name": "default_tablespace", "value": "''"},
45+
],
46+
"domains": [],
47+
"schemas": [],
48+
"sequences": [],
49+
"tables": [],
50+
"types": [],
51+
}
52+
assert expected == result
53+
54+
55+
def test_parse_validly_tables_after_set():
56+
57+
ddl = """
58+
--
59+
-- PostgreSQL database dump
60+
--
61+
62+
-- Dumped from database version 11.6 (Debian 11.6-1.pgdg90+1)
63+
-- Dumped by pg_dump version 12.9 (Ubuntu 12.9-0ubuntu0.20.04.1)
64+
65+
SET statement_timeout = 0;
66+
SET lock_timeout = 0;
67+
SET idle_in_transaction_session_timeout = 0;
68+
SET client_encoding = 'UTF8';
69+
SET standard_conforming_strings = on;
70+
SELECT pg_catalog.set_config('search_path', '', false);
71+
SET check_function_bodies = false;
72+
SET xmloption = content;
73+
SET client_min_messages = warning;
74+
SET row_security = off;
75+
76+
SET default_tablespace = '';
77+
78+
--
79+
-- Name: accounts; Type: TABLE; Schema: public; Owner: myapp
80+
--
81+
82+
CREATE TABLE public.accounts (
83+
user_id integer NOT NULL,
84+
username character varying(50) NOT NULL,
85+
password character varying(50) NOT NULL,
86+
email character varying(255) NOT NULL,
87+
);
88+
89+
90+
"""
91+
result = DDLParser(ddl).run(group_by_type=True, output_mode="bigquery")
92+
expected = {
93+
"ddl_properties": [
94+
{"name": "statement_timeout", "value": "0"},
95+
{"name": "lock_timeout", "value": "0"},
96+
{"name": "idle_in_transaction_session_timeout", "value": "0"},
97+
{"name": "client_encoding", "value": "'UTF8'"},
98+
{"name": "standard_conforming_strings", "value": "on"},
99+
{"name": "check_function_bodies", "value": "false"},
100+
{"name": "xmloption", "value": "content"},
101+
{"name": "client_min_messages", "value": "warning"},
102+
{"name": "row_security", "value": "off"},
103+
{"name": "default_tablespace", "value": "''"},
104+
],
105+
"domains": [],
106+
"schemas": [],
107+
"sequences": [],
108+
"tables": [
109+
{
110+
"alter": {},
111+
"checks": [],
112+
"columns": [
113+
{
114+
"check": None,
115+
"default": None,
116+
"name": "user_id",
117+
"nullable": False,
118+
"references": None,
119+
"size": None,
120+
"type": "integer",
121+
"unique": False,
122+
},
123+
{
124+
"check": None,
125+
"default": None,
126+
"name": "username",
127+
"nullable": False,
128+
"references": None,
129+
"size": 50,
130+
"type": "character varying",
131+
"unique": False,
132+
},
133+
{
134+
"check": None,
135+
"default": None,
136+
"name": "password",
137+
"nullable": False,
138+
"references": None,
139+
"size": 50,
140+
"type": "character varying",
141+
"unique": False,
142+
},
143+
{
144+
"check": None,
145+
"default": None,
146+
"name": "email",
147+
"nullable": False,
148+
"references": None,
149+
"size": 255,
150+
"type": "character varying",
151+
"unique": False,
152+
},
153+
],
154+
"dataset": "public",
155+
"index": [],
156+
"partitioned_by": [],
157+
"primary_key": [],
158+
"table_name": "accounts",
159+
"tablespace": None,
160+
}
161+
],
162+
"types": [],
163+
}
164+
assert expected == result

tests/test_sequences.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,38 @@ def test_sequence_with_by():
132132
"""
133133
result = DDLParser(ddl).run(group_by_type=True)
134134
assert expected == result
135+
136+
137+
def test_add_support_no_value():
138+
139+
ddl = """
140+
CREATE SEQUENCE public.accounts_user_id_seq
141+
AS integer
142+
START WITH 1
143+
INCREMENT BY 1
144+
NO MINVALUE
145+
NO MAXVALUE
146+
CACHE 1;
147+
148+
"""
149+
result = DDLParser(ddl).run(group_by_type=True, output_mode="bigquery")
150+
expected = {
151+
"ddl_properties": [],
152+
"domains": [],
153+
"schemas": [],
154+
"sequences": [
155+
{
156+
"AS": "integer",
157+
"cache": 1,
158+
"dataset": "public",
159+
"increment_by": 1,
160+
"maxvalue": False,
161+
"minvalue": False,
162+
"sequence_name": "accounts_user_id_seq",
163+
"start_with": 1,
164+
}
165+
],
166+
"tables": [],
167+
"types": [],
168+
}
169+
assert expected == result

0 commit comments

Comments
 (0)