-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from WomenPlusPlus/table_modifications
Add migrations
- Loading branch information
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
DROP TABLE IF EXISTS public.target; | ||
|
||
CREATE TABLE target ( | ||
target_id int8 generated by default as identity, | ||
circle_id int8 not null, | ||
kpi_id int8 not null, | ||
target_value numeric not null, | ||
created_at timestamp default current_timestamp not null, | ||
updated_at timestamp, | ||
PRIMARY KEY (target_id), | ||
CONSTRAINT fk_kpi FOREIGN KEY(kpi_id) REFERENCES kpi_definition(kpi_id), | ||
CONSTRAINT fk_circle FOREIGN KEY(circle_id) REFERENCES circle(circle_id), | ||
CONSTRAINT unique_circle_kpi unique (circle_id, kpi_id) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
ALTER TABLE | ||
kpi_definition | ||
ADD | ||
COLUMN IF NOT EXISTS created_by uuid; | ||
|
||
ALTER TABLE | ||
kpi_definition | ||
ADD | ||
CONSTRAINT IF NOT EXISTS fk_auth_user FOREIGN KEY (created_by) REFERENCES auth.users (id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
ALTER TABLE | ||
kpi_values_history | ||
ADD | ||
COLUMN IF NOT EXISTS periodicity periodicity; | ||
|
||
UPDATE | ||
kpi_values_history kvh | ||
SET | ||
periodicity = k.periodicity | ||
FROM | ||
kpi_definition k | ||
WHERE | ||
kvh.kpi_id = k.kpi_id; | ||
|
||
ALTER TABLE | ||
kpi_values_history | ||
ALTER COLUMN | ||
periodicity | ||
SET | ||
NOT NULL; |