-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqitch.sql
186 lines (163 loc) · 5.49 KB
/
sqitch.sql
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
CREATE SCHEMA sqitch;
COMMENT ON SCHEMA sqitch IS 'Sqitch database deployment metadata v1.0.';
CREATE SCHEMA flipr;
CREATE TABLE sqitch.projects
(
project varchar(1024) NOT NULL,
uri varchar(1024),
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
creator_name varchar(1024) NOT NULL,
creator_email varchar(1024) NOT NULL
);
COMMENT ON TABLE sqitch.projects IS 'Sqitch projects deployed to this database.';
ALTER TABLE sqitch.projects ADD CONSTRAINT C_PRIMARY PRIMARY KEY (project);
ALTER TABLE sqitch.projects ADD CONSTRAINT C_UNIQUE UNIQUE (uri);
CREATE TABLE sqitch.changes
(
change_id char(40) NOT NULL,
change varchar(1024) NOT NULL,
project varchar(1024) NOT NULL,
note varchar(65000) NOT NULL DEFAULT '',
committed_at timestamptz NOT NULL DEFAULT clock_timestamp(),
committer_name varchar(1024) NOT NULL,
committer_email varchar(1024) NOT NULL,
planned_at timestamptz NOT NULL,
planner_name varchar(1024) NOT NULL,
planner_email varchar(1024) NOT NULL
);
COMMENT ON TABLE sqitch.changes IS 'Tracks the changes currently deployed to the database.';
ALTER TABLE sqitch.changes ADD CONSTRAINT C_PRIMARY PRIMARY KEY (change_id);
CREATE TABLE sqitch.tags
(
tag_id char(40) NOT NULL,
tag varchar(1024) NOT NULL,
project varchar(1024) NOT NULL,
change_id char(40) NOT NULL,
note varchar(65000) NOT NULL DEFAULT '',
committed_at timestamptz NOT NULL DEFAULT clock_timestamp(),
committer_name varchar(1024) NOT NULL,
committer_email varchar(1024) NOT NULL,
planned_at timestamptz NOT NULL,
planner_name varchar(1024) NOT NULL,
planner_email varchar(1024) NOT NULL
);
COMMENT ON TABLE sqitch.tags IS 'Tracks the tags currently applied to the database.';
ALTER TABLE sqitch.tags ADD CONSTRAINT C_PRIMARY PRIMARY KEY (tag_id);
ALTER TABLE sqitch.tags ADD CONSTRAINT C_UNIQUE UNIQUE (project, tag);
CREATE TABLE sqitch.dependencies
(
change_id char(40) NOT NULL,
type varchar(8) NOT NULL,
dependency varchar(2048) NOT NULL,
dependency_id char(40)
);
COMMENT ON TABLE sqitch.dependencies IS 'Tracks the currently satisfied dependencies.';
ALTER TABLE sqitch.dependencies ADD CONSTRAINT C_PRIMARY PRIMARY KEY (change_id, dependency);
CREATE TABLE sqitch.events
(
event varchar(6) NOT NULL,
change_id char(40) NOT NULL,
change varchar(1024) NOT NULL,
project varchar(1024) NOT NULL,
note varchar(65000) NOT NULL DEFAULT '',
requires long varchar(1048576) NOT NULL DEFAULT '{}',
conflicts long varchar(1048576) NOT NULL DEFAULT '{}',
tags long varchar(1048576) NOT NULL DEFAULT '{}',
committed_at timestamptz NOT NULL DEFAULT clock_timestamp(),
committer_name varchar(1024) NOT NULL,
committer_email varchar(1024) NOT NULL,
planned_at timestamptz NOT NULL,
planner_name varchar(1024) NOT NULL,
planner_email varchar(1024) NOT NULL
);
COMMENT ON TABLE sqitch.events IS 'Contains full history of all deployment events.';
ALTER TABLE sqitch.events ADD CONSTRAINT C_PRIMARY PRIMARY KEY (change_id, committed_at);
ALTER TABLE sqitch.changes ADD CONSTRAINT C_FOREIGN FOREIGN KEY (project) references sqitch.projects (project);
ALTER TABLE sqitch.tags ADD CONSTRAINT C_FOREIGN FOREIGN KEY (project) references sqitch.projects (project);
ALTER TABLE sqitch.tags ADD CONSTRAINT C_FOREIGN_1 FOREIGN KEY (change_id) references sqitch.changes (change_id);
ALTER TABLE sqitch.dependencies ADD CONSTRAINT C_FOREIGN FOREIGN KEY (change_id) references sqitch.changes (change_id);
ALTER TABLE sqitch.dependencies ADD CONSTRAINT C_FOREIGN_1 FOREIGN KEY (dependency_id) references sqitch.changes (change_id);
ALTER TABLE sqitch.events ADD CONSTRAINT C_FOREIGN FOREIGN KEY (project) references sqitch.projects (project);
CREATE PROJECTION sqitch.changes_super /*+basename(changes),createtype(P)*/
(
change_id,
change,
project,
note,
committed_at,
committer_name,
committer_email,
planned_at,
planner_name,
planner_email
)
AS
SELECT changes.change_id,
changes.change,
changes.project,
changes.note,
changes.committed_at,
changes.committer_name,
changes.committer_email,
changes.planned_at,
changes.planner_name,
changes.planner_email
FROM sqitch.changes
ORDER BY changes.project,
changes.change_id
SEGMENTED BY hash(changes.change_id) ALL NODES ;
CREATE PROJECTION sqitch.projects_super /*+basename(projects),createtype(L)*/
(
project,
uri,
created_at,
creator_name,
creator_email
)
AS
SELECT projects.project,
projects.uri,
projects.created_at,
projects.creator_name,
projects.creator_email
FROM sqitch.projects
ORDER BY projects.project
SEGMENTED BY hash(projects.project) ALL NODES ;
CREATE PROJECTION sqitch.events_super /*+basename(events),createtype(L)*/
(
event,
change_id,
change,
project,
note,
requires,
conflicts,
tags,
committed_at,
committer_name,
committer_email,
planned_at,
planner_name,
planner_email
)
AS
SELECT events.event,
events.change_id,
events.change,
events.project,
events.note,
events.requires,
events.conflicts,
events.tags,
events.committed_at,
events.committer_name,
events.committer_email,
events.planned_at,
events.planner_name,
events.planner_email
FROM sqitch.events
ORDER BY events.project,
events.change_id,
events.committed_at
SEGMENTED BY hash(events.change_id, events.committed_at) ALL NODES ;
SELECT MARK_DESIGN_KSAFE(0);