Skip to content

Commit 13d9052

Browse files
committed
Added migration sql script: create project.templateId and new tables
1 parent dcaef1c commit 13d9052

File tree

1 file changed

+309
-0
lines changed

1 file changed

+309
-0
lines changed
Lines changed: 309 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,309 @@
1+
--
2+
-- UPDATE EXISTING TABLES:
3+
-- projects
4+
-- templateId column: added
5+
-- CREATE NEW TABLES:
6+
-- milestones
7+
-- phase_products
8+
-- product_milestone_templates
9+
-- product_templates
10+
-- project_phases
11+
-- project_templates
12+
-- project_types
13+
-- timelines
14+
--
15+
16+
--
17+
-- projects
18+
--
19+
ALTER TABLE projects ADD COLUMN "templateId" bigint;
20+
21+
--
22+
-- milestones
23+
--
24+
25+
CREATE TABLE milestones (
26+
id bigint NOT NULL,
27+
name character varying(255) NOT NULL,
28+
description character varying(255),
29+
duration integer NOT NULL,
30+
"startDate" timestamp with time zone NOT NULL,
31+
"endDate" timestamp with time zone,
32+
"completionDate" timestamp with time zone,
33+
status character varying(45) NOT NULL,
34+
type character varying(45) NOT NULL,
35+
details json,
36+
"order" integer NOT NULL,
37+
"plannedText" character varying(512) NOT NULL,
38+
"activeText" character varying(512) NOT NULL,
39+
"completedText" character varying(512) NOT NULL,
40+
"blockedText" character varying(512) NOT NULL,
41+
"deletedAt" timestamp with time zone,
42+
"createdAt" timestamp with time zone,
43+
"updatedAt" timestamp with time zone,
44+
"deletedBy" bigint,
45+
"createdBy" bigint NOT NULL,
46+
"updatedBy" bigint NOT NULL,
47+
"timelineId" bigint
48+
);
49+
50+
CREATE SEQUENCE milestones_id_seq
51+
START WITH 1
52+
INCREMENT BY 1
53+
NO MINVALUE
54+
NO MAXVALUE
55+
CACHE 1;
56+
57+
ALTER SEQUENCE milestones_id_seq OWNED BY milestones.id;
58+
59+
60+
--
61+
-- phase_products
62+
--
63+
64+
CREATE TABLE phase_products (
65+
id bigint NOT NULL,
66+
name character varying(255),
67+
"projectId" bigint,
68+
"directProjectId" bigint,
69+
"billingAccountId" bigint,
70+
"templateId" bigint DEFAULT 0,
71+
type character varying(255),
72+
"estimatedPrice" double precision DEFAULT 0,
73+
"actualPrice" double precision DEFAULT 0,
74+
details json DEFAULT '{}'::json,
75+
"deletedAt" timestamp with time zone,
76+
"createdAt" timestamp with time zone,
77+
"updatedAt" timestamp with time zone,
78+
"deletedBy" integer,
79+
"createdBy" integer NOT NULL,
80+
"updatedBy" integer NOT NULL,
81+
"phaseId" bigint
82+
);
83+
84+
85+
CREATE SEQUENCE phase_products_id_seq
86+
START WITH 1
87+
INCREMENT BY 1
88+
NO MINVALUE
89+
NO MAXVALUE
90+
CACHE 1;
91+
92+
ALTER SEQUENCE phase_products_id_seq OWNED BY phase_products.id;
93+
94+
--
95+
-- product_milestone_templates
96+
--
97+
98+
CREATE TABLE product_milestone_templates (
99+
id bigint NOT NULL,
100+
name character varying(255) NOT NULL,
101+
description character varying(255),
102+
duration integer NOT NULL,
103+
type character varying(45) NOT NULL,
104+
"order" integer NOT NULL,
105+
"deletedAt" timestamp with time zone,
106+
"createdAt" timestamp with time zone,
107+
"updatedAt" timestamp with time zone,
108+
"deletedBy" bigint,
109+
"createdBy" bigint NOT NULL,
110+
"updatedBy" bigint NOT NULL,
111+
"productTemplateId" bigint
112+
);
113+
114+
CREATE SEQUENCE product_milestone_templates_id_seq
115+
START WITH 1
116+
INCREMENT BY 1
117+
NO MINVALUE
118+
NO MAXVALUE
119+
CACHE 1;
120+
121+
ALTER SEQUENCE product_milestone_templates_id_seq OWNED BY product_milestone_templates.id;
122+
123+
124+
--
125+
-- product_templates
126+
--
127+
CREATE TABLE product_templates (
128+
id bigint NOT NULL,
129+
name character varying(255) NOT NULL,
130+
"productKey" character varying(45) NOT NULL,
131+
icon character varying(255) NOT NULL,
132+
brief character varying(45) NOT NULL,
133+
details character varying(255) NOT NULL,
134+
aliases json NOT NULL,
135+
template json NOT NULL,
136+
"deletedAt" timestamp with time zone,
137+
"createdAt" timestamp with time zone,
138+
"updatedAt" timestamp with time zone,
139+
"deletedBy" bigint,
140+
"createdBy" bigint NOT NULL,
141+
"updatedBy" bigint NOT NULL
142+
);
143+
144+
CREATE SEQUENCE product_templates_id_seq
145+
START WITH 1
146+
INCREMENT BY 1
147+
NO MINVALUE
148+
NO MAXVALUE
149+
CACHE 1;
150+
151+
ALTER SEQUENCE product_templates_id_seq OWNED BY product_templates.id;
152+
153+
--
154+
-- project_phases
155+
--
156+
157+
CREATE TABLE project_phases (
158+
id bigint NOT NULL,
159+
name character varying(255),
160+
status character varying(255),
161+
"startDate" timestamp with time zone,
162+
"endDate" timestamp with time zone,
163+
budget double precision DEFAULT 0,
164+
progress double precision DEFAULT 0,
165+
details json DEFAULT '{}'::json,
166+
"deletedAt" timestamp with time zone,
167+
"createdAt" timestamp with time zone,
168+
"updatedAt" timestamp with time zone,
169+
"deletedBy" integer,
170+
"createdBy" integer NOT NULL,
171+
"updatedBy" integer NOT NULL,
172+
"projectId" bigint
173+
);
174+
175+
CREATE SEQUENCE project_phases_id_seq
176+
START WITH 1
177+
INCREMENT BY 1
178+
NO MINVALUE
179+
NO MAXVALUE
180+
CACHE 1;
181+
182+
ALTER SEQUENCE project_phases_id_seq OWNED BY project_phases.id;
183+
184+
185+
--
186+
-- project_templates
187+
--
188+
CREATE TABLE project_templates (
189+
id bigint NOT NULL,
190+
name character varying(255) NOT NULL,
191+
key character varying(45) NOT NULL,
192+
category character varying(45) NOT NULL,
193+
icon character varying(255) NOT NULL,
194+
question character varying(255) NOT NULL,
195+
info character varying(255) NOT NULL,
196+
aliases json NOT NULL,
197+
scope json NOT NULL,
198+
phases json NOT NULL,
199+
"deletedAt" timestamp with time zone,
200+
"createdAt" timestamp with time zone,
201+
"updatedAt" timestamp with time zone,
202+
"deletedBy" bigint,
203+
"createdBy" bigint NOT NULL,
204+
"updatedBy" bigint NOT NULL
205+
);
206+
207+
CREATE SEQUENCE project_templates_id_seq
208+
START WITH 1
209+
INCREMENT BY 1
210+
NO MINVALUE
211+
NO MAXVALUE
212+
CACHE 1;
213+
214+
ALTER SEQUENCE project_templates_id_seq OWNED BY project_templates.id;
215+
216+
--
217+
-- project_types
218+
--
219+
220+
CREATE TABLE project_types (
221+
key character varying(45) NOT NULL,
222+
"displayName" character varying(255) NOT NULL,
223+
"deletedAt" timestamp with time zone,
224+
"createdAt" timestamp with time zone,
225+
"updatedAt" timestamp with time zone,
226+
"deletedBy" integer,
227+
"createdBy" integer NOT NULL,
228+
"updatedBy" integer NOT NULL
229+
);
230+
231+
--
232+
-- timelines
233+
--
234+
CREATE TABLE timelines (
235+
id bigint NOT NULL,
236+
name character varying(255) NOT NULL,
237+
description character varying(255),
238+
"startDate" timestamp with time zone NOT NULL,
239+
"endDate" timestamp with time zone,
240+
reference character varying(45) NOT NULL,
241+
"referenceId" bigint NOT NULL,
242+
"deletedAt" timestamp with time zone,
243+
"createdAt" timestamp with time zone,
244+
"updatedAt" timestamp with time zone,
245+
"deletedBy" bigint,
246+
"createdBy" bigint NOT NULL,
247+
"updatedBy" bigint NOT NULL
248+
);
249+
250+
CREATE SEQUENCE timelines_id_seq
251+
START WITH 1
252+
INCREMENT BY 1
253+
NO MINVALUE
254+
NO MAXVALUE
255+
CACHE 1;
256+
257+
ALTER SEQUENCE timelines_id_seq OWNED BY timelines.id;
258+
259+
260+
ALTER TABLE ONLY milestones ALTER COLUMN id SET DEFAULT nextval('milestones_id_seq'::regclass);
261+
262+
ALTER TABLE ONLY phase_products ALTER COLUMN id SET DEFAULT nextval('phase_products_id_seq'::regclass);
263+
264+
ALTER TABLE ONLY product_milestone_templates ALTER COLUMN id SET DEFAULT nextval('product_milestone_templates_id_seq'::regclass);
265+
266+
ALTER TABLE ONLY product_templates ALTER COLUMN id SET DEFAULT nextval('product_templates_id_seq'::regclass);
267+
268+
ALTER TABLE ONLY project_phases ALTER COLUMN id SET DEFAULT nextval('project_phases_id_seq'::regclass);
269+
270+
ALTER TABLE ONLY project_templates ALTER COLUMN id SET DEFAULT nextval('project_templates_id_seq'::regclass);
271+
272+
ALTER TABLE ONLY timelines ALTER COLUMN id SET DEFAULT nextval('timelines_id_seq'::regclass);
273+
274+
ALTER TABLE ONLY milestones
275+
ADD CONSTRAINT milestones_pkey PRIMARY KEY (id);
276+
277+
ALTER TABLE ONLY phase_products
278+
ADD CONSTRAINT phase_products_pkey PRIMARY KEY (id);
279+
280+
ALTER TABLE ONLY product_milestone_templates
281+
ADD CONSTRAINT product_milestone_templates_pkey PRIMARY KEY (id);
282+
283+
ALTER TABLE ONLY product_templates
284+
ADD CONSTRAINT product_templates_pkey PRIMARY KEY (id);
285+
286+
ALTER TABLE ONLY project_phases
287+
ADD CONSTRAINT project_phases_pkey PRIMARY KEY (id);
288+
289+
ALTER TABLE ONLY project_templates
290+
ADD CONSTRAINT project_templates_pkey PRIMARY KEY (id);
291+
292+
ALTER TABLE ONLY project_types
293+
ADD CONSTRAINT project_types_pkey PRIMARY KEY (key);
294+
295+
ALTER TABLE ONLY timelines
296+
ADD CONSTRAINT timelines_pkey PRIMARY KEY (id);
297+
298+
ALTER TABLE ONLY milestones
299+
ADD CONSTRAINT "milestones_timelineId_fkey" FOREIGN KEY ("timelineId") REFERENCES timelines(id) ON UPDATE CASCADE ON DELETE CASCADE;
300+
301+
ALTER TABLE ONLY phase_products
302+
ADD CONSTRAINT "phase_products_phaseId_fkey" FOREIGN KEY ("phaseId") REFERENCES project_phases(id) ON UPDATE CASCADE ON DELETE SET NULL;
303+
304+
305+
ALTER TABLE ONLY product_milestone_templates
306+
ADD CONSTRAINT "product_milestone_templates_productTemplateId_fkey" FOREIGN KEY ("productTemplateId") REFERENCES product_templates(id) ON UPDATE CASCADE ON DELETE CASCADE;
307+
308+
ALTER TABLE ONLY project_phases
309+
ADD CONSTRAINT "project_phases_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES projects(id) ON UPDATE CASCADE ON DELETE SET NULL;

0 commit comments

Comments
 (0)