forked from Juniper/contrail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsql_psql.tmpl
91 lines (73 loc) · 3.06 KB
/
sql_psql.tmpl
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
create table metadata (
"uuid" varchar(255),
"type" varchar(255),
"fq_name" varchar(255),
unique("type", "fq_name"),
primary key ("uuid"));
create index fq_name_index on metadata ("fq_name");
create table int_pool (
"key" varchar(255),
"start" int,
"end" int
);
alter table int_pool replica identity full;
insert into int_pool ("key", "start", "end") values ('virtual_network_id', 5, 65543);
insert into int_pool ("key", "start", "end") values ('security_group_id', 1, 65543);
create table ipaddress_pool (
"key" varchar(255),
"start" inet,
"end" inet
);
alter table ipaddress_pool replica identity full;
create table kv_store (
"key" varchar(255),
"value" varchar(255),
primary key ("key")
);
{% for schema in schemas %}{% if schema.Type != "abstract" and schema.ID %}
create table "{{ schema.ID | lower }}" (
{% for column in schema.Columns %}"{{column.Column}}" {{column.JSONSchema.SQL}},
{% endfor %} primary key("uuid"));
create index {{ schema.ID | lower }}_parent_uuid_index on "{{ schema.ID | lower }}" ("parent_uuid");
{% endif %}
{% endfor %}
{% for schema in schemas %}{% if schema.Type != "abstract" and schema.ID %}
{% for linkTo, reference in schema.References %}
create table {{ reference.Table }} (
"from" varchar(255),
"to" varchar(255),
primary key ("from","to"),
{% for column in reference.Columns %}"{{column.Column}}" {{column.JSONSchema.SQL}},
{% endfor %} foreign key ("from") references "{{ schema.ID | lower }}"(uuid) on delete cascade,
foreign key ("to") references "{{ linkTo | lower }}"(uuid));
create index index_{{ reference.Table }} on {{ reference.Table }} ("from");
{% endfor %}
{% for linkTo, reference in schema.Parents %}
create table {{ reference.Table }} (
"from" varchar(255),
"to" varchar(255),
primary key ("from","to"),
foreign key ("from") references "{{ schema.ID | lower }}"(uuid) on delete cascade,
foreign key ("to") references "{{ linkTo | lower }}"(uuid));
create index index_{{ reference.Table }} on {{ reference.Table }} ("from");
{% endfor%}
create table tenant_share_{{ schema.ID | lower }} (
"uuid" varchar(255),
"to" varchar(255),
primary key ("uuid","to"),
"access" integer,
foreign key ("uuid") references "{{ schema.ID | lower }}"(uuid) on delete cascade,
foreign key ("to") references project(uuid) on delete cascade);
create index index_t_{{ schema.ID | lower }}_id on tenant_share_{{ schema.ID | lower }}("uuid");
create index index_t_{{ schema.ID | lower }}_to on tenant_share_{{ schema.ID | lower }}("to");
create table domain_share_{{ schema.ID | lower }} (
"uuid" varchar(255),
"to" varchar(255),
primary key ("uuid","to"),
"access" integer,
foreign key ("uuid") references "{{ schema.ID | lower }}"(uuid) on delete cascade,
foreign key ("to") references domain(uuid) on delete cascade);
create index index_d_{{ schema.ID | lower }}_id on domain_share_{{ schema.ID | lower }}("uuid");
create index index_d_{{ schema.ID | lower }}_to on domain_share_{{ schema.ID | lower }}("to");
{% endif %}
{% endfor %}