-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdatabase.pg.sql
628 lines (547 loc) · 19.6 KB
/
database.pg.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
-- liquibase formatted sql
-- changeset kdonald:1
CREATE TABLE UserConnection (
userId varchar(255) NOT NULL,
providerId varchar(255) NOT NULL,
providerUserId varchar(255),
rank int NOT NULL,
displayName varchar(255),
profileUrl varchar(512),
imageUrl varchar(512),
accessToken varchar(255) NOT NULL,
secret varchar(255),
refreshToken varchar(255),
expireTime bigint,
PRIMARY KEY (userId, providerId, providerUserId)
);
CREATE UNIQUE INDEX UserConnectionRank ON UserConnection (userId, providerId, rank);
-- changeset gertvv:2
CREATE TABLE Account (
id serial NOT NULL,
username varchar UNIQUE,
firstName varchar NOT NULL,
lastName varchar NOT NULL,
password varchar DEFAULT '',
PRIMARY KEY (id)
);
CREATE TABLE Workspace (
id serial NOT NULL,
owner int,
title varchar NOT NULL,
problem text NOT NULL,
defaultScenarioId int,
PRIMARY KEY (id),
FOREIGN KEY (OWNER) REFERENCES Account (id)
);
CREATE TABLE Scenario (
id serial NOT NULL,
workspace int,
title varchar NOT NULL,
state text NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (workspace) REFERENCES Workspace (id)
);
-- changeset gertvv:3
ALTER TABLE Workspace
ADD CONSTRAINT Workspace_defaultScenarioId_FK FOREIGN KEY (defaultScenarioId) REFERENCES Scenario (id) DEFERRABLE;
-- changeset gertvv:4
CREATE TABLE AccountRoles (
accountId int,
role VARCHAR NOT NULL,
FOREIGN KEY (accountId) REFERENCES Account (id)
);
-- changeset reidd:5
CREATE TABLE Remarks (
workspaceId int NOT NULL,
remarks varchar NOT NULL,
PRIMARY KEY (workspaceId),
FOREIGN KEY (workspaceId) REFERENCES Workspace (id)
);
-- changeset bobgoe:6
ALTER TABLE Workspace
ALTER COLUMN problem TYPE JSON
USING problem::json;
ALTER TABLE Scenario
ALTER COLUMN state TYPE JSON
USING state::json;
ALTER TABLE Remarks
ALTER COLUMN remarks TYPE JSON
USING remarks::json;
-- changeset joelkuiper:7
ALTER TABLE Account
ADD COLUMN email varchar DEFAULT '';
-- changeset keijserj:8
CREATE TABLE effectsTableExclusion (
workspaceId int NOT NULL,
alternativeId varchar(255) NOT NULL,
PRIMARY KEY (workspaceId, alternativeId)
);
-- changeset keijserj:9
CREATE TABLE subProblem (
id serial NOT NULL,
workspaceId int NOT NULL,
definition jsonb NOT NULL,
title varchar NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (workspaceId) REFERENCES workspace (id) ON DELETE CASCADE
);
INSERT INTO subProblem (workspaceId, definition, title)
SELECT
id,
'{}',
'Default'
FROM
workspace;
ALTER TABLE scenario
ADD COLUMN subProblemId int;
ALTER TABLE workspace
ADD COLUMN defaultSubProblemId int;
UPDATE
workspace
SET
defaultSubProblemId = subProblem.id
FROM
subProblem
WHERE
subProblem.workspaceId = workspace.id;
ALTER TABLE workspace
ADD FOREIGN KEY (defaultSubProblemId) REFERENCES subProblem (id) ON DELETE CASCADE;
UPDATE
scenario
SET
subProblemId = subProblem.id
FROM
subProblem
WHERE
subProblem.workspaceId = scenario.workspace;
ALTER TABLE scenario
ALTER COLUMN subProblemId SET NOT NULL;
ALTER TABLE scenario
ADD FOREIGN KEY (subProblemId) REFERENCES subProblem (id) ON DELETE CASCADE;
DROP TABLE remarks;
ALTER TABLE workspace
ALTER COLUMN OWNER SET NOT NULL;
--changeset keijserj:10
ALTER TABLE effectsTableExclusion RENAME TO effectsTableAlternativeInclusion;
--changeset keijserj:11
DROP TABLE effectsTableAlternativeInclusion;
--changeset reidd:12
CREATE TABLE inProgressWorkspace (
id serial NOT NULL,
owner INT NOT NULL,
state jsonb NOT NULL,
PRIMARY KEY (id),
FOREIGN KEY (OWNER) REFERENCES Account (id)
);
--changeset reidd:13
CREATE TABLE ordering (
workspaceId int NOT NULL,
ordering jsonb NOT NULL,
PRIMARY KEY (workspaceId),
FOREIGN KEY (workspaceId) REFERENCES workspace (id) ON DELETE CASCADE
);
--changeset keijserj:14
CREATE TABLE toggledColumns (
workspaceId int NOT NULL,
toggledColumns jsonb NOT NULL,
PRIMARY KEY (workspaceId),
FOREIGN KEY (workspaceId) REFERENCES workspace (id) ON DELETE CASCADE
);
--changeset reidd:15
CREATE TABLE "session" (
"sid" varchar NOT NULL COLLATE "default",
"sess" json NOT NULL,
"expire" timestamp(6) NOT NULL
)
WITH (
OIDS = FALSE
);
ALTER TABLE "session"
ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE;
--changeset keijserj:16
CREATE TABLE workspaceSettings (
workspaceId int NOT NULL,
settings jsonb NOT NULL,
PRIMARY KEY (workspaceId),
FOREIGN KEY (workspaceId) REFERENCES workspace (id) ON DELETE CASCADE
);
--changeset reidd:17
DROP TABLE toggledColumns;
--changeset reidd:18
DROP TABLE UserConnection;
--changeset reidd:19
START TRANSACTION;
ALTER TABLE scenario
DROP CONSTRAINT scenario_workspace_fkey;
ALTER TABLE scenario
ADD CONSTRAINT scenario_workspace_fkey FOREIGN KEY (workspace) REFERENCES workspace (id) ON DELETE CASCADE;
COMMIT;
--rollback START TRANSACTION;
--rollback ALTER TABLE scenario DROP CONSTRAINT scenario_workspace_fkey;
--rollback ALTER TABLE scenario ADD CONSTRAINT scenario_workspace_fkey FOREIGN KEY (workspace) REFERENCES workspace(id);
--rollback COMMIT;
--changeset keijserj:20
START TRANSACTION;
ALTER TABLE scenario
DROP CONSTRAINT scenario_workspace_fkey;
ALTER TABLE scenario
ADD CONSTRAINT scenario_workspace_fkey FOREIGN KEY (workspace) REFERENCES workspace (id) ON DELETE CASCADE;
COMMIT;
--rollback START TRANSACTION;
--rollback ALTER TABLE scenario DROP CONSTRAINT scenario_workspace_fkey;
--rollback ALTER TABLE scenario ADD CONSTRAINT scenario_workspace_fkey FOREIGN KEY (workspace) REFERENCES workspace(id);
--rollback COMMIT;
--changeset keijserj:21
START TRANSACTION;
WITH effectsDisplay AS (
SELECT
workspaceId,
settings #> '{settings}' ->> 'effectsDisplay' AS displayValue
FROM
workspacesettings
WHERE
settings #> '{settings, effectsDisplay}' IS NOT NULL
),
newSettings AS (
SELECT
workspaceId,
CASE WHEN displayValue = 'deterministic' THEN
'{"displayMode": "enteredData"}'::jsonb
WHEN displayValue = 'sourceData' THEN
'{"displayMode": "enteredData"}'::jsonb
WHEN displayValue = 'smaaDistributions' THEN
'{"displayMode": "enteredData"}'::jsonb
WHEN displayValue = 'effects' THEN
'{"displayMode": "values"}'::jsonb
WHEN displayValue = 'deterministicMCDA' THEN
'{"displayMode": "values"}'::jsonb
WHEN displayValue = 'smaa' THEN
'{"displayMode": "values"}'::jsonb
END AS displayMode,
CASE WHEN displayValue = 'deterministic' THEN
'{"analysisType": "deterministic"}'::jsonb
WHEN displayValue = 'sourceData' THEN
'{"analysisType": "deterministic"}'::jsonb
WHEN displayValue = 'smaaDistributions' THEN
'{"analysisType": "smaa"}'::jsonb
WHEN displayValue = 'effects' THEN
'{"analysisType": "deterministic"}'::jsonb
WHEN displayValue = 'deterministicMCDA' THEN
'{"analysisType": "deterministic"}'::jsonb
WHEN displayValue = 'smaa' THEN
'{"analysisType": "smaa"}'::jsonb
END AS analysisType
FROM
effectsDisplay)
UPDATE
workspacesettings
SET
settings = jsonb_set(jsonb_set(settings, '{settings, analysisType}', newSettings.analysisType -> 'analysisType'), '{settings, displayMode}', newSettings.displayMode -> 'displayMode')
FROM
newSettings
WHERE
workspacesettings.workspaceId = newSettings.workspaceId;
UPDATE
workspacesettings
SET
settings = settings #-'{settings, effectsDisplay}';
COMMIT;
--rollback START TRANSACTION;
--rollback WITH oldSettings AS (
--rollback SELECT
--rollback workspaceId,
--rollback settings#>'{settings}'->>'analysisType' AS analysisType,
--rollback settings#>'{settings}'->>'displayMode' AS displayMode
--rollback FROM workspacesettings
--rollback WHERE settings#>'{settings, analysisType}' IS NOT NULL
--rollback AND settings#>'{settings, displayMode}' IS NOT NULL
--rollback ),
--rollback
--rollback newSettings AS (
--rollback SELECT
--rollback workspaceId,
--rollback CASE
--rollback WHEN analysisType = 'deterministic' AND displayMode = 'enteredData' THEN '{"effectsDisplay": "deterministic"}'::jsonb
--rollback WHEN analysisType = 'smaa' AND displayMode = 'enteredData' THEN '{"effectsDisplay": "smaaDistributions"}'::jsonb
--rollback WHEN analysisType = 'deterministic' AND displayMode = 'values' THEN '{"effectsDisplay": "deterministicMCDA"}'::jsonb
--rollback WHEN analysisType = 'smaa' AND displayMode = 'values' THEN '{"effectsDisplay": "smaa"}'::jsonb
--rollback END AS effectsDisplay
--rollback FROM oldSettings
--rollback )
--rollback
--rollback UPDATE workspacesettings
--rollback SET settings = jsonb_set(settings, '{settings, effectsDisplay}', newSettings.effectsDisplay->'effectsDisplay')
--rollback FROM newSettings
--rollback WHERE workspacesettings.workspaceId = newSettings.workspaceId;
--rollback
--rollback UPDATE workspacesettings
--rollback SET settings = settings #-'{settings, analysisType}';
--rollback
--rollback UPDATE workspacesettings
--rollback SET settings = settings #-'{settings, displayMode}';
--rollback COMMIT;
--changeset keijserj:22
ALTER TABLE workspace
DROP CONSTRAINT workspace_defaultsubproblemid_fkey;
ALTER TABLE workspace
ADD CONSTRAINT workspace_defaultsubproblemid_fkey FOREIGN KEY (defaultSubproblemId) REFERENCES subproblem (id);
--rollback ALTER TABLE workspace DROP CONSTRAINT workspace_defaultsubproblemid_fkey;
--rollback ALTER TABLE workspace ADD CONSTRAINT workspace_defaultsubproblemid_fkey FOREIGN KEY (defaultSubproblemId) REFERENCES subproblem(id) ON DELETE CASCADE;
--changeset zalitek:23
DROP TABLE accountroles;
ALTER TABLE inprogressworkspace
DROP CONSTRAINT inprogressworkspace_owner_fkey;
ALTER TABLE inprogressworkspace
ADD CONSTRAINT inprogressworkspace_owner_fkey FOREIGN KEY (OWNER) REFERENCES account (id) ON DELETE CASCADE;
ALTER TABLE workspace
DROP CONSTRAINT workspace_owner_fkey;
ALTER TABLE workspace
ADD CONSTRAINT workspace_owner_fkey FOREIGN KEY (OWNER) REFERENCES account (id) ON DELETE CASCADE;
--rollback CREATE TABLE AccountRoles (
--rollback accountId INT,
--rollback role VARCHAR NOT NULL,
--rollback FOREIGN KEY (accountId) REFERENCES Account(id)
--rollback );
--rollback ALTER TABLE inprogressworkspace DROP CONSTRAINT inprogressworkspace_owner_fkey;
--rollback ALTER TABLE inprogressworkspace ADD CONSTRAINT inprogressworkspace_owner_fkey FOREIGN KEY (owner) REFERENCES account(id);
--rollback ALTER TABLE workspace DROP CONSTRAINT workspace_owner_fkey;
--rollback ALTER TABLE workspace ADD CONSTRAINT workspace_owner_fkey FOREIGN KEY (owner) REFERENCES account(id);
--changeset reidd:24
ALTER TABLE inProgressWorkspace
ADD COLUMN title varchar NOT NULL DEFAULT '';
ALTER TABLE inProgressWorkspace
ADD COLUMN therapeuticContext varchar DEFAULT '';
ALTER TABLE inProgressWorkspace
ADD COLUMN useFavourability boolean;
CREATE TABLE inProgressCriterion (
id varchar NOT NULL,
inProgressWorkspaceId int NOT NULL,
orderIndex int NOT NULL,
title varchar NOT NULL DEFAULT '',
description varchar NOT NULL DEFAULT '',
isFavourable boolean,
PRIMARY KEY (id),
FOREIGN KEY (inProgressWorkspaceId) REFERENCES inprogressworkspace (id) ON DELETE CASCADE
);
CREATE TYPE unitType AS enum (
'custom',
'percentage',
'decimal'
);
CREATE TABLE inProgressDataSource (
id varchar NOT NULL,
inProgressWorkspaceId int NOT NULL,
orderIndex int NOT NULL,
criterionId varchar NOT NULL,
reference varchar NOT NULL DEFAULT '',
unitLabel varchar NOT NULL DEFAULT '',
unitType unitType NOT NULL DEFAULT 'custom',
unitLowerBound int,
unitUpperBound int,
uncertainty varchar NOT NULL DEFAULT '',
strengthOfEvidence varchar NOT NULL DEFAULT '',
PRIMARY KEY (id),
FOREIGN KEY (criterionId) REFERENCES inProgressCriterion (id) ON DELETE CASCADE,
FOREIGN KEY (inProgressWorkspaceId) REFERENCES inprogressworkspace (id) ON DELETE CASCADE
);
CREATE TABLE inProgressAlternative (
id varchar NOT NULL,
orderIndex int NOT NULL,
inProgressWorkspaceId int NOT NULL,
title varchar NOT NULL DEFAULT '',
PRIMARY KEY (id),
FOREIGN KEY (inProgressWorkspaceId) REFERENCES inprogressworkspace (id) ON DELETE CASCADE
);
CREATE TYPE effectOrDistributionType AS enum (
'effect',
'distribution'
);
CREATE TYPE inputTypeType AS enum (
'value',
'valueCI',
'range',
'empty',
'text',
'normal',
'beta',
'gamma'
);
CREATE TABLE inProgressWorkspaceCell (
inProgressWorkspaceId int NOT NULL,
alternativeId varchar NOT NULL,
dataSourceId varchar NOT NULL,
criterionId varchar NOT NULL,
val float,
lowerbound float,
upperbound float,
isNotEstimableLowerBound boolean,
isNotEstimableUpperBound boolean,
txt varchar,
mean float,
standardError float,
alpha float,
beta float,
cellType effectOrDistributionType NOT NULL,
inputType inputTypeType NOT NULL,
PRIMARY KEY (alternativeId, dataSourceId, criterionId, cellType),
FOREIGN KEY (alternativeId) REFERENCES inProgressAlternative (id) ON DELETE CASCADE,
FOREIGN KEY (dataSourceId) REFERENCES inProgressDataSource (id) ON DELETE CASCADE,
FOREIGN KEY (criterionId) REFERENCES inProgressCriterion (id) ON DELETE CASCADE,
FOREIGN KEY (inProgressWorkspaceId) REFERENCES inprogressworkspace (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX inProgressWorkspaceCell_index ON inProgressWorkspaceCell (alternativeId, dataSourceId, criterionId, cellType);
--rollback ALTER TABLE inProgressWorkspace DROP COLUMN title;
--rollback ALTER TABLE inProgressWorkspace DROP COLUMN therapeuticContext;
--rollback ALTER TABLE inProgressWorkspace DROP COLUMN useFavourability;
--rollback DROP TABLE inProgressWorkspaceCell;
--rollback DROP TABLE inProgressDataSource;
--rollback DROP TABLE inProgressAlternative;
--rollback DROP TABLE inProgressCriterion;
--rollback DROP TYPE unitType;
--rollback DROP TYPE effectOrDistributionType;
--rollback DROP TYPE inputTypeType;
--rollback DROP INDEX inProgressWorkspaceCell_index;
--changeset zalitek:25
ALTER TABLE inProgressDataSource
ADD COLUMN referenceLink varchar;
--rollback ALTER TABLE inProgressDataSource DROP COLUMN referenceLink;
--changeset zalitek:26
UPDATE
scenario
SET
state = json (state)::jsonb || '{"prefs":[]}'::jsonb
WHERE
json (state) ->> 'prefs' IS NULL;
--changeset zalitek:28
ALTER TABLE workspace ADD COLUMN creationDate TIMESTAMP DEFAULT NOW() NOT NULL;
--rollback ALTER TABLE workspace DROP COLUMN creationDate
--changeset zalitek:27
START TRANSACTION;
WITH oldSettings AS (
SELECT
workspaceId,
settings#>'{settings}'->>'analysisType' AS analysisType,
settings#>'{settings}'->>'displayMode' AS displayMode
FROM workspacesettings
WHERE settings#>'{settings, analysisType}' IS NOT NULL
AND settings#>'{settings, displayMode}' IS NOT NULL
),
newSettings AS (
SELECT
workspaceId,
CASE
WHEN analysisType = 'deterministic' AND displayMode = 'enteredData' THEN '{"displayMode": "enteredEffects"}'::jsonb
WHEN analysisType = 'smaa' AND displayMode = 'enteredData' THEN '{"displayMode": "enteredDistributions"}'::jsonb
WHEN analysisType = 'deterministic' AND displayMode = 'values' THEN '{"displayMode": "deterministicValues"}'::jsonb
WHEN analysisType = 'smaa' AND displayMode = 'values' THEN '{"displayMode": "smaaValues"}'::jsonb
END AS displayMode
FROM oldSettings
)
UPDATE workspacesettings
SET settings = jsonb_set(settings, '{settings, displayMode}', newSettings.displayMode->'displayMode')
FROM newSettings
WHERE workspacesettings.workspaceId = newSettings.workspaceId;
UPDATE workspacesettings
SET settings = settings #-'{settings, analysisType}';
COMMIT;
--rollback START TRANSACTION;
--rollback WITH oldDisplayMode AS (
--rollback SELECT
--rollback workspaceId,
--rollback settings #> '{settings}' ->> 'displayMode' AS oldDisplayMode
--rollback FROM
--rollback workspacesettings
--rollback WHERE
--rollback settings #> '{settings, displayMode}' IS NOT NULL
--rollback ),
--rollback newSettings AS (
--rollback SELECT
--rollback workspaceId,
--rollback CASE WHEN oldDisplayMode = 'enteredEffects' THEN
--rollback '{"displayMode": "enteredData"}'::jsonb
--rollback WHEN oldDisplayMode = 'enteredDistributions' THEN
--rollback '{"displayMode": "enteredData"}'::jsonb
--rollback WHEN oldDisplayMode = 'smaaValues' THEN
--rollback '{"displayMode": "values"}'::jsonb
--rollback WHEN oldDisplayMode = 'deterministicValues' THEN
--rollback '{"displayMode": "values"}'::jsonb
--rollback END AS displayMode,
--rollback CASE WHEN oldDisplayMode = 'enteredEffects' THEN
--rollback '{"analysisType": "deterministic"}'::jsonb
--rollback WHEN oldDisplayMode = 'enteredDistributions' THEN
--rollback '{"analysisType": "smaa"}'::jsonb
--rollback WHEN oldDisplayMode = 'smaaValues' THEN
--rollback '{"analysisType": "smaa"}'::jsonb
--rollback WHEN oldDisplayMode = 'deterministicValues' THEN
--rollback '{"analysisType": "deterministic"}'::jsonb
--rollback END AS analysisType
--rollback FROM
--rollback oldDisplayMode)
--rollback UPDATE
--rollback workspacesettings
--rollback SET
--rollback settings = jsonb_set(jsonb_set(settings, '{settings, analysisType}', newSettings.--rollback analysisType -> 'analysisType'), '{settings, displayMode}', newSettings.displayMode -> --rollback 'displayMode')
--rollback FROM
--rollback newSettings
--rollback WHERE
--rollback workspacesettings.workspaceId = newSettings.workspaceId;
--rollback COMMIT;
--changeset reidd:28
WITH oldSettings AS (
SELECT
workspaceId,
settings#>'{settings}'->>'showPercentages' AS showPercentages
FROM workspacesettings
WHERE settings#>'{settings, showPercentages}' IS NOT NULL AND
settings#>'{settings}'->>'showPercentages' != 'decimal' AND
settings#>'{settings}'->>'showPercentages' != 'percentage'
),
newSettings AS (
SELECT
workspaceId,
CASE
WHEN showPercentages = 'true' THEN '{"showPercentages": "percentage"}'::jsonb
WHEN showPercentages = 'false'THEN '{"showPercentages": "decimal"}'::jsonb
END AS showPercentages
FROM oldSettings
)
UPDATE workspacesettings
SET settings = jsonb_set(settings, '{settings, showPercentages}', newSettings.showPercentages->'showPercentages')
FROM newSettings
WHERE workspacesettings.workspaceId = newSettings.workspaceId;
--rollback WITH oldSettings AS (
--rollback SELECT
--rollback workspaceId,
--rollback settings#>'{settings}'->>'showPercentages' AS showPercentages
--rollback FROM workspacesettings
--rollback WHERE settings#>'{settings, showPercentages}' IS NOT NULL AND
--rollback settings#>'{settings}'->>'showPercentages' != 'true' AND
--rollback settings#>'{settings}'->>'showPercentages' != 'false'
--rollback ),
--rollback newSettings AS (
--rollback SELECT
--rollback workspaceId,
--rollback CASE
--rollback WHEN showPercentages = 'percentage' THEN '{"showPercentages": true}'::jsonb
--rollback WHEN showPercentages = 'decimal'THEN '{"showPercentages": false}'::jsonb
--rollback END AS showPercentages
--rollback FROM oldSettings
--rollback )
--rollback UPDATE workspacesettings
--rollback SET settings = jsonb_set(settings, '{settings, showPercentages}', newSettings.showPercentages->'showPercentages')
--rollback FROM newSettings
--rollback WHERE workspacesettings.workspaceId = newSettings.workspaceId;
--changeset keijserj:29
ALTER TABLE inprogressworkspace ADD COLUMN creationDate TIMESTAMP DEFAULT NOW() NOT NULL;
--rollback ALTER TABLE inprogressworkspace DROP COLUMN creationDate
--changeset keijserj:30
START TRANSACTION;
CREATE TABLE thresholdElicitationValues (
scenarioid INTEGER REFERENCES scenario (id) ON DELETE CASCADE,
criterionid VARCHAR NOT NULL,
thresholdvalue FLOAT NOT NULL
);
ALTER TABLE thresholdElicitationValues
ADD CONSTRAINT criterion_scenario_combination UNIQUE (scenarioid, criterionid);
COMMIT;
--rollback DROP TABLE thresholdElicitationValues;