From 777b15e5f811a3a0a31efbe4c9b07e6b48a4ecb9 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 11 May 2020 12:13:36 +0800 Subject: [PATCH] bugfix --- sqlor/ddl_template_mysql.py | 8 +++----- sqlor/ddl_template_oracle.py | 6 ++---- sqlor/ddl_template_postgresql.py | 4 ++-- sqlor/ddl_template_sqlserver.py | 6 ++---- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/sqlor/ddl_template_mysql.py b/sqlor/ddl_template_mysql.py index ecde8ca..b311509 100644 --- a/sqlor/ddl_template_mysql.py +++ b/sqlor/ddl_template_mysql.py @@ -31,11 +31,9 @@ NOT NULL {%- endif -%} {% endmacro %} {% macro primary() %} -{% if len(','.join(summary[0].primary))>0 %} -,primary key({{','.join(summary[0].primary)}}) -{% endif %} +,primary key({{summary[0].primary}}) {% endmacro %} -drop table {{summary[0].name}}; +drop table if exists {{summary[0].name}}; CREATE TABLE {{summary[0].name}} ( {% for field in fields %} @@ -52,4 +50,4 @@ default charset=utf8 CREATE {% if v.value.idxtype=='unique' %}UNIQUE{% endif %} INDEX {{summary[0].name}}_{{v.name}} ON {{summary[0].name}}({{",".join(v.value.fields)}}); {% endif %} {%- endfor -%} -""" \ No newline at end of file +""" diff --git a/sqlor/ddl_template_oracle.py b/sqlor/ddl_template_oracle.py index cdc6991..56a16c5 100644 --- a/sqlor/ddl_template_oracle.py +++ b/sqlor/ddl_template_oracle.py @@ -25,9 +25,7 @@ NOT NULL {%- endif -%} {% endmacro %} {% macro primary() %} -{% if len(','.join(summary[0].primary))>0 %} -,primary key({{','.join(summary[0].primary)}}) -{% endif %} +,primary key({{summary[0].primary}}) {% endmacro %} drop table {{summary[0].name}}; CREATE TABLE {{summary[0].name}} @@ -46,4 +44,4 @@ COMMENT ON TABLE {{summary[0].name}} IS '{{summary[0].title}}'; {% for field in fields %} COMMENT ON COLUMN {{summary[0].name}}.{{field.name}} is '{{field.title}}'; {% endfor %} -""" \ No newline at end of file +""" diff --git a/sqlor/ddl_template_postgresql.py b/sqlor/ddl_template_postgresql.py index 407dde6..cad7795 100644 --- a/sqlor/ddl_template_postgresql.py +++ b/sqlor/ddl_template_postgresql.py @@ -23,7 +23,7 @@ NOT NULL {%- endif -%} {% endmacro %} {% macro primary() %} -primary key({{','.join(summary[0].primary)}}) +primary key({{summary[0].primary}}) {% endmacro %} DROP TABLE IF EXISTS {{summary[0].name}}; CREATE TABLE {{summary[0].name}} @@ -42,4 +42,4 @@ COMMENT ON TABLE {{summary[0].name}} IS '{{summary[0].title.decode('utf8')}}'; {% for field in fields %} COMMENT ON COLUMN {{summary[0].name}}.{{field.name}} is '{{field.title.decode('utf8')}}'; {% endfor %} -""" \ No newline at end of file +""" diff --git a/sqlor/ddl_template_sqlserver.py b/sqlor/ddl_template_sqlserver.py index 9861f8f..ae0239f 100644 --- a/sqlor/ddl_template_sqlserver.py +++ b/sqlor/ddl_template_sqlserver.py @@ -26,9 +26,7 @@ NOT NULL {% endmacro %} {% macro primary() %} -{% if len(','.join(summary[0].primary))>0 %} -,primary key({{','.join(summary[0].primary)}}) -{% endif %} +,primary key({{summary[0].primary}}) {% endmacro %} drop table dbo.{{summary[0].name}}; @@ -48,4 +46,4 @@ EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{{summary[0].t {% for field in fields %} EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'{{field.title}}' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'{{summary[0].name}}', @level2type=N'COLUMN',@level2name=N'{{field.name}}' {% endfor %} -""" \ No newline at end of file +"""