Skip to content

Commit

Permalink
add CRD to ipmas and NRRM to regional districts
Browse files Browse the repository at this point in the history
  • Loading branch information
brennanwebster committed Dec 5, 2024
1 parent 9d561b7 commit ba5645b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions database/src/migrations/0030_add_crd_ipmas.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Knex } from 'knex';
import axios from 'axios';
import { ungzip } from 'node-gzip';

export async function up(knex: Knex): Promise<void> {
try {
const url = 'https://nrs.objectstore.gov.bc.ca/seeds/CRD_IPMAS.sql.gz';
const { data } = await axios.get(url, { responseType: 'arraybuffer' });
const sql = await ungzip(data);

await knex.raw(sql.toString());
} catch (e) {
console.error('Failed to insert IPMAS data:', e);
throw e;
}
}

export async function down(knex: Knex): Promise<void> {
try {
await knex.raw(`
DELETE FROM public.invasive_plant_management_areas
WHERE agency_cd = 'CRD';
`);
} catch (e) {
console.error('Failed to rollback IPMAS data:', e);
throw e;
}
}
28 changes: 28 additions & 0 deletions database/src/migrations/0031_add_nrrm_to_regional_districts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Knex } from 'knex';
import axios from 'axios';
import { ungzip } from 'node-gzip';

export async function up(knex: Knex): Promise<void> {
try {
const url = 'https://nrs.objectstore.gov.bc.ca/seeds/NRRM.sql.gz';
const { data } = await axios.get(url, { responseType: 'arraybuffer' });
const sql = await ungzip(data);

await knex.raw(sql.toString());
} catch (e) {
console.error('Failed to insert NRRM data:', e);
throw e;
}
}

export async function down(knex: Knex): Promise<void> {
try {
await knex.raw(`
DELETE FROM public.regional_districts
WHERE agency_cd = 'NRRM';
`);
} catch (e) {
console.error('Failed to rollback NRRM data:', e);
throw e;
}
}

0 comments on commit ba5645b

Please sign in to comment.