-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
39 lines (36 loc) · 1.13 KB
/
Copy pathinit.sql
File metadata and controls
39 lines (36 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* DROP TABLE IF EXISTS {{table}}; DEBUG ONLY !! */
CREATE TABLE IF NOT EXISTS {{table}} (
{% for col in columns -%}
{{col.name}} {{col.type}} {% if col.default %}{{col.default}}{% endif %}
{%- if not loop.last -%}
,
{%- endif %}
{% endfor %}
);
{% if (alter_columns|length) or (add_columns|length) or (drop_columns|length) %}
ALTER TABLE IF EXISTS {{table}}
{% for alt in alter_columns -%}
/* ALTER COLUMN {{alt.name}} TYPE {{alt.type}}*/
DROP COLUMN {{alt.name}},
ADD COLUMN {{alt.name}} {{alt.type}} {% if col.default %}{{col.default}}{% endif %}
{%- if not loop.last -%}
,
{%- elif (add_columns|length) or (drop_columns|length) -%}
,
{%- endif %}
{% endfor %}
{%- for alt in add_columns -%}
ADD COLUMN {{alt.name}} {{alt.type}} {% if col.default %}{{col.default}}{% endif %}
{%- if not loop.last -%}
,
{%- elif drop_columns|length -%}
,
{%- endif %}
{% endfor %}
{%- for alt in drop_columns -%}
DROP COLUMN {{alt.name}}
{%- if not loop.last -%}
,
{%- endif %}
{% endfor %}
{%- endif %}