Skip to content

Commit

Permalink
chore(EMS-3901): data migration - no pdf iterations (#3193)
Browse files Browse the repository at this point in the history
* chore(EMS-3901): update application versions, migration version types

* chore(EMS-3901): move common migration steps into parent directory

* chore(EMS-3901): data migration - v2 to v3 script

* chore(EMS-3901): data migration - v2 to v3 - update README.md

* chore(EMS-3901): update db schema

* chore(EMS-3901): remove todo comment

* chore(EMS-3901): update unit test

* chore(EMS-3901): data migration - v2 to v3 - remove migratedV1toV2 field

* chore(EMS-3901): update ui type

* chore(EMS-3901): recompile keystone schema

* chore(EMS-3901): update data migration logs

* chore(EMS-3901): update data migration README.md

* chore(EMS-3901): update data migration error logs
  • Loading branch information
ttbarnes authored Oct 25, 2024
1 parent c721023 commit 13d128a
Show file tree
Hide file tree
Showing 131 changed files with 579 additions and 205 deletions.
1 change: 1 addition & 0 deletions database/exip.sql
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ CREATE TABLE `Application` (
`dealType` varchar(4) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'EXIP',
`policyContact` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`nominatedLossPayee` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`migratedV2toV3` tinyint(1) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `Application_eligibility_idx` (`eligibility`),
KEY `Application_referenceNumber_idx` (`referenceNumber`),
Expand Down
43 changes: 24 additions & 19 deletions src/api/.keystone/config.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/api/constants/application/versions/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ describe('api/constants/application/versions', () => {
DEFAULT_CURRENCY: GBP,
BROKER_ADDRESS_AS_MULTIPLE_FIELDS: false,
},
{
VERSION_NUMBER: '3',
OVER_500K_SUPPORT: true,
DEFAULT_FINAL_DESTINATION_KNOWN: null,
DEFAULT_NEED_PRE_CREDIT_PERIOD_COVER: null,
DEFAULT_CURRENCY: GBP,
BROKER_ADDRESS_AS_MULTIPLE_FIELDS: false,
REQUESTED_CREDIT_LIMIT_REQUIRED: true,
},
];

expect(VERSIONS).toEqual(expected);
Expand Down
48 changes: 30 additions & 18 deletions src/api/constants/application/versions/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import { ApplicationVersion } from '../../../types';
import { GBP } from '../../supported-currencies';

const VERSION_1 = {
VERSION_NUMBER: '1',
OVER_500K_SUPPORT: false,
MAXIMUM_BUYER_CAN_OWE: 500000,
TOTAL_VALUE_OF_CONTRACT: 500000,
DEFAULT_FINAL_DESTINATION_KNOWN: true,
DEFAULT_NEED_PRE_CREDIT_PERIOD_COVER: false,
BROKER_ADDRESS_AS_MULTIPLE_FIELDS: true,
} as ApplicationVersion;

const VERSION_2 = {
VERSION_NUMBER: '2',
OVER_500K_SUPPORT: true,
DEFAULT_FINAL_DESTINATION_KNOWN: null,
DEFAULT_NEED_PRE_CREDIT_PERIOD_COVER: null,
DEFAULT_CURRENCY: GBP,
BROKER_ADDRESS_AS_MULTIPLE_FIELDS: false,
} as ApplicationVersion;

const VERSION_3 = {
...VERSION_2,
VERSION_NUMBER: '3',
REQUESTED_CREDIT_LIMIT_REQUIRED: true,
} as ApplicationVersion;

/**
* VERSIONS
* All possible application versions.
Expand All @@ -9,27 +34,14 @@ import { GBP } from '../../supported-currencies';
* This should be manually updated each time a phase of EXIP is started. For example:
* - Version number 1: MVP, no support for applications over 500k.
* - Version number 2: Support for applications over 500k.
* - Version number 3: Payments integration
* - Version number 3: Design and content iterations. 1x new database field.
* - Version number 4: Payments integration
* @returns {Array<ApplicationVersion>} All application versions
*/
const VERSIONS = [
{
VERSION_NUMBER: '1',
OVER_500K_SUPPORT: false,
MAXIMUM_BUYER_CAN_OWE: 500000,
TOTAL_VALUE_OF_CONTRACT: 500000,
DEFAULT_FINAL_DESTINATION_KNOWN: true,
DEFAULT_NEED_PRE_CREDIT_PERIOD_COVER: false,
BROKER_ADDRESS_AS_MULTIPLE_FIELDS: true,
},
{
VERSION_NUMBER: '2',
OVER_500K_SUPPORT: true,
DEFAULT_FINAL_DESTINATION_KNOWN: null,
DEFAULT_NEED_PRE_CREDIT_PERIOD_COVER: null,
DEFAULT_CURRENCY: GBP,
BROKER_ADDRESS_AS_MULTIPLE_FIELDS: false,
},
VERSION_1,
VERSION_2,
VERSION_3,
] as Array<ApplicationVersion>;

export default VERSIONS;
7 changes: 4 additions & 3 deletions src/api/constants/application/versions/latest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import VERSIONS from '.';
* For example:
* - Version number 1: MVP - No support for applications over 500k.
* - Version number 2: "No PDF" - Support for applications over 500k.
* - Version number 3: File uploads
* - Version number 4: Address lookup
* - Version number 5: Payments integration
* - Version number 3: "No PDF" design and content iterations. 1x new database field.
* - Version number 4: File uploads
* - Version number 5: Address lookup
* - Version number 6: Payments integration
* @returns {String} Latest application version number
*/
const LATEST_VERSION_NUMBER = VERSIONS[VERSIONS.length - 1].VERSION_NUMBER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const executeSqlQuery = async ({ connection, query, loggingMessage }: ExecuteSql

return response;
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/data-migration/version-1-to-version-2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Note - there are 2 new fields that are created with a default currency code (GBP

## Prerequisites :gear:

To set up and run the API locally, you'll need the following prerequisites:
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 1 (MVP) data structure.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Connection } from 'mysql2/promise';
import executeSqlQuery from '../execute-sql-query';
import executeSqlQuery from '../../execute-sql-query';
import { AccountStatus } from '../../../types';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { format } from 'date-fns';
import { Connection } from 'mysql2/promise';
import executeSqlQuery from '../execute-sql-query';
import executeSqlQuery from '../../execute-sql-query';
import { AccountMvp } from '../../../types';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const createNewAccountStatusRelationships = async (connection: Connection): Prom

return true;
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Connection } from 'mysql2/promise';
import createCuid from '../create-cuid';
import executeSqlQuery from '../execute-sql-query';
import executeSqlQuery from '../../execute-sql-query';
import { Application } from '../../../types';

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ const createCompanyDifferentTradingAddress = async (connection: Connection, appl

return Promise.all(promises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Connection } from 'mysql2/promise';
import getAllDeclarations from '../get-all-declarations';
import getAllDeclarationVersions from '../get-all-declaration-versions';
import executeSqlQuery from '../execute-sql-query';
import executeSqlQuery from '../../execute-sql-query';

/**
* updateDeclarationVersionField
Expand Down Expand Up @@ -39,7 +39,7 @@ const updateDeclarationVersionField = async (connection: Connection) => {

return Promise.all(declarationPromises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const createDeclarationVersionRelationship = async (connection: Connection) => {

return promises;
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Connection } from 'mysql2/promise';
import { DECLARATIONS } from '../../../../constants';
import getAllNonSubmittedApplications from '../../get-all-non-submitted-applications';
import createCuid from '../../create-cuid';
import executeSqlQuery from '../../execute-sql-query';
import executeSqlQuery from '../../../execute-sql-query';
import { Application } from '../../../../types';

const { ANTI_BRIBERY, ANTI_BRIBERY_CODE_OF_CONDUCT, ANTI_BRIBERY_EXPORTING_WITH_CODE_OF_CONDUCT, CONFIDENTIALITY, CONFIRMATION_AND_ACKNOWLEDGEMENTS } =
Expand Down Expand Up @@ -53,7 +53,7 @@ const createDeclarationVersionRelationshipNotSubmittedApplications = async (conn

return Promise.all(declarationPromises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Connection } from 'mysql2/promise';
import { DECLARATIONS } from '../../../../constants';
import getAllSubmittedApplications from '../../get-all-submitted-applications';
import createCuid from '../../create-cuid';
import executeSqlQuery from '../../execute-sql-query';
import executeSqlQuery from '../../../execute-sql-query';
import { Application } from '../../../../types';

const {
Expand Down Expand Up @@ -59,7 +59,7 @@ const createDeclarationVersionRelationshipSubmittedApplications = async (connect

return Promise.all(declarationPromises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Connection } from 'mysql2/promise';
import createCuid from '../../create-cuid';
import executeSqlQuery from '../../execute-sql-query';
import executeSqlQuery from '../../../execute-sql-query';
import { Application } from '../../../../types';

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ const createAgentServiceCharges = async (connection: Connection, applications: A

return Promise.all(servicesPromises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Connection } from 'mysql2/promise';
import createCuid from '../../create-cuid';
import executeSqlQuery from '../../execute-sql-query';
import executeSqlQuery from '../../../execute-sql-query';
import { Application } from '../../../../types';

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ const createAgentServices = async (connection: Connection, applications: Array<A

return Promise.all(servicesPromises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Connection } from 'mysql2/promise';
import createCuid from '../../create-cuid';
import executeSqlQuery from '../../execute-sql-query';
import executeSqlQuery from '../../../execute-sql-query';
import { Application } from '../../../../types';

/**
Expand Down Expand Up @@ -37,7 +37,7 @@ const createInitialAgents = async (connection: Connection, applications: Array<A

return Promise.all(initialAgentsPromises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const createExportContractAgent = async (connection: Connection, applications: A

return promises;
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Connection } from 'mysql2/promise';
import getAllExportContractAgentServices from '../../get-all-export-contract-agent-services';
import getAllExportContractAgentServiceCharges from '../../get-all-export-contract-agent-service-charges';
import executeSqlQuery from '../../execute-sql-query';
import executeSqlQuery from '../../../execute-sql-query';

/**
* updateExportContractAgentServiceCharges
Expand Down Expand Up @@ -39,7 +39,7 @@ const updateExportContractAgentServiceCharges = async (connection: Connection) =

return Promise.all(promises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Connection } from 'mysql2/promise';
import getAllExportContractAgents from '../../get-all-export-contract-agents';
import getAllExportContractAgentServices from '../../get-all-export-contract-agent-services';
import executeSqlQuery from '../../execute-sql-query';
import executeSqlQuery from '../../../execute-sql-query';

/**
* updateExportContractAgentServices
Expand Down Expand Up @@ -39,7 +39,7 @@ const updateExportContractAgentServices = async (connection: Connection) => {

return Promise.all(promises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Connection } from 'mysql2/promise';
import getAllExportContracts from '../../get-all-export-contracts';
import getAllExportContractAgents from '../../get-all-export-contract-agents';
import executeSqlQuery from '../../execute-sql-query';
import executeSqlQuery from '../../../execute-sql-query';

/**
* updateExportContractAgents
Expand Down Expand Up @@ -39,7 +39,7 @@ const updateExportContractAgents = async (connection: Connection) => {

return Promise.all(promises);
} catch (error) {
console.error('🚨 error %s %o', loggingMessage, error);
console.error('🚨 Error %s %o', loggingMessage, error);

throw new Error(`🚨 error ${loggingMessage} ${error}`);
}
Expand Down
Loading

0 comments on commit 13d128a

Please sign in to comment.