diff --git a/db/seeds/01-regions.seed.js b/db/seeds/01-regions.seed.js index f9916fe708..9652728174 100644 --- a/db/seeds/01-regions.seed.js +++ b/db/seeds/01-regions.seed.js @@ -8,6 +8,16 @@ const RegionModel = require('../../app/models/region.model.js') const ServerConfig = require('../../config/server.config.js') +/** + * Seed the regions reference data + * + * Water.regions does not have a composite key constraint for chargeRegionId and naldRegionId. + * + * We do not want multiple occurrences of the column pair chargeRegionId and naldRegionId. + * + * We manually check if the combination exits already and update / insert accordingly. + * + */ async function seed () { for (const region of regions) { const exists = await _exists(region) diff --git a/db/seeds/02-purposes.seed.js b/db/seeds/02-purposes.seed.js index 83d52fe027..b0d0a56159 100644 --- a/db/seeds/02-purposes.seed.js +++ b/db/seeds/02-purposes.seed.js @@ -4,6 +4,16 @@ const { timestampForPostgres } = require('../../app/lib/general.lib.js') const { data: purposes } = require('./data/purposes.js') const PurposeModel = require('../../app/models/purpose.model.js') +/** + * Seeds the purposes reference data using an upsert + * + * The water.purpose_uses.legacy_id column must be unique + * + * Previous table name - water.purposes_uses + * + * Public table name - public.purposes + * + */ async function seed () { for (const purpose of purposes) { await _upsert(purpose) diff --git a/db/seeds/03-primary-purposes.seed.js b/db/seeds/03-primary-purposes.seed.js index 1968132cf5..60d7e2d722 100644 --- a/db/seeds/03-primary-purposes.seed.js +++ b/db/seeds/03-primary-purposes.seed.js @@ -4,6 +4,16 @@ const { timestampForPostgres } = require('../../app/lib/general.lib.js') const { data: primaryPurposes } = require('./data/primary-purposes.js') const PrimaryPurposeModel = require('../../app/models/primary-purpose.model.js') +/** + * Seeds the primary purpose reference data using an upsert + * + * The water.primary_purposes.legacy_id column must be unique + * + * Previous table name - water.primary_purposes + * + * Public table name - public.primary_purposes + * + */ async function seed () { for (const purpose of primaryPurposes) { await _upsert(purpose) diff --git a/db/seeds/04-secondary-purposes.seed.js b/db/seeds/04-secondary-purposes.seed.js index 0f6849691a..36f37afbab 100644 --- a/db/seeds/04-secondary-purposes.seed.js +++ b/db/seeds/04-secondary-purposes.seed.js @@ -4,6 +4,16 @@ const { timestampForPostgres } = require('../../app/lib/general.lib.js') const { data: secondaryPurposes } = require('./data/secondary-purposes.js') const SecondaryPurposeModel = require('../../app/models/secondary-purpose.model.js') +/** + * Seeds the secondary purpose reference data using an upsert + * + * The water.purposes_secondary.legacy_id column must be unique + * + * Previous table name - water.purposes_secondary + * + * Public table name - public.secondary_purposes + * + */ async function seed () { for (const purpose of secondaryPurposes) { await _upsert(purpose) diff --git a/db/seeds/05-licence-version-purpose-condition-types.seed.js b/db/seeds/05-licence-version-purpose-condition-types.seed.js index 915bd023df..bf9c2f332a 100644 --- a/db/seeds/05-licence-version-purpose-condition-types.seed.js +++ b/db/seeds/05-licence-version-purpose-condition-types.seed.js @@ -4,6 +4,16 @@ const { timestampForPostgres } = require('../../app/lib/general.lib.js') const { data: licenceVersionPurposeConditionTypes } = require('./data/licence-version-purpose-condition-types.js') const LicenceVersionPurposeConditionTypeModel = require('../../app/models/licence-version-purpose-condition-type.model.js') +/** + * Seeds the licence version purpose condition types reference data using an upsert + * + * The water.licence_version_purpose_condition_types has a unique constraint composite key for (code, subcode) + * + * Previous table name - water.licence_version_purpose_condition_types + * + * Public table name - public.licence_version_purpose_condition_types + * + */ async function seed () { for (const licenceVersionPurposeConditionType of licenceVersionPurposeConditionTypes) { await _upsert(licenceVersionPurposeConditionType)