Skip to content

Commit

Permalink
feat(EMS-3722-3723): data migration - eligibility, export contract (#…
Browse files Browse the repository at this point in the history
…2901)

* feat(EMS-3722-3723): data migration - export contract award method

* feat(EMS-3722): data migration - eligibility updates

* feat(EMS-3722): data migration - eligibility - conditional task list requirements

* fix(EMS-3633): data migration - declarations versioning issue

* chore(db): update timestamp

* fix(EMS-3633): data migration - declarations versioning issue

* chore(docs): fix typos

* chore(helpers): improve canSubmitApplication logging

* chore(migration): simplify promise.all
  • Loading branch information
ttbarnes authored Aug 6, 2024
1 parent 004c790 commit 0c16bc1
Show file tree
Hide file tree
Showing 38 changed files with 317 additions and 123 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

## [2.33.0](https://github.com/UK-Export-Finance/exip/compare/v2.32.0...v2.33.0) (2024-08-06)


### Features

* **EMS-3709-3710:** export contract - how the contract was awarded - check your answers ([#2895](https://github.com/UK-Export-Finance/exip/issues/2895)) ([4648efc](https://github.com/UK-Export-Finance/exip/commit/4648efc28376536127975d4954b1615135a083bc))
- **EMS-3709-3710:** export contract - how the contract was awarded - check your answers ([#2895](https://github.com/UK-Export-Finance/exip/issues/2895)) ([4648efc](https://github.com/UK-Export-Finance/exip/commit/4648efc28376536127975d4954b1615135a083bc))

## [2.32.0](https://github.com/UK-Export-Finance/exip/compare/v2.31.0...v2.32.0) (2024-08-05)

Expand Down
6 changes: 3 additions & 3 deletions database/exip.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Version 2
#
# Database: exip
# Generation Time: 2024-07-25 15:31:00 +0000
# Generation Time: 2024-08-05 16:34:00 +0000
# ************************************************************

CREATE DATABASE IF NOT EXISTS `exip`;
Expand Down Expand Up @@ -662,12 +662,12 @@ CREATE TABLE IF NOT EXISTS `Eligibility` (
`hasCompaniesHouseNumber` tinyint(1) NOT NULL DEFAULT '0',
`hasEndBuyer` tinyint(1) NOT NULL DEFAULT '0',
`hasMinimumUkGoodsOrServices` tinyint(1) NOT NULL DEFAULT '0',
`isMemberOfAGroup` tinyint(1) NOT NULL DEFAULT '0',
`isPartyToConsortium` tinyint(1) NOT NULL DEFAULT '0',
`otherPartiesInvolved` tinyint(1) NOT NULL DEFAULT '0',
`paidByLetterOfCredit` tinyint(1) NOT NULL DEFAULT '0',
`totalContractValue` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`validExporterLocation` tinyint(1) NOT NULL DEFAULT '0',
`isPartyToConsortium` tinyint(1) NOT NULL DEFAULT '0',
`isMemberOfAGroup` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `Eligibility_application_idx` (`application`),
KEY `Eligibility_buyerCountry_idx` (`buyerCountry`),
Expand Down
4 changes: 2 additions & 2 deletions src/api/custom-schema/type-defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,10 @@ const typeDefs = `
hasCompaniesHouseNumber: Boolean!
hasEndBuyer: Boolean!
hasMinimumUkGoodsOrServices: Boolean!
isMemberOfAGroup: Boolean!
isPartyToConsortium: Boolean!
totalContractValueId: Int!
validExporterLocation: Boolean!
isPartyToConsortium: Boolean!
isMemberOfAGroup: Boolean!
}
type CreateAnApplicationResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const updateDeclarationVersionField = async (connection: Connection) => {
const updated = await executeSqlQuery({
connection,
query,
loggingMessage: `Updating version column in declartion table for declaration ${declaration.id}`,
loggingMessage: `Updating version column in declaration table for declaration ${declaration.id}`,
});

return updated;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ const createNewApplicationRelationships = async (connection: Connection) => {
updateExportContractPrivateMarket(connection),
createCompanyDifferentTradingAddress(connection, applications),
updateCompanyDifferentTradingAddress(connection),
createDeclarationVersionRelationship(connection, applications),
createDeclarationVersionRelationship(connection),
updateDeclarationVersionField(connection, applications),
updateLossPayeeFinancialUkVector(connection),
updateLossPayeeFinancialInternationalVector(connection),
]);

await updateLossPayeeFinancialUkVector(connection);
await updateLossPayeeFinancialInternationalVector(connection);

return newRelationships;
} catch (err) {
console.error(`🚨 error ${loggingMessage} %O`, err);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Connection } from 'mysql2/promise';
import executeSqlQuery from '../execute-sql-query';

/**
* createExportContractAwardMethodTable
* Create new "export contract - award method" database table.
* @param {Connection} connection: SQL database connection
* @returns {Promise<Array<object>>} executeSqlQuery response
*/
const createExportContractAwardMethodTable = async (connection: Connection) => {
const loggingMessage = 'Creating TABLE - export contract award method';

console.info(`✅ ${loggingMessage}`);

try {
const query = `
CREATE TABLE ExportContractAwardMethod (
id varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
value varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
PRIMARY KEY (id)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
`;

await executeSqlQuery({ connection, query, loggingMessage });

const awardMethodPromises = [
executeSqlQuery({
connection,
query: `INSERT INTO ExportContractAwardMethod (id, value) VALUES ('eg9qxlqw4edxa8b5mwbybsrfp', 'Open tender')`,
loggingMessage,
}),

executeSqlQuery({
connection,
query: `INSERT INTO ExportContractAwardMethod (id, value) VALUES ('mzwp337piamg1mei7fqh1o73s', 'Negotiated contract')`,
loggingMessage,
}),

executeSqlQuery({
connection,
query: `INSERT INTO ExportContractAwardMethod (id, value) VALUES ('qnqrle4xwsj5go8pchj31sat4', 'Direct award')`,
loggingMessage,
}),

executeSqlQuery({
connection,
query: `INSERT INTO ExportContractAwardMethod (id, value) VALUES ('qw2hp8khykctdic2z58z70ru8', 'Competitive bidding')`,
loggingMessage,
}),

executeSqlQuery({
connection,
query: `INSERT INTO ExportContractAwardMethod (id, value) VALUES ('tn8k8lot1bvirmztmmgq2u8hn', 'Other')`,
loggingMessage,
}),
];

return Promise.all(awardMethodPromises);
} catch (err) {
console.error(`🚨 error ${loggingMessage} %O`, err);

throw new Error(`🚨 error ${loggingMessage} ${err}`);
}
};

export default createExportContractAwardMethodTable;
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import createJointlyInsuredPartyTable from './create-jointly-insured-party-table
import createExportContractAgentServiceChargeTable from './create-export-contract-agent-service-charge-table';
import createExportContractAgentServiceTable from './create-export-contract-agent-service-table';
import createExportContractAgentTable from './create-export-contract-agent-table';
import createExportContractAwardMethodTable from './create-export-contract-award-method-table';
import createPrivateMarketTable from './create-private-market-table';
import createCompanyDifferentTradingAddressTable from './create-company-different-trading-address-table';
import createBuyerContactTable from './create-buyer-contact-table';
Expand Down Expand Up @@ -36,6 +37,7 @@ const createTables = async (connection: Connection) => {
createExportContractAgentServiceChargeTable(connection),
createExportContractAgentServiceTable(connection),
createExportContractAgentTable(connection),
createExportContractAwardMethodTable(connection),

createPrivateMarketTable(connection),
createCompanyDifferentTradingAddressTable(connection),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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<Object>} Declarations
* @returns {Promise<ApplicationDeclaration>} Declarations
*/
const getAllDeclarations = async (connection: Connection) => {
const loggingMessage = 'Getting all declarations';
Expand All @@ -17,7 +18,7 @@ const getAllDeclarations = async (connection: Connection) => {

const [declarations] = await executeSqlQuery({ connection, query, loggingMessage });

return declarations;
return declarations as Array<ApplicationDeclaration>;
} catch (err) {
console.error(`🚨 error ${loggingMessage} %O`, err);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Connection } from 'mysql2/promise';
import { APPLICATION } from '../../constants';
import executeSqlQuery from './execute-sql-query';
import { Application } from '../../types';

const { STATUS } = APPLICATION;

Expand All @@ -18,7 +19,7 @@ const getAllNonSubmittedApplications = async (connection: Connection) => {

const [applications] = await executeSqlQuery({ connection, query, loggingMessage });

return applications;
return applications as Array<Application>;
} catch (err) {
console.error(`🚨 error ${loggingMessage} %O`, err);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Connection } from 'mysql2/promise';
import { APPLICATION } from '../../constants';
import executeSqlQuery from './execute-sql-query';
import { Application } from '../../types';

const { STATUS } = APPLICATION;

Expand All @@ -18,7 +19,7 @@ const getAllSubmittedApplications = async (connection: Connection) => {

const [applications] = await executeSqlQuery({ connection, query, loggingMessage });

return applications;
return applications as Array<Application>;
} catch (err) {
console.error(`🚨 error ${loggingMessage} %O`, err);

Expand Down
4 changes: 2 additions & 2 deletions src/api/data-migration/version-1-to-version-2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ const dataMigration = async () => {

console.info('✅ Buyers successfully updated.');

await createNewApplicationRelationships(connection);

await removeDeclarationFields(connection);

await removeDeclarationContentTables(connection);

console.info('✅ Declarations successfully updated.');

await createNewApplicationRelationships(connection);

console.info('✅ Application relationships successfully updated.');

console.info('🎉 Migration complete. Exiting script');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import executeSqlQuery from '../execute-sql-query';

/**
* addBusinessFields
* Add new business fields to the business table.
* Add new fields to the business table.
* @param {Connection} connection: SQL database connection
* @returns {Promise<Array<object>>} executeSqlQuery response
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const companyConstraints = (connection: Connection) =>

/**
* addCompanyFields
* Add new company fields to the company table.
* Add new fields to the company table.
* @param {Connection} connection: SQL database connection
* @returns {Promise<Array<object>>} executeSqlQuery response
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Connection } from 'mysql2/promise';
import executeSqlQuery from '../execute-sql-query';

/**
* addEligibilityFields
* Add new fields to the eligibility table.
* @param {Connection} connection: SQL database connection
* @returns {Promise<Array<object>>} executeSqlQuery response
*/
const addEligibilityFields = async (connection: Connection) => {
const promises = await Promise.all([
executeSqlQuery({
connection,
query: `ALTER TABLE Eligibility ADD hasEndBuyer tinyint(1) NOT NULL DEFAULT '0'`,
loggingMessage: 'Adding FIELD hasEndBuyer to eligibility table',
}),

executeSqlQuery({
connection,
query: `ALTER TABLE Eligibility ADD isMemberOfAGroup tinyint(1) NOT NULL DEFAULT '0'`,
loggingMessage: 'Adding FIELD isMemberOfAGroup to eligibility table',
}),

executeSqlQuery({
connection,
query: `ALTER TABLE Eligibility ADD isPartyToConsortium tinyint(1) NOT NULL DEFAULT '0'`,
loggingMessage: 'Adding FIELD isPartyToConsortium to eligibility table',
}),
]);

return promises;
};

export default addEligibilityFields;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ const exportContractConstraints = async (connection: Connection) => {
loggingMessage: 'Adding CONSTRAINT agent to exportContract table',
}),

executeSqlQuery({
connection,
query: `ALTER TABLE ExportContract ADD CONSTRAINT ExportContract_awardMethod_fkey FOREIGN KEY (awardMethod) REFERENCES ExportContractAwardMethod (id) ON DELETE SET NULL ON UPDATE CASCADE`,
loggingMessage: 'Adding CONSTRAINT awardMethod to exportContract table',
}),

executeSqlQuery({
connection,
query: `ALTER TABLE ExportContract ADD CONSTRAINT ExportContract_privateMarket_fkey FOREIGN KEY (privateMarket) REFERENCES PrivateMarket (id) ON DELETE SET NULL ON UPDATE CASCADE`,
Expand All @@ -51,28 +57,40 @@ const exportContractConstraints = async (connection: Connection) => {

/**
* addExportContractFields
* Add new export contract fields to the exportContract table.
* Add new fields to the exportContract table.
* @param {Connection} connection: SQL database connection
* @returns {Promise<Array<object>>} executeSqlQuery response
*/
const addExportContractFields = async (connection: Connection) => {
const queries = await Promise.all([
executeSqlQuery({
connection,
query: `ALTER TABLE ExportContract ADD paymentTermsDescription varchar(1000) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''`,
loggingMessage: 'Adding FIELD paymentTermsDescription to exportContract table',
query: `ALTER TABLE ExportContract ADD agent varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL`,
loggingMessage: 'Adding FIELD agent to exportContract table',
}),

executeSqlQuery({
connection,
query: `ALTER TABLE ExportContract ADD privateMarket varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL`,
loggingMessage: 'Adding FIELD privateMarket to exportContract table',
query: `ALTER TABLE ExportContract ADD awardMethod varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL`,
loggingMessage: 'Adding FIELD awardMethod to exportContract table',
}),

executeSqlQuery({
connection,
query: `ALTER TABLE ExportContract ADD agent varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL`,
loggingMessage: 'Adding FIELD agent to exportContract table',
query: `ALTER TABLE ExportContract ADD otherAwardMethod varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''`,
loggingMessage: 'Adding FIELD otherAwardMethod to exportContract table',
}),

executeSqlQuery({
connection,
query: `ALTER TABLE ExportContract ADD paymentTermsDescription varchar(1000) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT ''`,
loggingMessage: 'Adding FIELD paymentTermsDescription to exportContract table',
}),

executeSqlQuery({
connection,
query: `ALTER TABLE ExportContract ADD privateMarket varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL`,
loggingMessage: 'Adding FIELD privateMarket to exportContract table',
}),

exportContractUniqueKeys(connection),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import addBuyerFields from './add-buyer-fields';
import addCompanyFields from './add-company-fields';
import addBusinessFields from './add-business-fields';
import addBrokerFullAddressField from './add-broker-full-address-field';
import addEligibilityHasEndBuyerField from './add-eligibility-has-end-buyer-field';
import addEligibilityFields from './add-eligibility-fields';
import addDeclarationFields from './add-declaration-fields';
import updateDeclarationFields from './update-declaration-fields';
import addSectionReviewExportContractField from './add-section-review-export-contract-field';
Expand Down Expand Up @@ -38,7 +38,7 @@ const updateApplications = async (connection: Connection) => {
addCompanyFields(connection),
addBusinessFields(connection),
addBrokerFullAddressField(connection),
addEligibilityHasEndBuyerField(connection),
addEligibilityFields(connection),

addDeclarationFields(connection),
updateDeclarationFields(connection),
Expand Down
4 changes: 2 additions & 2 deletions src/api/types/application-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ export interface ApplicationCompanySicCode {
}

export interface ApplicationDeclaration extends Relationship {
agreeToConfidentiality?: boolean;
agreeToAntiBribery?: boolean;
agreeToConfidentiality?: boolean;
agreeToConfirmationAndAcknowledgements?: boolean;
hasAntiBriberyCodeOfConduct?: boolean | null;
willExportWithAntiBriberyCodeOfConduct?: boolean;
agreeToConfirmationAndAcknowledgements?: boolean;
}

export interface ApplicationDeclarationVersions {
Expand Down
Loading

0 comments on commit 0c16bc1

Please sign in to comment.