Skip to content

Commit

Permalink
fix: naics_code should be varchar
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Mar 18, 2021
1 parent 02aafea commit 563e1bb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
8 changes: 6 additions & 2 deletions schema/deploy/tables/naics.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
begin;

create table ggircs_portal.naics (
naics_code integer not null primary key,
id integer primary key generated always as identity,
naics_code varchar(1000) not null,
naics_description varchar(10000) not null
);

create unique index naics_naics_code_uindex on ggircs_portal.naics(naics_code);

select ggircs_portal_private.upsert_timestamp_columns(
table_schema_name := 'ggircs_portal',
table_name := 'naics',
Expand Down Expand Up @@ -36,7 +39,8 @@ $grant$;
alter table ggircs_portal.naics enable row level security;

comment on table ggircs_portal.naics is 'Table contains naics codes & their descriptions. NAICS is an acronym for North American Industry Classification System and is used to categorize industrial operations into sectors.';
comment on column ggircs_portal.naics.naics_code is 'Primary key for naics table';
comment on column ggircs_portal.naics.id is 'Primary key for naics table';
comment on column ggircs_portal.naics.naics_code is 'The naics_code, NAICS is an acronym for North American Industry Classification System and is used to categorize industrial operations into sectors.';
comment on column ggircs_portal.naics.naics_description is 'Unique step_name to be included in during an application review';

commit;
26 changes: 16 additions & 10 deletions schema/test/unit/tables/naics_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ create extension if not exists pgtap;
reset client_min_messages;

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

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

select has_index(
'ggircs_portal', 'naics', 'naics_naics_code_uindex',
'naics table has a unique index on the naics_code column'
);


-- Test Setup
select test_helper.clean_ggircs_portal_schema();
alter table ggircs_portal.ciip_user disable trigger _welcome_email;
Expand All @@ -27,7 +33,7 @@ select results_eq(
$$
select naics_code from ggircs_portal.naics;
$$,
ARRAY[1234::integer],
ARRAY[1234::varchar(1000)],
'ciip_administrator can select data from the naics table'
);

Expand All @@ -41,7 +47,7 @@ select lives_ok(

select results_eq(
$$
select naics_description from ggircs_portal.naics where naics_code=1001;
select naics_description from ggircs_portal.naics where naics_code='1001';
$$,
ARRAY['admin created'::varchar(10000)],
'Data was inserted by ciip_administrator'
Expand All @@ -56,7 +62,7 @@ select lives_ok(

select results_eq(
$$
select naics_description from ggircs_portal.naics where naics_code=1001;
select naics_description from ggircs_portal.naics where naics_code='1001';
$$,
ARRAY['admin updated'::varchar(10000)],
'Data was updated by ciip_administrator'
Expand All @@ -76,9 +82,9 @@ select concat('current user is: ', (select current_user));

select results_eq(
$$
select naics_code from ggircs_portal.naics where naics_code=1234;
select naics_code from ggircs_portal.naics where naics_code='1234';
$$,
ARRAY[1234::integer],
ARRAY[1234::varchar(1000)],
'Industry user can view data from naics'
);

Expand All @@ -92,7 +98,7 @@ select throws_like(

select throws_like(
$$
update ggircs_portal.naics set naics_description='user changed' where naics_code=1234;
update ggircs_portal.naics set naics_description='user changed' where naics_code='1234';
$$,
'permission denied%',
'Industry User cannot update ggircs_portal.naics'
Expand All @@ -112,9 +118,9 @@ select concat('current user is: ', (select current_user));

select results_eq(
$$
select naics_code from ggircs_portal.naics where naics_code=1234;
select naics_code from ggircs_portal.naics where naics_code='1234';
$$,
ARRAY[1234::integer],
ARRAY[1234::varchar(1000)],
'Analyst can select from table naics'
);

Expand All @@ -128,7 +134,7 @@ select throws_like(

select throws_like(
$$
update ggircs_portal.naics set naics_description='user changed' where naics_code=1234;
update ggircs_portal.naics set naics_description='user changed' where naics_code='1234';
$$,
'permission denied%',
'Analyst cannot update ggircs_portal.naics'
Expand Down

0 comments on commit 563e1bb

Please sign in to comment.