From a87493d7b8a29b484471639151482226155366f0 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Tue, 24 Sep 2024 11:51:09 -0700 Subject: [PATCH 1/4] feat: CE-1035 Update lead agency field in CEEB decision --- backend/prisma/schema.prisma | 3 +- backend/src/agency_code/agency_code.graphql | 11 + backend/src/agency_code/agency_code.module.ts | 10 + .../agency_code/agency_code.resolver.spec.ts | 21 ++ .../src/agency_code/agency_code.resolver.ts | 18 ++ .../agency_code/agency_code.service.spec.ts | 20 ++ .../src/agency_code/agency_code.service.ts | 40 +++ .../entities/agency_code.entity.ts | 7 + backend/src/app.module.ts | 2 + backend/src/case_file/case_file.service.ts | 14 +- migrations/sql/R__code-table-data.sql.sql | 268 ++++++++++++++++++ migrations/sql/V1.28.0__CE-1035.sql | 6 + 12 files changed, 412 insertions(+), 8 deletions(-) create mode 100644 backend/src/agency_code/agency_code.graphql create mode 100644 backend/src/agency_code/agency_code.module.ts create mode 100644 backend/src/agency_code/agency_code.resolver.spec.ts create mode 100644 backend/src/agency_code/agency_code.resolver.ts create mode 100644 backend/src/agency_code/agency_code.service.spec.ts create mode 100644 backend/src/agency_code/agency_code.service.ts create mode 100644 backend/src/agency_code/entities/agency_code.entity.ts create mode 100644 migrations/sql/V1.28.0__CE-1035.sql diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 7b4d2f76..2b1aed1f 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -246,6 +246,7 @@ model agency_code { agency_code String @id(map: "PK_agency_code") @db.VarChar(10) short_description String? @db.VarChar(50) long_description String? @db.VarChar(250) + display_order Int? active_ind Boolean? create_user_id String @db.VarChar(32) create_utc_timestamp DateTime @db.Timestamp(6) @@ -467,7 +468,7 @@ model decision { discharge_code String @db.VarChar(10) rationale_code String? @db.VarChar(10) inspection_number Int? - lead_agency String? @db.VarChar(10) + lead_agency_code String? @db.VarChar(10) non_compliance_decision_matrix_code String? @db.VarChar(10) active_ind Boolean create_user_id String @db.VarChar(32) diff --git a/backend/src/agency_code/agency_code.graphql b/backend/src/agency_code/agency_code.graphql new file mode 100644 index 00000000..c9b0ccc3 --- /dev/null +++ b/backend/src/agency_code/agency_code.graphql @@ -0,0 +1,11 @@ +type AgencyCode { + agencyCode: String + shortDescription: String + longDescription: String + displayOrder: Int + activeIndicator: Boolean +} + +type Query { + agencyCodes: [AgencyCode]! +} diff --git a/backend/src/agency_code/agency_code.module.ts b/backend/src/agency_code/agency_code.module.ts new file mode 100644 index 00000000..c68e503c --- /dev/null +++ b/backend/src/agency_code/agency_code.module.ts @@ -0,0 +1,10 @@ +import { Module } from "@nestjs/common"; +import { AgencyCodeService } from "./agency_code.service"; +import { AgencyCodeResolver } from "./agency_code.resolver"; +import { PrismaModule } from "nestjs-prisma"; + +@Module({ + imports: [PrismaModule], + providers: [AgencyCodeResolver, AgencyCodeService], +}) +export class AgencyCodeModule {} diff --git a/backend/src/agency_code/agency_code.resolver.spec.ts b/backend/src/agency_code/agency_code.resolver.spec.ts new file mode 100644 index 00000000..90fc95a9 --- /dev/null +++ b/backend/src/agency_code/agency_code.resolver.spec.ts @@ -0,0 +1,21 @@ +import { Test, TestingModule } from "@nestjs/testing"; +import { AgencyCodeResolver } from "./agency_code.resolver"; +import { AgencyCodeService } from "./agency_code.service"; +import { PrismaModule } from "nestjs-prisma"; + +describe("AgencyCodeResolver", () => { + let resolver: AgencyCodeResolver; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [PrismaModule], + providers: [AgencyCodeResolver, AgencyCodeService], + }).compile(); + + resolver = module.get(AgencyCodeResolver); + }); + + it("should be defined", () => { + expect(resolver).toBeDefined(); + }); +}); diff --git a/backend/src/agency_code/agency_code.resolver.ts b/backend/src/agency_code/agency_code.resolver.ts new file mode 100644 index 00000000..77d22e8a --- /dev/null +++ b/backend/src/agency_code/agency_code.resolver.ts @@ -0,0 +1,18 @@ +import { Resolver, Query, Args } from "@nestjs/graphql"; +import { AgencyCodeService } from "./agency_code.service"; +import { JwtRoleGuard } from "../auth/jwtrole.guard"; +import { UseGuards } from "@nestjs/common"; +import { Role } from "../enum/role.enum"; +import { Roles } from "../auth/decorators/roles.decorator"; + +@UseGuards(JwtRoleGuard) +@Resolver("AgencyCode") +export class AgencyCodeResolver { + constructor(private readonly agencyCodeService: AgencyCodeService) {} + + @Query("agencyCodes") + @Roles(Role.COS_OFFICER, Role.CEEB) + findAll() { + return this.agencyCodeService.findAll(); + } +} diff --git a/backend/src/agency_code/agency_code.service.spec.ts b/backend/src/agency_code/agency_code.service.spec.ts new file mode 100644 index 00000000..88454184 --- /dev/null +++ b/backend/src/agency_code/agency_code.service.spec.ts @@ -0,0 +1,20 @@ +import { Test, TestingModule } from "@nestjs/testing"; +import { AgencyCodeService } from "./agency_code.service"; +import { PrismaModule } from "nestjs-prisma"; + +describe("AgencyCodeService", () => { + let service: AgencyCodeService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + imports: [PrismaModule], + providers: [AgencyCodeService], + }).compile(); + + service = module.get(AgencyCodeService); + }); + + it("should be defined", () => { + expect(service).toBeDefined(); + }); +}); diff --git a/backend/src/agency_code/agency_code.service.ts b/backend/src/agency_code/agency_code.service.ts new file mode 100644 index 00000000..cdffe710 --- /dev/null +++ b/backend/src/agency_code/agency_code.service.ts @@ -0,0 +1,40 @@ +import { Injectable } from "@nestjs/common"; +import { PrismaService } from "nestjs-prisma"; +import { AgencyCode } from "./entities/agency_code.entity"; + +@Injectable() +export class AgencyCodeService { + constructor(private prisma: PrismaService) {} + + async findAll() { + const prismaAgencyCodes = await this.prisma.agency_code.findMany({ + select: { + agency_code: true, + short_description: true, + long_description: true, + display_order: true, + active_ind: true, + }, + orderBy: [{ display_order: "asc" }], + }); + + const agencyCodes: AgencyCode[] = prismaAgencyCodes.map((prismaAgencyCodes) => ({ + agencyCode: prismaAgencyCodes.agency_code, + shortDescription: prismaAgencyCodes.short_description, + longDescription: prismaAgencyCodes.long_description, + displayOrder: prismaAgencyCodes.display_order, + activeIndicator: prismaAgencyCodes.active_ind, + })); + + return agencyCodes; + } + + findOne(id: string) { + return this.prisma.agency_code.findUnique({ + where: { + agency_code: id, + active_ind: true, + }, + }); + } +} diff --git a/backend/src/agency_code/entities/agency_code.entity.ts b/backend/src/agency_code/entities/agency_code.entity.ts new file mode 100644 index 00000000..29ac2844 --- /dev/null +++ b/backend/src/agency_code/entities/agency_code.entity.ts @@ -0,0 +1,7 @@ +export class AgencyCode { + agencyCode: string; + shortDescription: string; + longDescription: string; + displayOrder: number; + activeIndicator: boolean; +} diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 476b8442..20043019 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -30,6 +30,7 @@ import { NonComplianceCodeModule } from "./code-tables/non_compliance_code/non_c import { RationaleCodeModule } from "./code-tables/rationale_code/rationale_code.module"; import { SectorCodeModule } from "./code-tables/sector_code/sector_code.module"; import { CEEBDecisionActionModule } from "./ceeb_decision_action/ceeb_decision_action.module"; +import { AgencyCodeModule } from "./agency_code/agency_code.module"; @Module({ imports: [ @@ -41,6 +42,7 @@ import { CEEBDecisionActionModule } from "./ceeb_decision_action/ceeb_decision_a }), JwtAuthModule, AgeCodeModule, + AgencyCodeModule, EquipmentCodeModule, SexCodeModule, ThreatLevelCodeModule, diff --git a/backend/src/case_file/case_file.service.ts b/backend/src/case_file/case_file.service.ts index a9c9f7e0..014dbdb8 100644 --- a/backend/src/case_file/case_file.service.ts +++ b/backend/src/case_file/case_file.service.ts @@ -305,7 +305,7 @@ export class CaseFileService { discharge_code: true, rationale_code: true, inspection_number: true, - lead_agency: true, + lead_agency_code: true, non_compliance_decision_matrix_code: true, schedule_sector_xref: { select: { @@ -421,8 +421,8 @@ export class CaseFileService { if (decision[0].inspection_number) { record = { ...record, inspectionNumber: decision[0].inspection_number.toString() }; } - if (decision[0].lead_agency) { - record = { ...record, leadAgency: decision[0].lead_agency }; + if (decision[0].lead_agency_code) { + record = { ...record, leadAgency: decision[0].lead_agency_code }; } caseFile.decision = record; @@ -2495,7 +2495,7 @@ export class CaseFileService { } if (decision.leadAgency) { - record = { ...record, lead_agency: decision.leadAgency }; + record = { ...record, lead_agency_code: decision.leadAgency }; } const result = await db.decision.create({ @@ -2677,15 +2677,15 @@ export class CaseFileService { }; if (actionTaken === "FWDLEADAGN") { - data = { ...data, inspection_number: null, lead_agency: leadAgency }; + data = { ...data, inspection_number: null, lead_agency_code: leadAgency }; } if (actionTaken === "RESPREC") { - data = { ...data, lead_agency: null, inspection_number: parseInt(inspectionNumber) }; + data = { ...data, lead_agency_code: null, inspection_number: parseInt(inspectionNumber) }; } if (actionTaken !== "RESPREC" && actionTaken !== "FWDLEADAGN") { - data = { ...data, inspection_number: null, lead_agency: null }; + data = { ...data, inspection_number: null, lead_agency_code: null }; } const result = await db.decision.update({ diff --git a/migrations/sql/R__code-table-data.sql.sql b/migrations/sql/R__code-table-data.sql.sql index 0bc577f0..1359ac82 100644 --- a/migrations/sql/R__code-table-data.sql.sql +++ b/migrations/sql/R__code-table-data.sql.sql @@ -21,6 +21,262 @@ values CURRENT_TIMESTAMP ) on conflict do nothing; +-- +-- INSERT data AGENCY_CODE +-- +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'ALC', + 'Agricultural Land Commission', + 'Agricultural Land Commission', + 10, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'ENERGY', + 'BC Energy Regulator ', + 'BC Energy Regulator', + 20, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'PARKS', + 'BC Parks', + 'BC Parks', + 30, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'CEB', + 'Compliance and Enforcement Branch', + 'Compliance and Enforcement Branch', + 40, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'ECCC', + 'Environment and Climate Change Canada', + 'Environment and Climate Change Canada', + 70, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'EAO', + 'Environmental Assessment Office', + 'Environmental Assessment Office', + 80, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'FSIB', + 'Food Safety Inspection Branch', + 'Food Safety Inspection Branch', + 90, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'HEALTH', + 'Health Authority', + 'Health Authority', + 100, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'MHSED', + 'Mines Health, Safety and Enforcement Division', + 'Mines Health, Safety and Enforcement Division', + 110, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'MUNI', + 'Municipality / Regional District', + 'Municipality / Regional District', + 120, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'MOTI', + 'Transport Canada / MOTI', + 'Transport Canada / MOTI', + 130, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'OTHER', + 'Other', + 'Other', + 140, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +-- Fix display order update case_management.inaction_reason_code set display_order = 1 @@ -39,6 +295,18 @@ set where inaction_reason_code = 'OTHOPRPRTY'; +update case_management.agency_code +set + display_order = 60 +where + agency_code = 'COS'; + +update case_management.agency_code +set + display_order = 50 +where + agency_code = 'EPO'; + UPDATE case_management.configuration SET configuration_value = cast(configuration_value as INTEGER) + 1 diff --git a/migrations/sql/V1.28.0__CE-1035.sql b/migrations/sql/V1.28.0__CE-1035.sql new file mode 100644 index 00000000..e2bfd495 --- /dev/null +++ b/migrations/sql/V1.28.0__CE-1035.sql @@ -0,0 +1,6 @@ +ALTER TABLE case_management.decision +RENAME COLUMN lead_agency TO lead_agency_code; + +ALTER TABLE case_management.decision ADD CONSTRAINT FK_decision__lead_agency_code FOREIGN KEY (lead_agency_code) REFERENCES case_management.agency_code (agency_code); + +ALTER TABLE case_management.agency_code ADD display_order int4; \ No newline at end of file From e5d6b311c00fa64383f4081168392de939038500 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Tue, 24 Sep 2024 13:07:06 -0700 Subject: [PATCH 2/4] update migration script --- migrations/sql/R__code-table-data.sql.sql | 267 ---------------- .../sql/R__insert_CEEB_decision_codes.sql | 300 ++++++++++++++++-- 2 files changed, 276 insertions(+), 291 deletions(-) diff --git a/migrations/sql/R__code-table-data.sql.sql b/migrations/sql/R__code-table-data.sql.sql index 1359ac82..fe690c0f 100644 --- a/migrations/sql/R__code-table-data.sql.sql +++ b/migrations/sql/R__code-table-data.sql.sql @@ -21,261 +21,6 @@ values CURRENT_TIMESTAMP ) on conflict do nothing; --- --- INSERT data AGENCY_CODE --- -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'ALC', - 'Agricultural Land Commission', - 'Agricultural Land Commission', - 10, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'ENERGY', - 'BC Energy Regulator ', - 'BC Energy Regulator', - 20, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'PARKS', - 'BC Parks', - 'BC Parks', - 30, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'CEB', - 'Compliance and Enforcement Branch', - 'Compliance and Enforcement Branch', - 40, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'ECCC', - 'Environment and Climate Change Canada', - 'Environment and Climate Change Canada', - 70, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'EAO', - 'Environmental Assessment Office', - 'Environmental Assessment Office', - 80, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'FSIB', - 'Food Safety Inspection Branch', - 'Food Safety Inspection Branch', - 90, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'HEALTH', - 'Health Authority', - 'Health Authority', - 100, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'MHSED', - 'Mines Health, Safety and Enforcement Division', - 'Mines Health, Safety and Enforcement Division', - 110, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'MUNI', - 'Municipality / Regional District', - 'Municipality / Regional District', - 120, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'MOTI', - 'Transport Canada / MOTI', - 'Transport Canada / MOTI', - 130, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -insert into - case_management.agency_code ( - agency_code, - short_description, - long_description, - display_order, - active_ind, - create_user_id, - create_utc_timestamp - ) -values - ( - 'OTHER', - 'Other', - 'Other', - 140, - 'Y', - CURRENT_USER, - CURRENT_TIMESTAMP - ) on conflict do nothing; - -- Fix display order update case_management.inaction_reason_code set @@ -295,18 +40,6 @@ set where inaction_reason_code = 'OTHOPRPRTY'; -update case_management.agency_code -set - display_order = 60 -where - agency_code = 'COS'; - -update case_management.agency_code -set - display_order = 50 -where - agency_code = 'EPO'; - UPDATE case_management.configuration SET configuration_value = cast(configuration_value as INTEGER) + 1 diff --git a/migrations/sql/R__insert_CEEB_decision_codes.sql b/migrations/sql/R__insert_CEEB_decision_codes.sql index 3427f321..c57af358 100644 --- a/migrations/sql/R__insert_CEEB_decision_codes.sql +++ b/migrations/sql/R__insert_CEEB_decision_codes.sql @@ -1135,8 +1135,7 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT schedule_code values @@ -1197,8 +1196,7 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT new action_type_code values @@ -1220,8 +1218,7 @@ VALUES 'Y', CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT new action_code values @@ -1267,8 +1264,7 @@ VALUES 'Y', CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT new action_type_action_xref values @@ -1314,8 +1310,7 @@ VALUES 'Y', CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT non_compliance_decision_matrix_code values @@ -1409,8 +1404,7 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT rationale values @@ -1460,8 +1454,7 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- -- INSERT discharge_code values @@ -1566,35 +1559,295 @@ VALUES CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) ON CONFLICT DO NOTHING; -- --- add new EPO agency code +-- INSERT data AGENCY_CODE -- insert into case_management.agency_code ( agency_code, short_description, long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'ALC', + 'Agricultural Land Commission', + 'Agricultural Land Commission', + 10, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'ENERGY', + 'BC Energy Regulator ', + 'BC Energy Regulator', + 20, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'PARKS', + 'BC Parks', + 'BC Parks', + 30, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'CEB', + 'Compliance and Enforcement Branch', + 'Compliance and Enforcement Branch', + 40, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, active_ind, create_user_id, create_utc_timestamp, - update_user_id, - update_utc_timestamp ) values ( 'EPO', 'CEEB', 'Compliance and Environmental Enforcement Branch', - true, + 50, + 'Y', CURRENT_USER, CURRENT_TIMESTAMP, + ) ON CONFLICT DO NOTHING; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'ECCC', + 'Environment and Climate Change Canada', + 'Environment and Climate Change Canada', + 70, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'EAO', + 'Environmental Assessment Office', + 'Environmental Assessment Office', + 80, + 'Y', CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'FSIB', + 'Food Safety Inspection Branch', + 'Food Safety Inspection Branch', + 90, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'HEALTH', + 'Health Authority', + 'Health Authority', + 100, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'MHSED', + 'Mines Health, Safety and Enforcement Division', + 'Mines Health, Safety and Enforcement Division', + 110, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'MUNI', + 'Municipality / Regional District', + 'Municipality / Regional District', + 120, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'MOTI', + 'Transport Canada / MOTI', + 'Transport Canada / MOTI', + 130, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +insert into + case_management.agency_code ( + agency_code, + short_description, + long_description, + display_order, + active_ind, + create_user_id, + create_utc_timestamp + ) +values + ( + 'OTHER', + 'Other', + 'Other', + 140, + 'Y', + CURRENT_USER, + CURRENT_TIMESTAMP + ) on conflict do nothing; + +update case_management.agency_code +set + display_order = 60 +where + agency_code = 'COS'; + +update case_management.agency_code +set + display_order = 50 +where + agency_code = 'EPO'; -- -- add new ERS case_code @@ -1620,5 +1873,4 @@ values CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP - ) ON CONFLICT -DO NOTHING; \ No newline at end of file + ) ON CONFLICT DO NOTHING; \ No newline at end of file From a0ad001d6e2f1c6a2a60255809031b7fb62a9f54 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Tue, 24 Sep 2024 13:59:27 -0700 Subject: [PATCH 3/4] fix syntax --- migrations/sql/R__insert_CEEB_decision_codes.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/migrations/sql/R__insert_CEEB_decision_codes.sql b/migrations/sql/R__insert_CEEB_decision_codes.sql index c57af358..74b36d91 100644 --- a/migrations/sql/R__insert_CEEB_decision_codes.sql +++ b/migrations/sql/R__insert_CEEB_decision_codes.sql @@ -1656,7 +1656,7 @@ insert into display_order, active_ind, create_user_id, - create_utc_timestamp, + create_utc_timestamp ) values ( @@ -1666,7 +1666,7 @@ values 50, 'Y', CURRENT_USER, - CURRENT_TIMESTAMP, + CURRENT_TIMESTAMP ) ON CONFLICT DO NOTHING; insert into From 4fca626e251b915d74548611bd8a07843b0a83f6 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Wed, 25 Sep 2024 14:08:09 -0700 Subject: [PATCH 4/4] add comment column --- migrations/sql/V1.28.0__CE-1035.sql | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/migrations/sql/V1.28.0__CE-1035.sql b/migrations/sql/V1.28.0__CE-1035.sql index e2bfd495..377cea70 100644 --- a/migrations/sql/V1.28.0__CE-1035.sql +++ b/migrations/sql/V1.28.0__CE-1035.sql @@ -3,4 +3,7 @@ RENAME COLUMN lead_agency TO lead_agency_code; ALTER TABLE case_management.decision ADD CONSTRAINT FK_decision__lead_agency_code FOREIGN KEY (lead_agency_code) REFERENCES case_management.agency_code (agency_code); -ALTER TABLE case_management.agency_code ADD display_order int4; \ No newline at end of file +ALTER TABLE case_management.agency_code ADD display_order int4; + +--comment +COMMENT ON COLUMN case_management.agency_code.display_order is 'The order in which the values of the agency should be displayed when presented to a user in a list.'; \ No newline at end of file