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