Skip to content

Commit

Permalink
feat: add default_form_result column to form_json table
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Mar 29, 2021
1 parent 83e1785 commit 3d7ef7c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 8 deletions.
13 changes: 7 additions & 6 deletions schema/data/prod/form_json.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@ create temporary table production (json_data jsonb);

with rows as (
insert into ggircs_portal.form_json
(id, name, slug, short_name, description, form_json, prepopulate_from_swrs, prepopulate_from_ciip, form_result_init_function)
(id, name, slug, short_name, description, form_json, prepopulate_from_swrs, prepopulate_from_ciip, form_result_init_function, default_form_result)
overriding system value
values
(1,
'Administration Data', 'admin', 'Admin data', 'Admin description',
(select json_data from administration), true, true, 'init_application_administration_form_result'),
(select json_data from administration), true, true, 'init_application_administration_form_result', '{}'),
(2, 'Emission', 'emission', 'Emission', 'Emission description',
(select json_data from emission), true, false, 'init_application_emission_form_result'),
(select json_data from emission), true, false, 'init_application_emission_form_result', '{}'),
(3, 'Fuel','fuel', 'Fuel', 'Fuel description',
(select json_data from fuel), true, false, 'init_application_fuel_form_result'),
(select json_data from fuel), true, false, 'init_application_fuel_form_result', '[]'),
(4, 'Production', 'production', 'Production', 'Production description',
(select json_data from production), false, false, null)
(select json_data from production), false, false, null, '[]')
on conflict(id) do update
set name=excluded.name, form_json=excluded.form_json,
prepopulate_from_ciip=excluded.prepopulate_from_ciip,
prepopulate_from_swrs=excluded.prepopulate_from_swrs,
slug=excluded.slug,
short_name=excluded.short_name,
description=excluded.description
description=excluded.description,
default_form_result=excluded.default_form_result
returning 1
) select 'Inserted ' || count(*) || ' rows into ggircs_portal.form_json' from rows;

Expand Down
10 changes: 10 additions & 0 deletions schema/deploy/tables/form_json_001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- Deploy ggircs-portal:tables/form_json_001 to pg
-- requires: tables/form_json

begin;

alter table ggircs_portal.form_json add column default_form_result jsonb;

comment on column ggircs_portal.form_json.default_form_result is 'The default_form_result column defines the shape of an empty form_result created from this form_json row';

commit;
7 changes: 7 additions & 0 deletions schema/revert/tables/form_json_001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Revert ggircs-portal:tables/form_json_001 from pg

begin;

alter table ggircs_portal.form_json drop column default_form_result;

commit;
2 changes: 1 addition & 1 deletion schema/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,4 @@ trigger_functions/run_graphile_worker_job [trigger_functions/run_graphile_worker
tables/certification_url_001 [tables/certification_url] 2021-03-15T21:50:02Z Pierre Bastianelli <pierre.bastianelli@gov.bc.ca> # dropping triggers for removed functions
trigger_functions/signature_md5 [trigger_functions/signature_md5@v1.16.0] 2021-03-15T22:58:28Z Pierre Bastianelli <pierre.bastianelli@gov.bc.ca> # removing since we don't certify applications anymore
trigger_functions/set_user_id [trigger_functions/set_user_id@v1.16.0] 2021-03-15T23:10:29Z Pierre Bastianelli <pierre.bastianelli@gov.bc.ca> # removing certification option
swrs_functions/refresh_swrs_version_data [tables/form_result swrs_functions/init_application_administration_form_result swrs_functions/init_application_emission_form_result swrs_functions/init_application_fuel_form_result] 2021-03-24T23:42:37Z Dylan Leard <dylan@button.is> # Function refreshes the swrs version (version 0) of an application with updated data from swrs
tables/form_json_001 [tables/form_json] 2021-03-26T20:02:39Z Dylan Leard <dylan@button.is> # Migration: add a default_form_result column to define the shape of an empty form result
21 changes: 20 additions & 1 deletion schema/test/unit/tables/form_json_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,33 @@ create extension if not exists pgtap;
reset client_min_messages;

begin;
select plan(15);
select plan(16);

-- Table exists
select has_table(
'ggircs_portal', 'form_json',
'ggircs_portal.form_json should exist, and be a table'
);

-- Columns
select columns_are('ggircs_portal'::name, 'form_json'::name, array[
'id'::name,
'name'::name,
'slug'::name,
'short_name'::name,
'description'::name,
'form_json'::name,
'created_at'::name,
'created_by'::name,
'updated_at'::name,
'updated_by'::name,
'deleted_at'::name,
'deleted_by'::name,
'prepopulate_from_ciip'::name,
'prepopulate_from_swrs'::name,
'form_result_init_function'::name,
'default_form_result'::name
]);

-- Row level security tests --

Expand Down
7 changes: 7 additions & 0 deletions schema/verify/tables/form_json_001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Verify ggircs-portal:tables/form_json_001 on pg

begin;

select pg_catalog.has_table_privilege('ggircs_portal.form_json', 'select');

rollback;

0 comments on commit 3d7ef7c

Please sign in to comment.