diff --git a/database/exip.sql b/database/exip.sql index 91105f45a0..f3bf695d05 100644 --- a/database/exip.sql +++ b/database/exip.sql @@ -646,9 +646,9 @@ DROP TABLE IF EXISTS `DeclarationModernSlaveryVersion`; CREATE TABLE `DeclarationModernSlaveryVersion` ( `id` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, `declarationModernSlavery` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, - `hasNoOffensesOrInvestigations` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', - `isNotAwareOfExistingSlavery` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', - `willAdhereToAllRequirements` varchar(3) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', + `hasNoOffensesOrInvestigations` tinyint(1) DEFAULT NULL, + `isNotAwareOfExistingSlavery` tinyint(1) DEFAULT NULL, + `willAdhereToAllRequirements` tinyint(1) DEFAULT NULL, PRIMARY KEY (`id`), KEY `DeclarationModernSlaveryVersion_declarationModernSlavery_idx` (`declarationModernSlavery`), CONSTRAINT `DeclarationModernSlaveryVersion_declarationModernSlavery_fkey` FOREIGN KEY (`declarationModernSlavery`) REFERENCES `DeclarationModernSlavery` (`id`) ON DELETE diff --git a/src/api/data-migration/version-1-to-version-2/create-cuid/index.ts b/src/api/data-migration/helpers/create-cuid/index.ts similarity index 100% rename from src/api/data-migration/version-1-to-version-2/create-cuid/index.ts rename to src/api/data-migration/helpers/create-cuid/index.ts diff --git a/src/api/data-migration/helpers/get-all-declaration-modern-slaveries.ts b/src/api/data-migration/helpers/get-all-declaration-modern-slaveries.ts new file mode 100644 index 0000000000..fc09af4d24 --- /dev/null +++ b/src/api/data-migration/helpers/get-all-declaration-modern-slaveries.ts @@ -0,0 +1,27 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../execute-sql-query'; +import { ApplicationDeclarationModernSlavery } from '../../types'; + +/** + * getAllDeclarationModernSlaveries + * Get all entries in the "DeclarationModernSlavery" table + * @param {Connection} connection: SQL database connection + * @returns {Promise>} + */ +const getAllDeclarationModernSlaveries = async (connection: Connection) => { + const loggingMessage = 'Getting all declaration modern slaveries'; + + try { + const query = 'SELECT * FROM DeclarationModernSlavery'; + + const [declarations] = await executeSqlQuery({ connection, query, loggingMessage }); + + return declarations as Array; + } catch (error) { + console.error('🚨 Error %s %o', loggingMessage, error); + + throw new Error(`🚨 error ${loggingMessage} ${error}`); + } +}; + +export default getAllDeclarationModernSlaveries; diff --git a/src/api/data-migration/helpers/get-all-declarations.ts b/src/api/data-migration/helpers/get-all-declarations.ts new file mode 100644 index 0000000000..9c8ae0d648 --- /dev/null +++ b/src/api/data-migration/helpers/get-all-declarations.ts @@ -0,0 +1,27 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../execute-sql-query'; +import { ApplicationDeclaration } from '../../types'; + +/** + * getAllDeclarations + * Get all entries in the "Declaration" table + * @param {Connection} connection: SQL database connection + * @returns {Promise>} + */ +const getAllDeclarations = async (connection: Connection) => { + const loggingMessage = 'Getting all declarations'; + + try { + const query = 'SELECT * FROM Application'; + + const [declarations] = await executeSqlQuery({ connection, query, loggingMessage }); + + return declarations as Array; + } catch (error) { + console.error('🚨 Error %s %o', loggingMessage, error); + + throw new Error(`🚨 error ${loggingMessage} ${error}`); + } +}; + +export default getAllDeclarations; diff --git a/src/api/data-migration/version-1-to-version-2/get-all-non-submitted-applications.ts b/src/api/data-migration/helpers/get-all-non-submitted-applications.ts similarity index 93% rename from src/api/data-migration/version-1-to-version-2/get-all-non-submitted-applications.ts rename to src/api/data-migration/helpers/get-all-non-submitted-applications.ts index d2e72fc803..035b02e8b8 100644 --- a/src/api/data-migration/version-1-to-version-2/get-all-non-submitted-applications.ts +++ b/src/api/data-migration/helpers/get-all-non-submitted-applications.ts @@ -9,7 +9,7 @@ const { STATUS } = APPLICATION; * getAllNonSubmittedApplications * Get all entries in the "Application" table that do NOT have a SUBMITTED status * @param {Connection} connection: SQL database connection - * @returns {Promise} Non-submitted applications + * @returns {Promise>} Non-submitted applications */ const getAllNonSubmittedApplications = async (connection: Connection) => { const loggingMessage = 'Getting all non-submitted applications'; diff --git a/src/api/data-migration/version-1-to-version-2/get-all-submitted-applications.ts b/src/api/data-migration/helpers/get-all-submitted-applications.ts similarity index 93% rename from src/api/data-migration/version-1-to-version-2/get-all-submitted-applications.ts rename to src/api/data-migration/helpers/get-all-submitted-applications.ts index 7c1dddcc93..e7efde6495 100644 --- a/src/api/data-migration/version-1-to-version-2/get-all-submitted-applications.ts +++ b/src/api/data-migration/helpers/get-all-submitted-applications.ts @@ -9,7 +9,7 @@ const { STATUS } = APPLICATION; * getAllSubmittedApplications * Get all entries in the "Application" table with a SUBMITTED status * @param {Connection} connection: SQL database connection - * @returns {Promise} Submitted applications + * @returns {Promise>} Submitted applications */ const getAllSubmittedApplications = async (connection: Connection) => { const loggingMessage = 'Getting all submitted applications'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/create-company-different-trading-address.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/create-company-different-trading-address.ts index 2fd6949f7d..7f87bc19b3 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/create-company-different-trading-address.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/create-company-different-trading-address.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../create-cuid'; +import createCuid from '../../helpers/create-cuid'; import executeSqlQuery from '../../execute-sql-query'; import { Application } from '../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/declaration-version-relationship/non-submitted-applications.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/declaration-version-relationship/non-submitted-applications.ts index c2c6c9c935..3c1977097a 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/declaration-version-relationship/non-submitted-applications.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/declaration-version-relationship/non-submitted-applications.ts @@ -1,7 +1,7 @@ import { Connection } from 'mysql2/promise'; import { DECLARATIONS } from '../../../../constants'; -import getAllNonSubmittedApplications from '../../get-all-non-submitted-applications'; -import createCuid from '../../create-cuid'; +import getAllNonSubmittedApplications from '../../../helpers/get-all-non-submitted-applications'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; import { Application } from '../../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/declaration-version-relationship/submitted-applications.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/declaration-version-relationship/submitted-applications.ts index e3d574c6ff..b6fbad8ff8 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/declaration-version-relationship/submitted-applications.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/declaration-version-relationship/submitted-applications.ts @@ -1,7 +1,7 @@ import { Connection } from 'mysql2/promise'; import { DECLARATIONS } from '../../../../constants'; -import getAllSubmittedApplications from '../../get-all-submitted-applications'; -import createCuid from '../../create-cuid'; +import getAllSubmittedApplications from '../../../helpers/get-all-submitted-applications'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; import { Application } from '../../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-agent-service-charges.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-agent-service-charges.ts index 68756c31df..1caae17be2 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-agent-service-charges.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-agent-service-charges.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../../create-cuid'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; import { Application } from '../../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-agent-services.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-agent-services.ts index ed6857a788..d9c2f8de18 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-agent-services.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-agent-services.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../../create-cuid'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; import { Application } from '../../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-initial-agents.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-initial-agents.ts index a07af72e67..a48ee415fd 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-initial-agents.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/export-contract-agent/create-initial-agents.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../../create-cuid'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; import { Application } from '../../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/jointly-insured-party.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/jointly-insured-party.ts index 959362d4a3..a8b99329f2 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/jointly-insured-party.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/jointly-insured-party.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../create-cuid'; +import createCuid from '../../helpers/create-cuid'; import executeSqlQuery from '../../execute-sql-query'; import { Application } from '../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-initial-loss-payees.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-initial-loss-payees.ts index e1e3924d6d..01136c23d5 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-initial-loss-payees.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-initial-loss-payees.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../../create-cuid'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; import { Application } from '../../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-international-vector.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-international-vector.ts index 9aac8af0b3..954a136ae1 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-international-vector.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-international-vector.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../../create-cuid'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; import { Application } from '../../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-international.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-international.ts index 90727b0580..2eec303f4c 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-international.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-international.ts @@ -1,6 +1,6 @@ import { Connection } from 'mysql2/promise'; import getAllLossPayees from '../../get-all-loss-payees'; -import createCuid from '../../create-cuid'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; /** diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-uk-vector.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-uk-vector.ts index 35387f2dcd..559bd6fe7f 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-uk-vector.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-uk-vector.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../../create-cuid'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; import { Application } from '../../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-uk.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-uk.ts index 54ea6a7be8..9bcc926565 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-uk.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/loss-payee/create-loss-payee-financial-uk.ts @@ -1,6 +1,6 @@ import { Connection } from 'mysql2/promise'; import getAllLossPayees from '../../get-all-loss-payees'; -import createCuid from '../../create-cuid'; +import createCuid from '../../../helpers/create-cuid'; import executeSqlQuery from '../../../execute-sql-query'; /** diff --git a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/private-market.ts b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/private-market.ts index adc6306927..f806b18436 100644 --- a/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/private-market.ts +++ b/src/api/data-migration/version-1-to-version-2/create-new-application-relationships/private-market.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../create-cuid'; +import createCuid from '../../helpers/create-cuid'; import executeSqlQuery from '../../execute-sql-query'; import { Application } from '../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-contact-fields.ts b/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-contact-fields.ts index d526ee1dd8..e95a20b2db 100644 --- a/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-contact-fields.ts +++ b/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-contact-fields.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../create-cuid'; +import createCuid from '../../helpers/create-cuid'; import executeSqlQuery from '../../execute-sql-query'; import { ApplicationBuyerMvp } from '../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-relationship-fields.ts b/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-relationship-fields.ts index a4b926cc6e..4ce7d74215 100644 --- a/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-relationship-fields.ts +++ b/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-relationship-fields.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../create-cuid'; +import createCuid from '../../helpers/create-cuid'; import executeSqlQuery from '../../execute-sql-query'; import { ApplicationBuyerMvp } from '../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-trading-history-fields.ts b/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-trading-history-fields.ts index ff0bf90717..01c4942906 100644 --- a/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-trading-history-fields.ts +++ b/src/api/data-migration/version-1-to-version-2/update-applications/move-buyer-trading-history-fields.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import createCuid from '../create-cuid'; +import createCuid from '../../helpers/create-cuid'; import executeSqlQuery from '../../execute-sql-query'; import { ApplicationBuyerMvp } from '../../../types'; diff --git a/src/api/data-migration/version-1-to-version-2/update-applications/update-declaration-fields.ts b/src/api/data-migration/version-1-to-version-2/update-applications/update-declaration-fields.ts index 6cb8b5c644..6563f9cde0 100644 --- a/src/api/data-migration/version-1-to-version-2/update-applications/update-declaration-fields.ts +++ b/src/api/data-migration/version-1-to-version-2/update-applications/update-declaration-fields.ts @@ -1,5 +1,5 @@ import { Connection } from 'mysql2/promise'; -import getAllNonSubmittedApplications from '../get-all-non-submitted-applications'; +import getAllNonSubmittedApplications from '../../helpers/get-all-non-submitted-applications'; import executeSqlQuery from '../../execute-sql-query'; import { Application } from '../../../types'; diff --git a/src/api/data-migration/version-2-to-version-3/index.ts b/src/api/data-migration/version-2-to-version-3/index.ts index 6b0942f349..60680e59b2 100644 --- a/src/api/data-migration/version-2-to-version-3/index.ts +++ b/src/api/data-migration/version-2-to-version-3/index.ts @@ -3,8 +3,8 @@ import updateApplications from './update-applications'; /** * dataMigration - * Update all accounts and applications from the MVP data model/structure, - * to the new "No PDF" data model/structure. + * Update all applications from the V2 data model/structure, + * to the V3 data model/structure. * @returns {Function} process.exit() */ const dataMigration = async () => { diff --git a/src/api/data-migration/version-2-to-version-3/update-applications/index.ts b/src/api/data-migration/version-2-to-version-3/update-applications/index.ts index cd207a1fd2..6753529f72 100644 --- a/src/api/data-migration/version-2-to-version-3/update-applications/index.ts +++ b/src/api/data-migration/version-2-to-version-3/update-applications/index.ts @@ -7,7 +7,7 @@ import updateApplicationMigrated from './update-application-migrated'; /** * updateApplications - * Update applications from the "No PDF" data model/structure, to the new "No PDF iterations" data model/structure. + * Update applications from the V2 data model/structure, to the V3 data model/structure. * @param {Connection} connection: SQL database connection * @returns {Promise>} executeSqlQuery responses */ diff --git a/src/api/data-migration/version-3-to-version-4/README.md b/src/api/data-migration/version-3-to-version-4/README.md new file mode 100644 index 0000000000..6d98c954e6 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/README.md @@ -0,0 +1,58 @@ +# EXIP API - data migration - version 2 to version 3 :file_folder: + +This directory contains source code for migrating version 2 of EXIP data into the version 3 data structure. + +- Version 1 is MVP. This is the first release with account and application functionalities. +- Version 2 is "No PDF". This is a large iteration of MVP, where we allow more applications through and collect more information, depending on answers a user provides. +- Version 3 is a small iteration of "No PDF". This is mostly design and content improvements, however 1x field has been added to the database. + +## In version 3, the following data has been added + +- `Policy` table - 1x new field - `requestedCreditLimit`. + +## Prerequisites :gear: + +To set up and run the API locally to test this data migration, you'll need the following prerequisites: + +- Node.js version 16.17.0 or higher along with the corresponding `npm` package manager. +- A MySQL database with the version 2 (No PDF) data structure. +- An operational API (parent directory - see the API's README). +- The `DATABASE_URL` environment variable should be configured to point to your local MySQL database, for example: `mysql://root:@localhost:1234/db-name`. +- The local `DATABASE_USER` environment variable +- The local `DATABASE_PASSWORD` environment variable +- The local `CUID_FINGERPRINT` environment variable +- `mysql2` NPM package installed as an API dependency. +- `ts-node` NPM package installed locally. + +## Running Locally :computer: + +1. Ensure that your database has the version 2 (No PDF) data structure. +2. In the API directory, execute `npm run data-migration`. + +The migration should successfully do the following: + +1. Connect to the database. +2. Remove the application `migratedV1toV2` field. +3. Create a new application `migratedV2toV3` field. +4. Create a new requestedCreditLimit field in the policy table. +5. Update the application version number. +6. Update the new application `migratedV2toV3` field. + +## How to ensure that data migration was successful + +1. All applications should be aligned with the version 3 data model (listed above) +2. In the UI, all existing applications with a status of "in progress" can be progressed and successfully submitted. + +## What happens to applications that are in progress :microscope: + +Due to the nature of GraphQL and KeystoneJS - the version 2 and version 3 data models are essentially "out of sync". + +If we try to run the version 3 API, with version 2 data, things will not work. + +Similarly, if we migrate the database and the API is running on version 3 - any applications created with the version 2 data model need to be migrated to the new version 3 model - hence why we need migration logic. + +This means that if a user has completed e.g all questions in an application, but has not yet submitted - and then we migrate to version 3, the user's application will be migrated from version 2 ("No PDF") to version 3 ("No PDF iterations"). Because this migration is minimal, only one section will be marked as incomplete - the "Policy" section. Because the `requestedCreditLimit` field is now required as part of version 3 ("No PDF interations). + +This is an intentional behaviour, so that a user can continue to complete and submit an application. The alternative to this is to ask a user to start again, which is not recommended. + +If you have any specific questions or need further guidance related to this data migration or the API, please feel free to ask. diff --git a/src/api/data-migration/version-3-to-version-4/index.ts b/src/api/data-migration/version-3-to-version-4/index.ts new file mode 100644 index 0000000000..cee97c5f77 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/index.ts @@ -0,0 +1,30 @@ +import connectToDatabase from '../connect-to-database'; +import updateApplications from './update-applications'; + +/** + * dataMigration + * Update all applications from the V3 data model/structure, + * to the V4 data model/structure. + * @returns {Function} process.exit() + */ +const dataMigration = async () => { + try { + console.info('🚀 Beginning data migration (v3 to v4)'); + + const connection = await connectToDatabase(); + + await updateApplications(connection); + + console.info('✅ Applications successfully updated'); + + console.info('🎉 Migration complete. Exiting script'); + + process.exit(); + } catch (error) { + console.error('🚨 Error with data migration %o', error); + + throw new Error(`🚨 Error with data migration ${error}`); + } +}; + +dataMigration(); diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/add-application-migrated-v3-to-v4-field.ts b/src/api/data-migration/version-3-to-version-4/update-applications/add-application-migrated-v3-to-v4-field.ts new file mode 100644 index 0000000000..3b30e0603b --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/add-application-migrated-v3-to-v4-field.ts @@ -0,0 +1,18 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../../execute-sql-query'; + +/** + * addMigratedV3toV4Field + * Add a migratedV3toV4 field to the application table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const addMigratedV3toV4Field = (connection: Connection) => { + const loggingMessage = 'Adding FIELD migratedV3toV4 to application table'; + + const query = `ALTER TABLE Application ADD migratedV3toV4 tinyint(1) DEFAULT NULL`; + + return executeSqlQuery({ connection, query, loggingMessage }); +}; + +export default addMigratedV3toV4Field; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/create-declaration-modern-slavery-table.ts b/src/api/data-migration/version-3-to-version-4/update-applications/create-declaration-modern-slavery-table.ts new file mode 100644 index 0000000000..ed8da8bcd0 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/create-declaration-modern-slavery-table.ts @@ -0,0 +1,28 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../../execute-sql-query'; + +/** + * createDeclarationModernSlaveryTable + * Create new "declaration modern slavery" database table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const createDeclarationModernSlaveryTable = (connection: Connection) => { + const loggingMessage = 'Creating TABLE - declaration modern slavery'; + + const query = ` + CREATE TABLE DeclarationModernSlavery ( + id varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, + declaration varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + version varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + willAdhereToAllRequirements tinyint(1) DEFAULT NULL, + hasNoOffensesOrInvestigations tinyint(1) DEFAULT NULL, + isNotAwareOfExistingSlavery tinyint(1) DEFAULT NULL, + PRIMARY KEY (id) + ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci; + `; + + return executeSqlQuery({ connection, query, loggingMessage }); +}; + +export default createDeclarationModernSlaveryTable; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/create-declaration-modern-slavery-version-table.ts b/src/api/data-migration/version-3-to-version-4/update-applications/create-declaration-modern-slavery-version-table.ts new file mode 100644 index 0000000000..7c834bc499 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/create-declaration-modern-slavery-version-table.ts @@ -0,0 +1,27 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../../execute-sql-query'; + +/** + * createDeclarationModernSlaveryVersionTable + * Create new "declaration modern slavery version" database table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const createDeclarationModernSlaveryVersionTable = (connection: Connection) => { + const loggingMessage = 'Creating TABLE - declaration modern slavery version'; + + const query = ` + CREATE TABLE DeclarationModernSlaveryVersion ( + id varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL, + declarationModernSlavery varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + hasNoOffensesOrInvestigations tinyint(1) DEFAULT NULL, + isNotAwareOfExistingSlavery tinyint(1) DEFAULT NULL, + willAdhereToAllRequirements tinyint(1) DEFAULT NULL, + PRIMARY KEY (id) + ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci; + `; + + return executeSqlQuery({ connection, query, loggingMessage }); +}; + +export default createDeclarationModernSlaveryVersionTable; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/index.ts b/src/api/data-migration/version-3-to-version-4/update-applications/index.ts new file mode 100644 index 0000000000..705af38cd1 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/index.ts @@ -0,0 +1,41 @@ +import { Connection } from 'mysql2/promise'; +import removeMigratedV2toV3Field from './remove-application-migrated-v2-to-v3-field'; +import addMigratedV3toV4Field from './add-application-migrated-v3-to-v4-field'; +import createDeclarationModernSlaveryTable from './create-declaration-modern-slavery-table'; +import createDeclarationModernSlaveryVersionTable from './create-declaration-modern-slavery-version-table'; +import updateDeclarations from './update-declarations'; +import updateApplicationMigrated from './update-application-migrated'; + +/** + * updateApplications + * Update applications from the V3 data model/structure, to the V4 data model/structure. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery responses + */ +const updateApplications = async (connection: Connection) => { + const loggingMessage = 'Updating applications'; + + console.info('✅ %s', loggingMessage); + + try { + const promises = await Promise.all([ + removeMigratedV2toV3Field(connection), + addMigratedV3toV4Field(connection), + + createDeclarationModernSlaveryTable(connection), + createDeclarationModernSlaveryVersionTable(connection), + + updateDeclarations(connection), + + updateApplicationMigrated(connection), + ]); + + return promises; + } catch (error) { + console.error('🚨 Error %s %o', loggingMessage, error); + + throw new Error(`🚨 error ${loggingMessage} ${error}`); + } +}; + +export default updateApplications; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/remove-application-migrated-v2-to-v3-field.ts b/src/api/data-migration/version-3-to-version-4/update-applications/remove-application-migrated-v2-to-v3-field.ts new file mode 100644 index 0000000000..fc6b565330 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/remove-application-migrated-v2-to-v3-field.ts @@ -0,0 +1,20 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../../execute-sql-query'; + +/** + * removeMigratedV2toV3Field + * Remove the migratedV2toV3 field from the application table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const removeMigratedV2toV3Field = (connection: Connection) => { + const loggingMessage = 'Removing FIELD migratedV2toV3 from application table'; + + const query = ` + ALTER TABLE Application DROP COLUMN migratedV2toV3 + `; + + return executeSqlQuery({ connection, query, loggingMessage }); +}; + +export default removeMigratedV2toV3Field; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-application-migrated.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-application-migrated.ts new file mode 100644 index 0000000000..650304221e --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-application-migrated.ts @@ -0,0 +1,23 @@ +import { Connection } from 'mysql2/promise'; +import { APPLICATION } from '../../../constants'; +import executeSqlQuery from '../../execute-sql-query'; + +const { STATUS } = APPLICATION; + +/** + * updateApplicationMigrated + * Update IN_PROGRESS applications migratedV3toV4 fields to have a value of 1/true + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const updateApplicationMigrated = (connection: Connection) => { + const loggingMessage = `Updating migratedV3toV4 FIELD to true in the application table`; + + const query = ` + UPDATE Application SET migratedV3toV4 = 1 WHERE status = '${STATUS.IN_PROGRESS}' + `; + + return executeSqlQuery({ connection, query, loggingMessage }); +}; + +export default updateApplicationMigrated; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-application-version.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-application-version.ts new file mode 100644 index 0000000000..8650ce72fb --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-application-version.ts @@ -0,0 +1,25 @@ +import { Connection } from 'mysql2/promise'; +import { APPLICATION } from '../../../constants'; +import executeSqlQuery from '../../execute-sql-query'; + +const { STATUS, LATEST_VERSION_NUMBER, VERSIONS } = APPLICATION; + +/** + * updateApplicationVersion + * Update IN_PROGRESS applications from the No PDF version (2), to the new "No PDF iterations" version (3) + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const updateApplicationVersion = (connection: Connection) => { + const originalVersionNumber = VERSIONS[1].VERSION_NUMBER; + + const loggingMessage = `Updating IN_PROGRESS FIELD VERSION from ${originalVersionNumber} to ${LATEST_VERSION_NUMBER} in the application table`; + + const query = ` + UPDATE Application SET version = '${LATEST_VERSION_NUMBER}' WHERE status = '${STATUS.IN_PROGRESS}' + `; + + return executeSqlQuery({ connection, query, loggingMessage }); +}; + +export default updateApplicationVersion; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-constraints.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-constraints.ts new file mode 100644 index 0000000000..d2c34e3558 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-constraints.ts @@ -0,0 +1,34 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../../../execute-sql-query'; + +/** + * addDeclarationModernSlaveryConstraints + * - Add a modernSlavery constraint to the Declaration table. + * - Add a declaration constraint to the DeclarationModernSlavery table. + * - Add a version constraint to the DeclarationModernSlavery table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const addDeclarationModernSlaveryConstraints = async (connection: Connection) => { + const queries = await Promise.all([ + executeSqlQuery({ + connection, + query: `ALTER TABLE Declaration ADD CONSTRAINT Declaration_modernSlavery_fkey FOREIGN KEY (modernSlavery) REFERENCES DeclarationModernSlavery (id) ON DELETE SET NULL ON UPDATE CASCADE`, + loggingMessage: 'Adding CONSTRAINT modernSlavery to Declaration table', + }), + executeSqlQuery({ + connection, + query: `ALTER TABLE DeclarationModernSlavery ADD CONSTRAINT DeclarationModernSlavery_declaration_fkey FOREIGN KEY (declaration) REFERENCES Declaration (id) ON DELETE SET NULL ON UPDATE CASCADE`, + loggingMessage: 'Adding CONSTRAINT declaration to DeclarationModernSlavery table', + }), + executeSqlQuery({ + connection, + query: `ALTER TABLE DeclarationModernSlavery ADD CONSTRAINT DeclarationModernSlavery_version_fkey FOREIGN KEY (version) REFERENCES DeclarationModernSlavery (id) ON DELETE SET NULL ON UPDATE CASCADE`, + loggingMessage: 'Adding CONSTRAINT version to DeclarationModernSlavery table', + }), + ]); + + return queries; +}; + +export default addDeclarationModernSlaveryConstraints; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-field.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-field.ts new file mode 100644 index 0000000000..8805341f59 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-field.ts @@ -0,0 +1,20 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../../../execute-sql-query'; + +/** + * addDeclarationModernSlaveryField + * Add a modernSlavery field to the declaration table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const addDeclarationModernSlaveryField = (connection: Connection) => { + const loggingMessage = 'Adding FIELD modernSlavery to declaration table'; + + const query = ` + ALTER TABLE Declaration ADD modernSlavery varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL + `; + + return executeSqlQuery({ connection, query, loggingMessage }); +}; + +export default addDeclarationModernSlaveryField; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-keys.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-keys.ts new file mode 100644 index 0000000000..08028e79d0 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-keys.ts @@ -0,0 +1,27 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../../../execute-sql-query'; + +/** + * addDeclarationModernSlaveryKeys + * Add declaration and version keys to the DeclarationModernSlavery table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const addDeclarationModernSlaveryKeys = async (connection: Connection) => { + const queries = await Promise.all([ + executeSqlQuery({ + connection, + query: 'ALTER TABLE DeclarationModernSlavery ADD KEY DeclarationModernSlavery_declaration_idx(declaration)', + loggingMessage: 'Adding KEY declaration to DeclarationModernSlavery table', + }), + executeSqlQuery({ + connection, + query: 'ALTER TABLE DeclarationModernSlavery ADD KEY DeclarationModernSlavery_version_idx(version)', + loggingMessage: 'Adding KEY version to DeclarationModernSlavery table', + }), + ]); + + return queries; +}; + +export default addDeclarationModernSlaveryKeys; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-version-constraint.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-version-constraint.ts new file mode 100644 index 0000000000..a170117bdb --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-version-constraint.ts @@ -0,0 +1,17 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../../../execute-sql-query'; + +/** + * addDeclarationModernSlaveryVersionConstraint + * Add a declarationModernSlavery constraint to the DeclarationModernSlaveryVersion table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const addDeclarationModernSlaveryVersionConstraint = async (connection: Connection) => + executeSqlQuery({ + connection, + query: `ALTER TABLE DeclarationModernSlaveryVersion ADD CONSTRAINT DeclarationModernSlaveryVersion_declarationModernSlavery_fkey FOREIGN KEY (declarationModernSlavery) REFERENCES DeclarationModernSlavery (id) ON DELETE SET NULL ON UPDATE CASCADE`, + loggingMessage: 'Adding CONSTRAINT declarationModernSlavery to DeclarationModernSlaveryVersion table', + }); + +export default addDeclarationModernSlaveryVersionConstraint; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-version-key.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-version-key.ts new file mode 100644 index 0000000000..d7c972170f --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/add-declaration-modern-slavery-version-key.ts @@ -0,0 +1,17 @@ +import { Connection } from 'mysql2/promise'; +import executeSqlQuery from '../../../execute-sql-query'; + +/** + * addDeclarationModernSlaveryVersionKey + * Add a declarationModernSlavery key to the DeclarationModernSlaveryVersion table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const addDeclarationModernSlaveryVersionKey = async (connection: Connection) => + executeSqlQuery({ + connection, + query: 'ALTER TABLE DeclarationModernSlaveryVersion ADD KEY DeclarationModernSlaveryVersion_declarationModernSlavery_idx(declarationModernSlavery)', + loggingMessage: 'Adding KEY declarationModernSlavery to DeclarationModernSlaveryVersion table', + }); + +export default addDeclarationModernSlaveryVersionKey; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/create-declaration-modern-slavery-rows.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/create-declaration-modern-slavery-rows.ts new file mode 100644 index 0000000000..1c1c18b4ac --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/create-declaration-modern-slavery-rows.ts @@ -0,0 +1,33 @@ +import { Connection } from 'mysql2/promise'; +import getAllDeclarations from '../../../helpers/get-all-declarations'; +import createCuid from '../../../helpers/create-cuid'; +import executeSqlQuery from '../../../execute-sql-query'; +import { ApplicationDeclaration } from '../../../../types'; + +/** + * createDeclarationModernSlaveryRows + * For each declaration, create a new row in the DeclarationModernSlavery table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const createDeclarationModernSlaveryRows = async (connection: Connection) => { + const declarations = await getAllDeclarations(connection); + + const declarationModernSlaveryPromises = declarations.map(async (declaration: ApplicationDeclaration) => { + const { id: declarationId } = declaration; + + const theValues = `('${createCuid()}', '${declarationId}')`; + + const query = await executeSqlQuery({ + connection, + query: `INSERT INTO DeclarationModernSlavery (id, declaration) VALUES ${theValues}`, + loggingMessage: `Creating DeclarationModernSlavery entry for declaration ${declarationId}`, + }); + + return query; + }); + + return Promise.all(declarationModernSlaveryPromises); +}; + +export default createDeclarationModernSlaveryRows; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/create-declaration-modern-slavery-version-rows.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/create-declaration-modern-slavery-version-rows.ts new file mode 100644 index 0000000000..ac9f1b1d57 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/create-declaration-modern-slavery-version-rows.ts @@ -0,0 +1,57 @@ +import { Connection } from 'mysql2/promise'; +import { DECLARATIONS } from '../../../../constants'; +import getAllDeclarationModernSlaveries from '../../../helpers/get-all-declaration-modern-slaveries'; +import createCuid from '../../../helpers/create-cuid'; +import executeSqlQuery from '../../../execute-sql-query'; +import { ApplicationDeclarationModernSlavery } from '../../../../types'; + +const { WILL_ADHERE_TO_ALL_REQUIREMENTS, HAS_NO_OFFENSES_OR_INVESTIGATIONS, IS_NOT_AWARE_OF_EXISTING_SLAVERY } = + DECLARATIONS.LATEST_MODERN_SLAVERY_DECLARATIONS; + +/** + * createDeclarationModernSlaveryVersionRows + * For each modern slavery, create a new row in the DeclarationModernSlaveryVersion table. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery response + */ +const createDeclarationModernSlaveryVersionRows = async (connection: Connection) => { + const loggingMessage = 'Creating modern slavery version entries with modern slavery relationships'; + + console.info('✅ %s', loggingMessage); + + try { + const modernSlaveries = await getAllDeclarationModernSlaveries(connection); + + if (!modernSlaveries.length) { + console.info('ℹī¸ No modern slavery entries available - no need to create declarationModernSlaveryVersion entries'); + + return false; + } + + const versionPromises = modernSlaveries.map(async (modernSlavery: ApplicationDeclarationModernSlavery) => { + const { id: modernSlaveryId } = modernSlavery; + + const idValues = `'${createCuid()}', '${modernSlaveryId}',`; + + const versionValues = `'${WILL_ADHERE_TO_ALL_REQUIREMENTS}', '${HAS_NO_OFFENSES_OR_INVESTIGATIONS}', '${IS_NOT_AWARE_OF_EXISTING_SLAVERY}'`; + + const theValues = `(${idValues} ${versionValues})`; + + const query = await executeSqlQuery({ + connection, + query: `INSERT INTO DeclarationModernSlaveryVersion (id, declarationModernSlavery, hasNoOffensesOrInvestigations, isNotAwareOfExistingSlavery, willAdhereToAllRequirements) VALUES ${theValues}`, + loggingMessage: `Creating DeclarationModernSlaveryVersion entry for modernSlavery ${modernSlaveryId}`, + }); + + return query; + }); + + return Promise.all(versionPromises); + } catch (error) { + console.error('🚨 Error %s %o', loggingMessage, error); + + throw new Error(`🚨 error ${loggingMessage} ${error}`); + } +}; + +export default createDeclarationModernSlaveryVersionRows; diff --git a/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/index.ts b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/index.ts new file mode 100644 index 0000000000..75dc782124 --- /dev/null +++ b/src/api/data-migration/version-3-to-version-4/update-applications/update-declarations/index.ts @@ -0,0 +1,44 @@ +import { Connection } from 'mysql2/promise'; +import createDeclarationModernSlaveryRows from './create-declaration-modern-slavery-rows'; +import createDeclarationModernSlaveryVersionRows from './create-declaration-modern-slavery-version-rows'; +import addDeclarationModernSlaveryField from './add-declaration-modern-slavery-field'; +import addDeclarationModernSlaveryKeys from './add-declaration-modern-slavery-keys'; +import addDeclarationModernSlaveryConstraints from './add-declaration-modern-slavery-constraints'; +import addDeclarationModernSlaveryVersionKey from './add-declaration-modern-slavery-version-key'; +import addDeclarationModernSlaveryVersionConstraint from './add-declaration-modern-slavery-version-constraint'; + +/** + * updateDeclarations + * Update declarations from the V3 data model/structure, to the V4 data model/structure. + * @param {Connection} connection: SQL database connection + * @returns {Promise>} executeSqlQuery responses + */ +const updateDeclarations = async (connection: Connection) => { + const loggingMessage = 'Updating declarations'; + + console.info('✅ %s', loggingMessage); + + try { + const promises = await Promise.all([ + await createDeclarationModernSlaveryRows(connection), + + await createDeclarationModernSlaveryVersionRows(connection), + + await addDeclarationModernSlaveryField(connection), + + await addDeclarationModernSlaveryKeys(connection), + await addDeclarationModernSlaveryConstraints(connection), + + await addDeclarationModernSlaveryVersionKey(connection), + await addDeclarationModernSlaveryVersionConstraint(connection), + ]); + + return promises; + } catch (error) { + console.error('🚨 Error %s %o', loggingMessage, error); + + throw new Error(`🚨 error ${loggingMessage} ${error}`); + } +}; + +export default updateDeclarations; diff --git a/src/api/package-lock.json b/src/api/package-lock.json index 1c0b43e2e1..d15ea582a4 100644 --- a/src/api/package-lock.json +++ b/src/api/package-lock.json @@ -17,6 +17,7 @@ "@keystone-6/auth": "^7.0.3", "@keystone-6/core": "^5.8.0", "@keystone-6/fields-document": "^8.0.2", + "@paralleldrive/cuid2": "^2.2.2", "@types/express": "^5.0.0", "@types/overload-protection": "^1.2.4", "apollo-server-express": "^3.13.0", @@ -27,7 +28,7 @@ "exceljs": "^4.4.0", "express-rate-limit": "^7.4.1", "jsonwebtoken": "^9.0.2", - "mysql2": "^3.11.3", + "mysql2": "^3.11.5", "node-cron": "^3.0.3", "notifications-node-client": "^8.2.1", "otplib": "^12.0.1", @@ -5416,6 +5417,18 @@ "node": ">= 10" } }, + "node_modules/@noble/hashes": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.6.1.tgz", + "integrity": "sha512-pq5D8h10hHBjyqX+cfBm0i8JUXJ0UhczFc4r74zbuT9XgewFo2E3J1cOaGtdZynILNmQ685YWGzGE1Zv6io50w==", + "license": "MIT", + "engines": { + "node": "^14.21.3 || >=16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-3.0.0.tgz", @@ -5513,6 +5526,15 @@ "@otplib/plugin-thirty-two": "^12.0.1" } }, + "node_modules/@paralleldrive/cuid2": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/@paralleldrive/cuid2/-/cuid2-2.2.2.tgz", + "integrity": "sha512-ZOBkgDwEdoYVlSeRbYYXs0S9MejQofiVYoTbKzy/6GQa39/q5tQU2IX46+shYnUkpEl3wc+J6wRlar7r2EK2xA==", + "license": "MIT", + "dependencies": { + "@noble/hashes": "^1.1.5" + } + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", @@ -18423,9 +18445,10 @@ } }, "node_modules/mysql2": { - "version": "3.11.3", - "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.3.tgz", - "integrity": "sha512-Qpu2ADfbKzyLdwC/5d4W7+5Yz7yBzCU05YWt5npWzACST37wJsB23wgOSo00qi043urkiRwXtEvJc9UnuLX/MQ==", + "version": "3.11.5", + "resolved": "https://registry.npmjs.org/mysql2/-/mysql2-3.11.5.tgz", + "integrity": "sha512-0XFu8rUmFN9vC0ME36iBvCUObftiMHItrYFhlCRvFWbLgpNqtC4Br/NmZX1HNCszxT0GGy5QtP+k3Q3eCJPaYA==", + "license": "MIT", "dependencies": { "aws-ssl-profiles": "^1.1.1", "denque": "^2.1.0", diff --git a/src/api/package.json b/src/api/package.json index b10da9ea6f..439fa49865 100644 --- a/src/api/package.json +++ b/src/api/package.json @@ -14,7 +14,7 @@ "author": "UK Export Finance", "scripts": { "build": "NODE_ENV=dev keystone build --no-ui", - "data-migration": "npx ts-node --transpile-only ./data-migration/version-2-to-version-3/index.ts", + "data-migration": "npx ts-node --transpile-only ./data-migration/version-3-to-version-4/index.ts", "dev": "keystone dev --no-ui", "documentation": "npx spectaql -t ./documentation/output ./documentation/config.yml", "lint": "eslint ./", @@ -31,6 +31,7 @@ "@keystone-6/auth": "^7.0.3", "@keystone-6/core": "^5.8.0", "@keystone-6/fields-document": "^8.0.2", + "@paralleldrive/cuid2": "^2.2.2", "@types/express": "^5.0.0", "@types/overload-protection": "^1.2.4", "apollo-server-express": "^3.13.0", @@ -41,7 +42,7 @@ "exceljs": "^4.4.0", "express-rate-limit": "^7.4.1", "jsonwebtoken": "^9.0.2", - "mysql2": "^3.11.3", + "mysql2": "^3.11.5", "node-cron": "^3.0.3", "notifications-node-client": "^8.2.1", "otplib": "^12.0.1",