Skip to content

Commit

Permalink
feat(db migrations): fix subid db (#836)
Browse files Browse the repository at this point in the history
* Fixed subId foreignkey issue

* Bumped up the version and postponed the audits

* Fixed integration tests
  • Loading branch information
vijayg10 authored May 4, 2021
1 parent 182a591 commit de5077a
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 13 deletions.
17 changes: 7 additions & 10 deletions audit-resolve.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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
}
}
53 changes: 53 additions & 0 deletions migrations/500501_feature-fixSubIdRef.js
Original file line number Diff line number Diff line change
@@ -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 <email>.
* Gates Foundation
- Name Surname <[email protected]>
* ModusBox
- Vijay Kumar Guthi <[email protected]>
--------------
******/

// 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')
})
}
90 changes: 90 additions & 0 deletions migrations/800101_feature-fixSubIdRef.js
Original file line number Diff line number Diff line change
@@ -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 <email>.
* Gates Foundation
- Name Surname <[email protected]>
* ModusBox
- Vijay Kumar Guthi <[email protected]>
--------------
******/

// 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
`)
}
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/integration-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit de5077a

Please sign in to comment.