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

add agencies, employers, and herbicides to code table #2965

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
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
53 changes: 53 additions & 0 deletions database/src/migrations/0076_add_agencies_employers_herbicides.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Knex } from 'knex';

export async function up(knex: Knex): Promise<void> {
await knex.raw(
`
set search_path=invasivesbc,public;

INSERT INTO code
(code_header_id, code_name, code_description, code_sort_order, valid_from, valid_to, created_at, updated_at, created_by_user_id, updated_by_user_id)
VALUES(44, 'RMT', 'Rocky Mountain Trench Natural Resources Society', 1, now(), null, now(), now(), 1, 1),
(44, 'GREP', 'Grassland and Rangeland Enhancement Program', 1, now(), null, now(), now(), 1, 1),
(44, 'CIRNAC', 'Crown-Indigenous Relations and Northern Affairs Canada', 1, now(), null, now(), now(), 1, 1),
(44, 'CWS', 'Canadian Wildlife Service', 1, now(), null, now(), now(), 1, 1),
(44, 'WSS', 'Wild Sheep Society of BC', 1, now(), null, now(), now(), 1, 1),
(79, 'CCE', 'Chu Cho Environmental', 1, now(), null, now(), now(), 1, 1),
(79, 'SFC', 'Strathinnes Forestry Consultants', 1, now(), null, now(), now(), 1, 1),
(48, '30409', 'Sightline A [aminopyralid/metsulfuron-methyl] 30409', 1, now(), null, now(), now(), 1, 1),
(47, '30795', 'Sightline B [fluroxypyr] 30795', 1, now(), null, now(), now(), 1, 1);

UPDATE code AS c
SET code_sort_order = subquery.row_number
FROM (
SELECT code_id, ROW_NUMBER() OVER (PARTITION BY code_header_id ORDER BY code_header_id, code_description) AS row_number
FROM code
) AS subquery
WHERE c.code_id = subquery.code_id;

`
);
}

export async function down(knex: Knex): Promise<void> {
await knex.raw(`

set search_path=invasivesbc,public;

DELETE FROM code
WHERE (code_header_id = 44
AND code_name IN ('RMT', 'GREP', 'CIRNAC' ,'CWS' ,'WSS'))
OR (code_header_id = 79
AND code_name IN ('CCE', 'SFC'))
OR (code_header_id = 48 and code_name in ('30409'))
OR (code_header_id = 47 and code_name in ('30795'));

UPDATE code AS c
SET code_sort_order = subquery.row_number
FROM (
SELECT code_id, ROW_NUMBER() OVER (PARTITION BY code_header_id ORDER BY code_header_id, code_description) AS row_number
FROM code
) AS subquery
WHERE c.code_id = subquery.code_id;
`);
}
Loading