diff --git a/database/src/migrations/0030_add_crd_ipmas.ts b/database/src/migrations/0030_add_crd_ipmas.ts new file mode 100644 index 000000000..0a49e8224 --- /dev/null +++ b/database/src/migrations/0030_add_crd_ipmas.ts @@ -0,0 +1,28 @@ +import { Knex } from 'knex'; +import axios from 'axios'; +import { ungzip } from 'node-gzip'; + +export async function up(knex: Knex): Promise { + 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 { + 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; + } +} diff --git a/database/src/migrations/0031_add_nrrm_to_regional_districts.ts b/database/src/migrations/0031_add_nrrm_to_regional_districts.ts new file mode 100644 index 000000000..8ba474e9d --- /dev/null +++ b/database/src/migrations/0031_add_nrrm_to_regional_districts.ts @@ -0,0 +1,28 @@ +import { Knex } from 'knex'; +import axios from 'axios'; +import { ungzip } from 'node-gzip'; + +export async function up(knex: Knex): Promise { + 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 { + 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; + } +}