Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure 'seeding' to be Knex based #1230

Merged
merged 103 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
2d36312
Restructure 'seeding' to be 100% knex based
Cruikshanks Aug 2, 2024
c3f6fec
Split into separate seeders starting with Regions
Cruikshanks Aug 2, 2024
f9e64d5
Move the regions data
Cruikshanks Aug 2, 2024
83887cb
Replace seeder
Cruikshanks Aug 2, 2024
7e73bfe
Update references to the old seeder
Cruikshanks Aug 2, 2024
2e60f60
Merge branch 'main' into restructure-seeders
Cruikshanks Aug 4, 2024
e6d2c56
Move purposes data
Cruikshanks Aug 5, 2024
b46b246
Replace seeder
Cruikshanks Aug 5, 2024
e9812fa
Update references to old purposes seeder
Cruikshanks Aug 5, 2024
9cce7f8
Merge branch 'main' into restructure-seeders
Cruikshanks Aug 5, 2024
84308df
Fix missed/incorrect purpose test references
Cruikshanks Aug 5, 2024
e9094be
Move primary purposes data
Cruikshanks Aug 5, 2024
bbba714
Replace primary purposes seeder
Cruikshanks Aug 5, 2024
70754e3
Update references to old primary purposes seeder
Cruikshanks Aug 5, 2024
fcb5f15
Move secondary purposes data
Cruikshanks Aug 5, 2024
7ab8204
Replace secondary purposes seeder
Cruikshanks Aug 5, 2024
3868310
Update references to old secondary purposes seeder
Cruikshanks Aug 5, 2024
b3c7a36
Move licence version purpose condition types
Cruikshanks Aug 5, 2024
973be7e
Replace licence version purpose cond. type seeder
Cruikshanks Aug 5, 2024
88ceb1a
Update references to old condition types seeder
Cruikshanks Aug 5, 2024
eef2e27
Housekeeping - rename arg
Cruikshanks Aug 5, 2024
2d83927
Remove redundant seed builder
Cruikshanks Aug 5, 2024
6b4bd27
Remove ReferenceData module
Cruikshanks Aug 5, 2024
6894517
Ensure updatedAt gets set during seeding
Cruikshanks Aug 5, 2024
00ffc72
Fix external ID in ret. req. purpose helper
Cruikshanks Aug 5, 2024
1d5b4eb
Switch to using stubs to remove region dependence
Cruikshanks Aug 6, 2024
8b65711
Add new `select()` method to region helper
Cruikshanks Aug 6, 2024
b3a4550
Switch all tests to use Region.select() not add()
Cruikshanks Aug 6, 2024
a5bac5f
Update regions.data to use select() instead
Cruikshanks Aug 6, 2024
6efbd40
Expose region data in helper
Cruikshanks Aug 6, 2024
62dee8f
Remove magic number from our tests
Cruikshanks Aug 6, 2024
ebb4b8b
Remove generateChargeRegionId from RegionHelper
Cruikshanks Aug 6, 2024
695139d
Add documentation to RegionHelper select()
Cruikshanks Aug 6, 2024
2ca95aa
Remove add from RegionHelper
Cruikshanks Aug 6, 2024
73c6e2b
Update and fix LoadService post RegionHelper change
Cruikshanks Aug 6, 2024
5f34de7
Update PurposeHelper
Cruikshanks Aug 6, 2024
e905e9b
Update Purposes.data to use select() instead
Cruikshanks Aug 6, 2024
8e7fff9
Doh! - Revert debug changes in LoadService
Cruikshanks Aug 6, 2024
72d0991
Doh! - Left a .only() in
Cruikshanks Aug 6, 2024
d6cd47e
Merge branch 'main' into restructure-seeders
Cruikshanks Aug 6, 2024
7761e8c
Remove add from PurposeHelper
Cruikshanks Aug 6, 2024
f629061
Rename const index in RegionHelper
Cruikshanks Aug 6, 2024
5a03257
Remove generateCode from PurposeHelper
Cruikshanks Aug 6, 2024
16ceb79
Update PrimaryPurposeHelper
Cruikshanks Aug 6, 2024
47eccfc
Update PrimaryPurposes.data to use select()
Cruikshanks Aug 6, 2024
a8ab472
Remove generateCode from PrimaryPurposeHelper
Cruikshanks Aug 6, 2024
de31d88
Remove add from PrimaryPurposeHelper
Cruikshanks Aug 6, 2024
0b589a0
Housekeeping - Fix module comment
Cruikshanks Aug 6, 2024
9b6f47a
Update SecondaryPurposeHelper
Cruikshanks Aug 6, 2024
366e6a5
Update SecondaryPurposes.data to use select()
Cruikshanks Aug 6, 2024
42f550b
Remove generate() from SecondaryPurposeHelper
Cruikshanks Aug 6, 2024
4f9bce5
Remove add from SecondaryPurposeHelper
Cruikshanks Aug 6, 2024
f3e356d
Update LicenceVersionPurposeConditionTypeHelper
Cruikshanks Aug 6, 2024
cb01e30
Update Lic Ver Pur Cond Type.data to use select()
Cruikshanks Aug 6, 2024
e5869a7
Remove add from Lic Ver Pur Cond Type helper
Cruikshanks Aug 6, 2024
b08b31e
Missed Lic Ver Purp Cond Types .data calls
Cruikshanks Aug 6, 2024
a2197e9
Housekeeping - Remove redundant section header
Cruikshanks Aug 6, 2024
e3a36a0
Add new Knex seed for Groups (users)
Cruikshanks Aug 6, 2024
31c149c
Include Groups in Database clean seed trigger
Cruikshanks Aug 6, 2024
dd7f487
Update GroupHelper
Cruikshanks Aug 6, 2024
621b929
Switch tests to use GroupHelper select() not add()
Cruikshanks Aug 6, 2024
30dad63
Remove add from GroupHelper
Cruikshanks Aug 6, 2024
6e0ec61
Add new Knex seed for Roles (users)
Cruikshanks Aug 6, 2024
7296fdf
Include Roles in Database clean seed trigger
Cruikshanks Aug 6, 2024
c579056
Update RoleHelper
Cruikshanks Aug 6, 2024
7003b1d
Switch tests to use RoleHelper select() not add()
Cruikshanks Aug 6, 2024
1f9fc91
Remove add from RoleHelper
Cruikshanks Aug 6, 2024
5ef0864
Fix FetchUserRolesAndGroupsService tests
Cruikshanks Aug 6, 2024
7c80ac7
Add new Knex seed for GroupRoles
Cruikshanks Aug 6, 2024
ca9c5b6
Include GroupRoles in Database clean seed trigger
Cruikshanks Aug 6, 2024
57d40bf
Update GroupRoleHelper
Cruikshanks Aug 6, 2024
f02b894
Switch tests to use GroupRoleHelper select()
Cruikshanks Aug 6, 2024
c5ea748
Remove add from GroupRoleHelper
Cruikshanks Aug 6, 2024
766f0c7
Fix - defaults was missed in RoleHelper
Cruikshanks Aug 6, 2024
b6b51b0
Replace knex seed for users
Cruikshanks Aug 7, 2024
3858ffc
Include Users in Database clean seed trigger
Cruikshanks Aug 7, 2024
b0e32d2
Update UserHelper
Cruikshanks Aug 7, 2024
2467842
Switch tests to use UserHelper select() not add()
Cruikshanks Aug 7, 2024
ed5db63
Do not remove UserHelper add
Cruikshanks Aug 7, 2024
2fdbe66
Reset Userhelper defaults() method
Cruikshanks Aug 7, 2024
98dd8e5
Add new Knex seed for UserGroups
Cruikshanks Aug 7, 2024
33163d1
Include UserGroups in Database clean seed trigger
Cruikshanks Aug 7, 2024
3328a6d
Update UserGroupHelper
Cruikshanks Aug 7, 2024
b313595
Switch tests to use UserGroupHelper select()
Cruikshanks Aug 7, 2024
b692462
Housekeeping - remove commented out code
Cruikshanks Aug 7, 2024
c51af8c
Update GroupRoles seeder to match UserGroups
Cruikshanks Aug 7, 2024
b866fa1
Rename (re-index) seed files
Cruikshanks Aug 7, 2024
b722b51
Need DEFAULT_USER_PASSWORD in CI
Cruikshanks Aug 7, 2024
287dce6
Merge remote-tracking branch 'origin/main' into restructure-seeders
Cruikshanks Aug 7, 2024
8f0bf2a
Merge branch 'main' into restructure-seeders
Cruikshanks Aug 7, 2024
f98dfad
Don't seed users & their groups in production
Cruikshanks Aug 7, 2024
6053535
Attempt tp avoid collisions in IDM testing
Cruikshanks Aug 7, 2024
5025916
Add new Knex seed for financial agreements
Cruikshanks Aug 7, 2024
7247b54
Include FinancialAgreements in DB clean seed trigger
Cruikshanks Aug 7, 2024
5004438
Update FinancialAgreementHelper
Cruikshanks Aug 7, 2024
ece6226
Switch tests to use FinancialAgreementHelper select()
Cruikshanks Aug 7, 2024
c96b1a8
Remove add from FinancialAgreementHelper
Cruikshanks Aug 7, 2024
9b3a46c
Remove generateCode from FinancialAgreementHelper
Cruikshanks Aug 7, 2024
f385ccb
Remove defaults() from reference-only helpers
Cruikshanks Aug 7, 2024
0fef3ac
Access the reference data in a consistent manner
Cruikshanks Aug 7, 2024
0acf3f6
Fix broken test
Cruikshanks Aug 7, 2024
64494a4
Added a README to the seeds folder
Cruikshanks Aug 7, 2024
295e7fc
Stop Test Region from being seeded in production
Cruikshanks Aug 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ jobs:
POSTGRES_DB_TEST: wabs_system_test
ENVIRONMENT: dev
COOKIE_SECRET: 1a1028df-a2af-468a-929b-e3a274be1208
DEFAULT_USER_PASSWORD: P@55word

# Service containers to run with `runner-job`
services:
Expand Down
12 changes: 0 additions & 12 deletions app/services/data/load/load.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const ContactHelper = require('../../../../test/support/helpers/contact.helper.j
const EventHelper = require('../../../../test/support/helpers/event.helper.js')
const FinancialAgreementHelper = require('../../../../test/support/helpers/financial-agreement.helper.js')
const GaugingStationHelper = require('../../../../test/support/helpers/gauging-station.helper.js')
const GroupRoleHelper = require('../../../../test/support/helpers/group-role.helper.js')
const GroupHelper = require('../../../../test/support/helpers/group.helper.js')
const LicenceAgreementHelper = require('../../../../test/support/helpers/licence-agreement.helper.js')
const LicenceDocumentHeaderHelper = require('../../../../test/support/helpers/licence-document-header.helper.js')
const LicenceDocumentRoleHelper = require('../../../../test/support/helpers/licence-document-role.helper.js')
Expand All @@ -40,14 +38,11 @@ const LicenceEntityHelper = require('../../../../test/support/helpers/licence-en
const LicenceGaugingStationHelper = require('../../../../test/support/helpers/licence-gauging-station.helper.js')
const LicenceRoleHelper = require('../../../../test/support/helpers/licence-role.helper.js')
const LicenceSupplementaryYearHelper = require('../../../../test/support/helpers/licence-supplementary-year.helper.js')
const LicenceVersionPurposeConditionTypeHelper = require('../../../../test/support/helpers/licence-version-purpose-condition-type.helper.js')
const LicenceVersionPurposeConditionHelper = require('../../../../test/support/helpers/licence-version-purpose-condition.helper.js')
const LicenceVersionPurposeHelper = require('../../../../test/support/helpers/licence-version-purpose.helper.js')
const LicenceVersionHelper = require('../../../../test/support/helpers/licence-version.helper.js')
const LicenceHelper = require('../../../../test/support/helpers/licence.helper.js')
const PermitLicenceHelper = require('../../../../test/support/helpers/permit-licence.helper.js')
const PurposeHelper = require('../../../../test/support/helpers/purpose.helper.js')
const RegionHelper = require('../../../../test/support/helpers/region.helper.js')
const ReturnLogHelper = require('../../../../test/support/helpers/return-log.helper.js')
const ReturnRequirementPointHelper = require('../../../../test/support/helpers/return-requirement-point.helper.js')
const ReturnRequirementPurposeHelper = require('../../../../test/support/helpers/return-requirement-purpose.helper.js')
Expand All @@ -61,7 +56,6 @@ const ReviewChargeReferenceHelper = require('../../../../test/support/helpers/re
const ReviewChargeVersionHelper = require('../../../../test/support/helpers/review-charge-version.helper.js')
const ReviewLicenceHelper = require('../../../../test/support/helpers/review-licence.helper.js')
const ReviewReturnHelper = require('../../../../test/support/helpers/review-return.helper.js')
const RoleHelper = require('../../../../test/support/helpers/role.helper.js')
const ScheduledNotificationHelper = require('../../../../test/support/helpers/scheduled-notification.helper.js')
const SessionHelper = require('../../../../test/support/helpers/session.helper.js')
const TransactionHelper = require('../../../../test/support/helpers/transaction.helper.js')
Expand Down Expand Up @@ -94,8 +88,6 @@ const LOAD_HELPERS = {
events: { helper: EventHelper, test: false },
financialAgreements: { helper: FinancialAgreementHelper, test: true, legacy: { schema: 'water', table: 'financial_agreement_types', id: 'financial_agreement_type_id' } },
gaugingStations: { helper: GaugingStationHelper, test: true, legacy: { schema: 'water', table: 'gauging_stations', id: 'gauging_station_id' } },
groupRoles: { helper: GroupRoleHelper, test: false },
groups: { helper: GroupHelper, test: false },
licenceAgreements: { helper: LicenceAgreementHelper, test: true, legacy: { schema: 'water', table: 'licence_agreements', id: 'licence_agreement_id' } },
licenceDocumentHeaders: { helper: LicenceDocumentHeaderHelper, test: false },
licenceDocumentRoles: { helper: LicenceDocumentRoleHelper, test: true, legacy: { schema: 'crm_v2', table: 'document_roles', id: 'document_role_id' } },
Expand All @@ -105,14 +97,11 @@ const LOAD_HELPERS = {
licenceGaugingStations: { helper: LicenceGaugingStationHelper, test: true, legacy: { schema: 'water', table: 'licence_gauging_stations', id: 'licence_gauging_station_id' } },
licenceRoles: { helper: LicenceRoleHelper, test: false },
LicenceSupplementaryYears: { helper: LicenceSupplementaryYearHelper, test: false },
licenceVersionPurposeConditionTypes: { helper: LicenceVersionPurposeConditionTypeHelper, test: false },
licenceVersionPurposeConditions: { helper: LicenceVersionPurposeConditionHelper, test: false },
licenceVersionPurposes: { helper: LicenceVersionPurposeHelper, test: true, legacy: { schema: 'water', table: 'licence_version_purposes', id: 'licence_version_purpose_id' } },
licenceVersions: { helper: LicenceVersionHelper, test: true, legacy: { schema: 'water', table: 'licence_versions', id: 'licence_version_id' } },
licences: { helper: LicenceHelper, test: true, legacy: { schema: 'water', table: 'licences', id: 'licence_id' } },
permitLicences: { helper: PermitLicenceHelper, test: false },
purposes: { helper: PurposeHelper, test: true, legacy: { schema: 'water', table: 'purposes_uses', id: 'purpose_use_id' } },
regions: { helper: RegionHelper, test: true, legacy: { schema: 'water', table: 'regions', id: 'region_id' } },
returnLogs: { helper: ReturnLogHelper, test: true, legacy: { schema: 'returns', table: 'returns', id: 'return_id' } },
returnRequirementPoints: { helper: ReturnRequirementPointHelper, test: false },
returnRequirementPurposes: { helper: ReturnRequirementPurposeHelper, test: false },
Expand All @@ -126,7 +115,6 @@ const LOAD_HELPERS = {
reviewChargeVersions: { helper: ReviewChargeVersionHelper, test: false },
reviewLicences: { helper: ReviewLicenceHelper, test: false },
reviewReturns: { helper: ReviewReturnHelper, test: false },
roles: { helper: RoleHelper, test: false },
scheduledNotifications: { helper: ScheduledNotificationHelper },
sessions: { helper: SessionHelper, test: false },
transactions: { helper: TransactionHelper, test: false },
Expand Down
59 changes: 59 additions & 0 deletions db/seeds/01-regions.seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
'use strict'

const { db } = require('../db.js')

const { timestampForPostgres } = require('../../app/lib/general.lib.js')
const Regions = require('./data/regions.js')
const RegionModel = require('../../app/models/region.model.js')

async function seed () {
for (const region of Regions.data) {
const exists = await _exists(region)

if (exists) {
await _update(region)
} else {
await _insert(region)
}
}
}

async function _applyTestFlag (region, id) {
if (region.name !== 'Test') {
return null
}

return db('regions').withSchema('water').update('isTest', true).where('regionId', id)
}

async function _exists (region) {
const { chargeRegionId, naldRegionId } = region

const result = await RegionModel.query()
.select('id')
.where('chargeRegionId', chargeRegionId)
.andWhere('naldRegionId', naldRegionId)
.limit(1)
.first()

return !!result
}

async function _insert (region) {
const result = await RegionModel.query().insert(region)

return _applyTestFlag(region, result.id)
}

async function _update (region) {
const { chargeRegionId, displayName, naldRegionId, name } = region

return RegionModel.query()
.patch({ displayName, name, updatedAt: timestampForPostgres() })
.where('chargeRegionId', chargeRegionId)
.andWhere('naldRegionId', naldRegionId)
}

module.exports = {
seed
}
159 changes: 0 additions & 159 deletions db/seeds/01-users.js

This file was deleted.

22 changes: 22 additions & 0 deletions db/seeds/02-purposes.seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const { timestampForPostgres } = require('../../app/lib/general.lib.js')
const Purposes = require('./data/purposes.js')
const PurposeModel = require('../../app/models/purpose.model.js')

async function seed () {
for (const purpose of Purposes.data) {
await _upsert(purpose)
}
}

async function _upsert (purpose) {
return PurposeModel.query()
.insert({ ...purpose, updatedAt: timestampForPostgres() })
.onConflict('legacyId')
.merge(['description', 'lossFactor', 'twoPartTariff', 'updatedAt'])
}

module.exports = {
seed
}
22 changes: 22 additions & 0 deletions db/seeds/03-primary-purposes.seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const { timestampForPostgres } = require('../../app/lib/general.lib.js')
const PrimaryPurposes = require('./data/primary-purposes.js')
const PrimaryPurposeModel = require('../../app/models/primary-purpose.model.js')

async function seed () {
for (const purpose of PrimaryPurposes.data) {
await _upsert(purpose)
}
}

async function _upsert (primaryPurpose) {
return PrimaryPurposeModel.query()
.insert({ ...primaryPurpose, updatedAt: timestampForPostgres() })
.onConflict('legacyId')
.merge(['description', 'updatedAt'])
}

module.exports = {
seed
}
22 changes: 22 additions & 0 deletions db/seeds/04-secondary-purposes.seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const { timestampForPostgres } = require('../../app/lib/general.lib.js')
const SecondaryPurposes = require('./data/secondary-purposes.js')
const SecondaryPurposeModel = require('../../app/models/secondary-purpose.model.js')

async function seed () {
for (const purpose of SecondaryPurposes.data) {
await _upsert(purpose)
}
}

async function _upsert (secondaryPurpose) {
return SecondaryPurposeModel.query()
.insert({ ...secondaryPurpose, updatedAt: timestampForPostgres() })
.onConflict('legacyId')
.merge(['description', 'updatedAt'])
}

module.exports = {
seed
}
22 changes: 22 additions & 0 deletions db/seeds/05-licence-version-purpose-condition-types.seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict'

const { timestampForPostgres } = require('../../app/lib/general.lib.js')
const LicenceVersionPurposeConditionTypes = require('./data/licence-version-purpose-condition-types.js')
const LicenceVersionPurposeConditionTypeModel = require('../../app/models/licence-version-purpose-condition-type.model.js')

async function seed () {
for (const purpose of LicenceVersionPurposeConditionTypes.data) {
await _upsert(purpose)
}
}

async function _upsert (licenceVersionPurposeConditionType) {
return LicenceVersionPurposeConditionTypeModel.query()
.insert({ ...licenceVersionPurposeConditionType, updatedAt: timestampForPostgres() })
.onConflict(['code', 'subcode'])
.merge(['description', 'displayTitle', 'subcodeDescription', 'updatedAt'])
}

module.exports = {
seed
}
Loading
Loading