Skip to content

Commit

Permalink
Merge pull request #27 from WomenPlusPlus/table_modifications
Browse files Browse the repository at this point in the history
Add migrations
  • Loading branch information
Aurelieph authored Oct 18, 2023
2 parents c785aec + e64dbae commit db82006
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions migrations/V12_recreate_table_target.sql
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)
);
9 changes: 9 additions & 0 deletions migrations/V13_add_column_created_by.sql
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);
20 changes: 20 additions & 0 deletions migrations/V14__add_periodicity_column.sql
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;

0 comments on commit db82006

Please sign in to comment.