Skip to content

Commit

Permalink
fix(EMS-3633): data migration - financial vector columns (#2928)
Browse files Browse the repository at this point in the history
* fix(EMS-3633): data migration - financial vectors

* chore(docs): data migration - documentation improvements
  • Loading branch information
ttbarnes authored Aug 9, 2024
1 parent 86ae2ac commit a3b1470
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
4 changes: 3 additions & 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 @@ -99,7 +99,9 @@ This is because, during `npm run dev`, KeystoneJS/prisma checks the schema again

We manage our own data migration, so we do not need these checks to run.

To run `npm run dev` after running the migration script, it can be achieved by adding a `--no-db-push` to the command. However, this should not be necessary since this is for development environments only. In a data migration scenario, `npm run start` should be used.
To run `npm run dev` after running the migration script, it can be achieved by adding a `--no-db-push` to the `package.json` `dev` script. However, this should only be used for debugging purposes in development environments only.

In a data migration scenario outside of a development environment, `npm run start` should be used.

## SQL and KeystoneJS queries

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ const createNewApplicationRelationships = async (connection: Connection) => {
updateCompanyDifferentTradingAddress(connection),
createDeclarationVersionRelationship(connection),
updateDeclarationVersionField(connection, applications),
]);

const financialVectorRelationships = await Promise.all([
updateLossPayeeFinancialUkVector(connection),
updateLossPayeeFinancialInternationalVector(connection),
]);

return newRelationships;
return [...newRelationships, ...financialVectorRelationships];
} catch (err) {
console.error(`🚨 error ${loggingMessage} %O`, err);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import createCuid from '../../create-cuid';
import executeSqlQuery from '../../execute-sql-query';

/**
* lossPayeeFinancialInternational
* lossPayeeFinancialUk
* Create new "nominated loss payee - financial UK" entries
* @param {Connection} connection: SQL database connection
* @returns {Promise<Array<object>>} Loss payee - nominated loss payee - financial UK entries
*/
const lossPayeeFinancialInternational = async (connection: Connection) => {
const lossPayeeFinancialUk = async (connection: Connection) => {
const loggingMessage = 'Creating nominatedLossPayees - financial UK';

console.info(`βœ… ${loggingMessage}`);
Expand Down Expand Up @@ -41,4 +41,4 @@ const lossPayeeFinancialInternational = async (connection: Connection) => {
}
};

export default lossPayeeFinancialInternational;
export default lossPayeeFinancialUk;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ const updateLossPayeeFinancialInternationalVector = async (connection: Connectio
const financialInternationals = await getAllLossPayeeFinancialInternational(connection);
const vectors = await getAllLossPayeeFinancialInternationalVectors(connection);

if (!financialInternationals.length) {
console.info('🚨 No financial internationals available - unable to update vector columns');

throw new Error('🚨 No financial internationals available - unable to update vector columns');
}

if (!vectors.length) {
console.info('🚨 No financial international vectors available - unable to update vector columns');

throw new Error('🚨 No financial international vectors available - unable to update vector columns');
}

const promises = financialInternationals.map(async (financialInternational: object, index: number) => {
const vector = vectors[index];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ const updateLossPayeeFinancialUkVector = async (connection: Connection) => {
const financialUks = await getAllLossPayeeFinancialUk(connection);
const vectors = await getAllLossPayeeFinancialUkVectors(connection);

if (!financialUks.length) {
console.info('🚨 No financial UKs available - unable to update vector columns');

throw new Error('🚨 No financial UKs available - unable to update vector columns');
}

if (!vectors.length) {
console.info('🚨 No financial UK vectors available - unable to update vector columns');

throw new Error('🚨 No financial UK vectors available - unable to update vector columns');
}

const promises = financialUks.map(async (financialUk: object, index: number) => {
const vector = vectors[index];

Expand Down

0 comments on commit a3b1470

Please sign in to comment.