-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add CRD to ipmas and NRRM to regional districts
- Loading branch information
1 parent
9d561b7
commit ba5645b
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
database/src/migrations/0031_add_nrrm_to_regional_districts.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |