Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/add db tables #3

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
859b8c7
feat: add sqitch
mikevespi Aug 29, 2022
d0aa730
feat: create db user roles
mikevespi Aug 29, 2022
e4847f4
feat: create eed schema
mikevespi Aug 29, 2022
27c3f6e
feat: create eed_private schema
mikevespi Aug 29, 2022
8bc62c0
feat: add verify_function_not_present function
mikevespi Aug 29, 2022
5ccdab5
feat: add eed_private.grant_permissions
mikevespi Aug 29, 2022
c1a5724
chore: typo fix
mikevespi Aug 29, 2022
6694043
feat: add eed_private.update_timestamps trigger function
mikevespi Aug 29, 2022
8073d3c
feat: add eed_private.upsert_timestamp_columns util function
mikevespi Aug 29, 2022
889a400
chore: add dependancy to sqitch.plan
mikevespi Aug 29, 2022
290619e
feat: add update_timestamps trigger function
mikevespi Aug 29, 2022
31fdd39
chore: add scratch directories to gitignore
mikevespi Aug 29, 2022
b7e685c
feat: add archived_records_are_immutable and verify_grant functions
mikevespi Aug 29, 2022
9b43d6c
feat: add data_provider table
mikevespi Aug 29, 2022
33b01a8
feat: add eed.eed_user table
mikevespi Aug 29, 2022
8ac9461
chore: reorder sqitch plan
mikevespi Aug 29, 2022
c6f9269
Merge branch 'develop' into feat/add-db-tables
tmastrom Aug 30, 2022
bb91131
chore: fix user table naming and update user table verification params
tmastrom Aug 30, 2022
2bad03a
feat: add eed.housing_type_code table
tmastrom Aug 31, 2022
a41fe85
feat: add livestock_type_code table
tmastrom Aug 31, 2022
b0f2dfb
feat: add measurement_type_code table
tmastrom Aug 31, 2022
57edcbc
chore: fix data type
tmastrom Aug 31, 2022
720f1af
feat: add sector_type_code table
tmastrom Aug 31, 2022
d85b62d
feat: add subsector_type_code table
tmastrom Aug 31, 2022
623d62d
feat: add secondary_indicator table
tmastrom Aug 31, 2022
91abaaf
feat: add subsecondary_indicator table
tmastrom Aug 31, 2022
8842aeb
feat: add indicator_detail_type table
tmastrom Aug 31, 2022
b465bb5
feat: add vehicle_class table
tmastrom Aug 31, 2022
07cd6e6
feat: add postal_code table
tmastrom Aug 31, 2022
645d9d8
feat: add rate_class table
tmastrom Aug 31, 2022
bcb603a
feat: add org_unit table
tmastrom Aug 31, 2022
98ec150
feat: create org_unit_type_code table
tmastrom Aug 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 33 additions & 3 deletions schema/deploy/tables/data_provider.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
-- Deploy eed:tables/data_provider to pg

BEGIN;
begin;

-- XXX Add DDLs here.
create table eed.data_provider(
data_proveder_id integer primary key,
provider_name varchar(200) not null,
contact_name varchar(200),
phone varchar(100) constraint e164_format check (phone ~ '^\+\d{1,15}$'),
contact_email varchar(200),
effective_date date not null,
expiry_date date
);

COMMIT;
select eed_private.upsert_timestamp_columns('eed', 'data_provider');

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'data_provider', 'eed_internal');
perform eed_private.grant_permissions('insert', 'data_provider', 'eed_internal');
perform eed_private.grant_permissions('update', 'data_provider', 'eed_internal');

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'data_provider', 'eed_admin');
perform eed_private.grant_permissions('insert', 'data_provider', 'eed_admin');
perform eed_private.grant_permissions('update', 'data_provider', 'eed_admin');

-- Grant eed_external no permissions
-- Grant eed_guest no permissions

end
$grant$;

commit;
54 changes: 54 additions & 0 deletions schema/deploy/tables/eed_user.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
-- Deploy eed:tables/eed_user to pg

begin;
create table eed.eed_user
(
id integer primary key generated always as identity,
uuid uuid not null,
given_name varchar(1000),
family_name varchar(1000),
email_address varchar(1000)
);

select eed_private.upsert_timestamp_columns('eed', 'eed_user');

create unique index eed_user_uuid on eed.eed_user(uuid);
create unique index eed_user_email_address on eed.eed_user(email_address);

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'eed_user', 'eed_internal');
perform eed_private.grant_permissions('insert', 'eed_user', 'eed_internal');
perform eed_private.grant_permissions('update', 'eed_user', 'eed_internal',
ARRAY['given_name', 'family_name', 'email_address', 'created_at', 'updated_at', 'archived_at']);

-- Grant eed_external permissions
perform eed_private.grant_permissions('select', 'eed_user', 'eed_external');
perform eed_private.grant_permissions('insert', 'eed_user', 'eed_external');
perform eed_private.grant_permissions('update', 'eed_user', 'eed_external',
ARRAY['given_name', 'family_name', 'email_address', 'created_at', 'updated_at', 'archived_at']);

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'eed_user', 'eed_admin');
perform eed_private.grant_permissions('insert', 'eed_user', 'eed_admin');
perform eed_private.grant_permissions('update', 'eed_user', 'eed_admin',
ARRAY['given_name', 'family_name', 'email_address', 'created_at', 'updated_at', 'archived_at']);


end
$grant$;

-- Enable row-level security
alter table eed.eed_user enable row level security;

comment on table eed.eed_user is 'Table containing information about the application''s users ';
comment on column eed.eed_user.id is 'Unique ID for the user';
comment on column eed.eed_user.uuid is 'Universally Unique ID for the user, defined by the single sign-on provider';
comment on column eed.eed_user.given_name is 'User''s first name';
comment on column eed.eed_user.family_name is 'User''s last name';
comment on column eed.eed_user.email_address is 'User''s email address';

commit;
35 changes: 35 additions & 0 deletions schema/deploy/tables/housing_type_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- Deploy eed:tables/housing_type_code to pg
-- requires: schemas/main

begin;

create table eed.housing_type_code(
housing_type_code varchar(4) not null,
housing_type_desc varchar(40) not null,
effective_date date not null,
expiry_date date
);

select eed_private.upsert_timestamp_columns('eed', 'housing_type_code');

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'housing_type_code', 'eed_internal');
perform eed_private.grant_permissions('insert', 'housing_type_code', 'eed_internal');
perform eed_private.grant_permissions('update', 'housing_type_code', 'eed_internal');

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'housing_type_code', 'eed_admin');
perform eed_private.grant_permissions('insert', 'housing_type_code', 'eed_admin');
perform eed_private.grant_permissions('update', 'housing_type_code', 'eed_admin');

-- Grant eed_external no permissions
-- Grant eed_guest no permissions

end
$grant$;

commit;
37 changes: 37 additions & 0 deletions schema/deploy/tables/indicator_detail_type.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Deploy eed:tables/indicator_detail_type to pg
-- requires: schemas/main

begin;

create table eed.indicator_detail_type(
indicator_detail_type varchar(5) not null,
unit_of_measure_code varchar(6) not null,
unit_description varchar(50) not null,
effective_date date not null,
secondary_indicator_code varchar(6) not null,
expiry_date date
);

select eed_private.upsert_timestamp_columns('eed', 'indicator_detail_type');

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'indicator_detail_type', 'eed_internal');
perform eed_private.grant_permissions('insert', 'indicator_detail_type', 'eed_internal');
perform eed_private.grant_permissions('update', 'indicator_detail_type', 'eed_internal');

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'indicator_detail_type', 'eed_admin');
perform eed_private.grant_permissions('insert', 'indicator_detail_type', 'eed_admin');
perform eed_private.grant_permissions('update', 'indicator_detail_type', 'eed_admin');

-- Grant eed_external no permissions
-- Grant eed_guest no permissions

end
$grant$;

commit;
35 changes: 35 additions & 0 deletions schema/deploy/tables/livestock_type_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- Deploy eed:tables/livestock_type_code to pg
-- requires: schemas/main

begin;

create table eed.livestock_type_code(
livestock_type_code numeric(3) not null,
livestock_type_desc varchar(100) not null,
effective_date date not null,
expiry_date date
);

select eed_private.upsert_timestamp_columns('eed', 'livestock_type_code');

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'livestock_type_code', 'eed_internal');
perform eed_private.grant_permissions('insert', 'livestock_type_code', 'eed_internal');
perform eed_private.grant_permissions('update', 'livestock_type_code', 'eed_internal');

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'livestock_type_code', 'eed_admin');
perform eed_private.grant_permissions('insert', 'livestock_type_code', 'eed_admin');
perform eed_private.grant_permissions('update', 'livestock_type_code', 'eed_admin');

-- Grant eed_external no permissions
-- Grant eed_guest no permissions

end
$grant$;

commit;
39 changes: 39 additions & 0 deletions schema/deploy/tables/measurement_type_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- Deploy eed:tables/measurement_type_code to pg
-- requires: schemas/main

begin;

create table eed.measurement_type_code(
measurement_type_code varchar(6) not null,
measurement_type_desc varchar(50) not null,
measurement_unit varchar(5),
measurement_unit_desc varchar(50),
effective_date date not null,
expiry_date date,
sort_order numeric(3) not null,
energy_conversion_factor numeric(8, 4)
);

select eed_private.upsert_timestamp_columns('eed', 'measurement_type_code');

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'measurement_type_code', 'eed_internal');
perform eed_private.grant_permissions('insert', 'measurement_type_code', 'eed_internal');
perform eed_private.grant_permissions('update', 'measurement_type_code', 'eed_internal');

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'measurement_type_code', 'eed_admin');
perform eed_private.grant_permissions('insert', 'measurement_type_code', 'eed_admin');
perform eed_private.grant_permissions('update', 'measurement_type_code', 'eed_admin');

-- Grant eed_external no permissions
-- Grant eed_guest no permissions

end
$grant$;

commit;
39 changes: 39 additions & 0 deletions schema/deploy/tables/org_unit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- Deploy eed:tables/org_unit to pg
-- requires: schemas/main

begin;

create table eed.org_unit(
org_unit_id numeric(10) not null,
unit_name varchar(100) not null,
spatial_link_value varchar(200),
effective_date date not null,
expiry_date date,
or_unit_id_is_part_of numeric(10),
org_unit_type_code numeric(10) not null,
reporting_level numeric(1)
);

select eed_private.upsert_timestamp_columns('eed', 'org_unit');

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'org_unit', 'eed_internal');
perform eed_private.grant_permissions('insert', 'org_unit', 'eed_internal');
perform eed_private.grant_permissions('update', 'org_unit', 'eed_internal');

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'org_unit', 'eed_admin');
perform eed_private.grant_permissions('insert', 'org_unit', 'eed_admin');
perform eed_private.grant_permissions('update', 'org_unit', 'eed_admin');

-- Grant eed_external no permissions
-- Grant eed_guest no permissions

end
$grant$;

commit;
37 changes: 37 additions & 0 deletions schema/deploy/tables/org_unit_type_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Deploy eed:tables/org_unit_type_code to pg
-- requires: schemas/main

begin;

create table eed.org_unit_type_code(
org_unit_type_code numeric(10) not null,
org_unit_type_name varchar(50) not null,
spatial_data_source varchar(200),
spatial_link_field varchar(200),
effective_date date not null,
expiry_date date
);

select eed_private.upsert_timestamp_columns('eed', 'org_unit_type_code');

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'org_unit_type_code', 'eed_internal');
perform eed_private.grant_permissions('insert', 'org_unit_type_code', 'eed_internal');
perform eed_private.grant_permissions('update', 'org_unit_type_code', 'eed_internal');

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'org_unit_type_code', 'eed_admin');
perform eed_private.grant_permissions('insert', 'org_unit_type_code', 'eed_admin');
perform eed_private.grant_permissions('update', 'org_unit_type_code', 'eed_admin');

-- Grant eed_external no permissions
-- Grant eed_guest no permissions

end
$grant$;

commit;
34 changes: 34 additions & 0 deletions schema/deploy/tables/postal_code.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
-- Deploy eed:tables/postal_code to pg
-- requires: schemas/main

begin;

create table eed.postal_code(
postal_code varchar(6) not null,
effective_date date not null,
expiry_date date
);

select eed_private.upsert_timestamp_columns('eed', 'postal_code');

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'postal_code', 'eed_internal');
perform eed_private.grant_permissions('insert', 'postal_code', 'eed_internal');
perform eed_private.grant_permissions('update', 'postal_code', 'eed_internal');

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'postal_code', 'eed_admin');
perform eed_private.grant_permissions('insert', 'postal_code', 'eed_admin');
perform eed_private.grant_permissions('update', 'postal_code', 'eed_admin');

-- Grant eed_external no permissions
-- Grant eed_guest no permissions

end
$grant$;

commit;
36 changes: 36 additions & 0 deletions schema/deploy/tables/rate_class.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
-- Deploy eed:tables/rate_class to pg
-- requires: schemas/main

begin;

create table eed.rate_class(
rate_class numeric(3) not null,
rate_class_meaning varchar(120) not null,
personal_work_indicator varchar(1),
effective_date date not null,
expiry_date date
);

select eed_private.upsert_timestamp_columns('eed', 'rate_class');

do
$grant$
begin

-- Grant eed_internal permissions
perform eed_private.grant_permissions('select', 'rate_class', 'eed_internal');
perform eed_private.grant_permissions('insert', 'rate_class', 'eed_internal');
perform eed_private.grant_permissions('update', 'rate_class', 'eed_internal');

-- Grant eed_admin permissions
perform eed_private.grant_permissions('select', 'rate_class', 'eed_admin');
perform eed_private.grant_permissions('insert', 'rate_class', 'eed_admin');
perform eed_private.grant_permissions('update', 'rate_class', 'eed_admin');

-- Grant eed_external no permissions
-- Grant eed_guest no permissions

end
$grant$;

commit;
Loading