From de5077a478131455f43ec478e55caa7d2c5ce295 Mon Sep 17 00:00:00 2001 From: vijayg10 <33152110+vijayg10@users.noreply.github.com> Date: Tue, 4 May 2021 15:00:34 +0530 Subject: [PATCH] feat(db migrations): fix subid db (#836) * Fixed subId foreignkey issue * Bumped up the version and postponed the audits * Fixed integration tests --- audit-resolve.json | 17 ++--- migrations/500501_feature-fixSubIdRef.js | 53 ++++++++++++++ migrations/800101_feature-fixSubIdRef.js | 90 ++++++++++++++++++++++++ package-lock.json | 2 +- package.json | 2 +- test/integration-runner.sh | 2 +- 6 files changed, 153 insertions(+), 13 deletions(-) create mode 100644 migrations/500501_feature-fixSubIdRef.js create mode 100644 migrations/800101_feature-fixSubIdRef.js diff --git a/audit-resolve.json b/audit-resolve.json index fd567cc33..10738dda0 100644 --- a/audit-resolve.json +++ b/audit-resolve.json @@ -96,9 +96,8 @@ "expiresAt": 1611878178540 }, "1500|@mojaloop/central-services-shared>widdershins>yargs>yargs-parser": { - "decision": "ignore", - "madeAt": 1613868373740, - "expiresAt": 1616460368344 + "decision": "postpone", + "madeAt": 1620064635168 }, "1594|@mojaloop/central-services-health>@mojaloop/central-services-shared>axios": { "decision": "ignore", @@ -111,9 +110,8 @@ "expiresAt": 1612675767235 }, "1500|@mojaloop/central-services-health>@mojaloop/central-services-shared>widdershins>yargs>yargs-parser": { - "decision": "ignore", - "madeAt": 1613868373740, - "expiresAt": 1616460368344 + "decision": "postpone", + "madeAt": 1620064635168 }, "1640|@mojaloop/central-services-health>@mojaloop/central-services-shared>widdershins>urijs": { "decision": "ignore", @@ -126,11 +124,10 @@ "expiresAt": 1618348850367 }, "1649|@mojaloop/central-object-store>mongoose>mquery": { - "decision": "ignore", - "madeAt": 1615756857121, - "expiresAt": 1618348850367 + "decision": "postpone", + "madeAt": 1620064635832 } }, "rules": {}, "version": 1 -} +} \ No newline at end of file diff --git a/migrations/500501_feature-fixSubIdRef.js b/migrations/500501_feature-fixSubIdRef.js new file mode 100644 index 000000000..dfdf943f4 --- /dev/null +++ b/migrations/500501_feature-fixSubIdRef.js @@ -0,0 +1,53 @@ +/***** + License + -------------- + Copyright © 2017 Bill & Melinda Gates Foundation + The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + + Initial contribution + -------------------- + The initial functionality and code base was donated by the Mowali project working in conjunction with MTN and Orange as service provides. + * Project: Mowali + +Contributors + -------------- + This is the official list of the Mojaloop project contributors for this file. + Names of the original copyright holders (individuals or organizations) + should be listed with a '*' in the first column. People who have + contributed from an organization can be listed under the organization + that actually holds the copyright for their contributions (see the + Gates Foundation organization for an example). Those individuals should have + their names indented and be marked with a '-'. Email address can be added + optionally within square brackets . + * Gates Foundation + - Name Surname + + * ModusBox + - Vijay Kumar Guthi + -------------- + ******/ + +// Notes: these changes are required for the quoting-service and are not used by central-ledger +'use strict' + +exports.up = (knex) => { + return knex.schema + .table('quoteParty', (t) => { + t.dropForeign('partySubIdOrTypeId') + }) + .alterTable('quoteParty', function(t) { + t.string('partySubIdOrTypeId', 128).defaultTo(null).nullable().comment('A sub-identifier or sub-type for the Party').alter(); + }) +} + +exports.down = (knex) => { + return knex.schema + .alterTable('quoteParty', function(t) { + t.integer('partySubIdOrTypeId').unsigned().defaultTo(null).nullable().comment('A sub-identifier or sub-type for the Party').alter(); + }) + .table('quoteParty', (t) => { + t.foreign('partySubIdOrTypeId').references('partyIdentifierTypeId').inTable('partyIdentifierType') + }) +} diff --git a/migrations/800101_feature-fixSubIdRef.js b/migrations/800101_feature-fixSubIdRef.js new file mode 100644 index 000000000..3a0f410df --- /dev/null +++ b/migrations/800101_feature-fixSubIdRef.js @@ -0,0 +1,90 @@ +/***** + License + -------------- + Copyright © 2017 Bill & Melinda Gates Foundation + The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. + + Initial contribution + -------------------- + The initial functionality and code base was donated by the Mowali project working in conjunction with MTN and Orange as service provides. + * Project: Mowali + +Contributors + -------------- + This is the official list of the Mojaloop project contributors for this file. + Names of the original copyright holders (individuals or organizations) + should be listed with a '*' in the first column. People who have + contributed from an organization can be listed under the organization + that actually holds the copyright for their contributions (see the + Gates Foundation organization for an example). Those individuals should have + their names indented and be marked with a '-'. Email address can be added + optionally within square brackets . + * Gates Foundation + - Name Surname + + * ModusBox + - Vijay Kumar Guthi + -------------- + ******/ + +// Notes: these changes are required for the quoting-service and are not used by central-ledger +'use strict' + +exports.up = function (knex) { + return knex.raw(` + CREATE OR REPLACE VIEW quotePartyView AS + SELECT + qp.quoteId AS quoteId, + qp.quotePartyId AS quotePartyId, + pt.name AS partyType, + pit.name AS identifierType, + qp.partyIdentifierValue, + qp.partySubIdOrTypeId AS partySubIdOrType, + qp.fspId AS fspId, + qp.merchantClassificationCode AS merchantClassificationCode, + qp.partyName AS partyName, + p.firstName AS firstName, + p.lastName AS lastName, + p.middleName AS middleName, + p.dateOfBirth AS dateOfBirth, + gc.longitude, + gc.latitude + FROM + quoteParty qp + INNER JOIN partyType pt ON pt.partyTypeId = qp.partyTypeId + INNER JOIN partyIdentifierType pit ON pit.partyIdentifierTypeId = qp.partyIdentifierTypeId + LEFT JOIN party p ON p.quotePartyId = qp.quotePartyId + LEFT JOIN geoCode gc ON gc.quotePartyId = qp.quotePartyId + `) +} + +module.exports.down = async function(knex) { + return knex.raw(` + CREATE OR REPLACE VIEW quotePartyView AS + SELECT + qp.quoteId AS quoteId, + qp.quotePartyId AS quotePartyId, + pt.name AS partyType, + pit.name AS identifierType, + qp.partyIdentifierValue, + spit.name AS partySubIdOrType, + qp.fspId AS fspId, + qp.merchantClassificationCode AS merchantClassificationCode, + qp.partyName AS partyName, + p.firstName AS firstName, + p.lastName AS lastName, + p.middleName AS middleName, + p.dateOfBirth AS dateOfBirth, + gc.longitude, + gc.latitude + FROM + quoteParty qp + INNER JOIN partyType pt ON pt.partyTypeId = qp.partyTypeId + INNER JOIN partyIdentifierType pit ON pit.partyIdentifierTypeId = qp.partyIdentifierTypeId + LEFT JOIN party p ON p.quotePartyId = qp.quotePartyId + LEFT JOIN partyIdentifierType spit ON spit.partyIdentifierTypeId = qp.partySubIdOrTypeId + LEFT JOIN geoCode gc ON gc.quotePartyId = qp.quotePartyId + `) +} diff --git a/package-lock.json b/package-lock.json index 03ca76bbd..d6da3f81e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@mojaloop/central-ledger", - "version": "13.2.6", + "version": "13.2.7", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 898dc5809..355eea61b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mojaloop/central-ledger", - "version": "13.2.6", + "version": "13.2.7", "description": "Central ledger hosted by a scheme to record and settle transfers", "license": "Apache-2.0", "author": "ModusBox", diff --git a/test/integration-runner.sh b/test/integration-runner.sh index 67c995677..632f69ee0 100644 --- a/test/integration-runner.sh +++ b/test/integration-runner.sh @@ -158,7 +158,7 @@ start_db() { -e MYSQL_PASSWORD=$DB_PASSWORD \ -e MYSQL_DATABASE=$DB_NAME \ -e MYSQL_ALLOW_EMPTY_PASSWORD=true \ - $DB_IMAGE:$DB_TAG + $DB_IMAGE:$DB_TAG --log-error=stdout } fdb() {