@mojaloop/central-ledger 17.7.8 → 17.8.0-orb.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/.ncurc.yaml +3 -1
  2. package/.nvmrc +1 -1
  3. package/.nycrc.yml +16 -1
  4. package/Dockerfile +9 -10
  5. package/README.md +39 -9
  6. package/audit-ci.jsonc +15 -2
  7. package/config/default.json +17 -1
  8. package/docker/central-ledger/default.json +9 -0
  9. package/docker/config-modifier/configs/central-ledger.js +25 -0
  10. package/docker/env.sh +15 -0
  11. package/docker/kafka/scripts/provision.sh +4 -1
  12. package/docker/ml-api-adapter/default.json +4 -1
  13. package/docker-compose.yml +90 -2
  14. package/documentation/db/erd-transfer-timeout.png +0 -0
  15. package/documentation/db/erd-transfer-timeout.txt +81 -0
  16. package/documentation/fx-implementation/README.md +48 -0
  17. package/documentation/fx-implementation/assets/fx-position-movements.drawio.svg +4 -0
  18. package/documentation/fx-implementation/assets/test-scenario.drawio.svg +4 -0
  19. package/documentation/sequence-diagrams/Handler - FX timeout.plantuml +123 -0
  20. package/documentation/sequence-diagrams/Handler - FX timeout.png +0 -0
  21. package/documentation/sequence-diagrams/Handler - timeout.plantuml +81 -0
  22. package/documentation/sequence-diagrams/Handler - timeout.png +0 -0
  23. package/documentation/state-diagrams/transfer-ML-spec-states-diagram.png +0 -0
  24. package/documentation/state-diagrams/transfer-internal-states-diagram.png +0 -0
  25. package/documentation/state-diagrams/transfer-internal-states.plantuml +75 -0
  26. package/documentation/state-diagrams/transfer-states.plantuml +13 -0
  27. package/migrations/310204_transferParticipant-participantId.js +52 -0
  28. package/migrations/310403_participantPositionChange-participantCurrencyId.js +47 -0
  29. package/migrations/310404_participantPositionChange-change.js +46 -0
  30. package/migrations/600010_fxTransferType.js +43 -0
  31. package/migrations/600011_fxTransferType-indexes.js +38 -0
  32. package/migrations/600012_fxParticipantCurrencyType.js +43 -0
  33. package/migrations/600013_fxParticipantCurrencyType-indexes.js +38 -0
  34. package/migrations/600100_fxTransferDuplicateCheck.js +42 -0
  35. package/migrations/600110_fxTransferErrorDuplicateCheck.js.js +17 -0
  36. package/migrations/600200_fxTransfer.js +51 -0
  37. package/migrations/600201_fxTransfer-indexes.js +40 -0
  38. package/migrations/600400_fxTransferStateChange.js +46 -0
  39. package/migrations/600401_fxTransferStateChange-indexes.js +40 -0
  40. package/migrations/600501_fxWatchList.js +46 -0
  41. package/migrations/600502_fxWatchList-indexes.js +40 -0
  42. package/migrations/600600_fxTransferFulfilmentDuplicateCheck.js +43 -0
  43. package/migrations/600601_fxTransferFulfilmentDuplicateCheck-indexes.js +38 -0
  44. package/migrations/600700_fxTransferFulfilment.js +47 -0
  45. package/migrations/600701_fxTransferFulfilment-indexes.js +43 -0
  46. package/migrations/600800_fxTransferExtension.js +47 -0
  47. package/migrations/601400_fxTransferTimeout.js +43 -0
  48. package/migrations/601401_fxTransferTimeout-indexes.js +37 -0
  49. package/migrations/601500_fxTransferError.js +44 -0
  50. package/migrations/601501_fxTransferError-indexes.js +37 -0
  51. package/migrations/610200_fxTransferParticipant.js +52 -0
  52. package/migrations/610201_fxTransferParticipant-indexes.js +44 -0
  53. package/migrations/610202_fxTransferParticipant-participantId.js +52 -0
  54. package/migrations/610403_participantPositionChange-fxTransfer.js +46 -0
  55. package/migrations/910101_feature904DataMigration.js +46 -52
  56. package/migrations/910102_feature949DataMigration.js +219 -225
  57. package/migrations/950104_settlementModel-settlementAccountTypeId.js +15 -20
  58. package/migrations/950108_participantProxy.js +18 -0
  59. package/migrations/950109_fxQuote.js +19 -0
  60. package/migrations/950110_fxQuoteResponse.js +25 -0
  61. package/migrations/950111_fxQuoteError.js +23 -0
  62. package/migrations/950113_fxQuoteDuplicateCheck.js +18 -0
  63. package/migrations/950114_fxQuoteResponseDuplicateCheck.js +21 -0
  64. package/migrations/950115_fxQuoteConversionTerms.js +36 -0
  65. package/migrations/950116_fxQuoteConversionTermsExtension.js +21 -0
  66. package/migrations/950117_fxQuoteResponseConversionTerms.js +39 -0
  67. package/migrations/950118_fxQuoteResponseConversionTermsExtension.js +21 -0
  68. package/migrations/950119_fxCharge.js +27 -0
  69. package/migrations/960100_create_externalParticipant.js +47 -0
  70. package/migrations/960110_alter_transferParticipant__addFiled_externalParticipantId.js +50 -0
  71. package/migrations/960111_alter_fxTransferParticipant__addFiled_externalParticipantId.js +50 -0
  72. package/package.json +27 -20
  73. package/seeds/endpointType.js +18 -0
  74. package/seeds/fxParticipantCurrencyType.js +45 -0
  75. package/seeds/fxTransferType.js +45 -0
  76. package/seeds/participant.js +2 -1
  77. package/seeds/transferParticipantRoleType.js +9 -0
  78. package/seeds/transferState.js +10 -0
  79. package/src/api/interface/swagger.json +23 -30
  80. package/src/api/participants/handler.js +6 -2
  81. package/src/api/participants/routes.js +8 -7
  82. package/src/api/root/handler.js +15 -5
  83. package/src/domain/fx/cyril.js +466 -0
  84. package/src/domain/fx/index.js +107 -0
  85. package/src/domain/participant/index.js +108 -1
  86. package/src/domain/position/abort.js +215 -0
  87. package/src/domain/position/binProcessor.js +361 -99
  88. package/src/domain/position/fulfil.js +252 -111
  89. package/src/domain/position/fx-fulfil.js +138 -0
  90. package/src/domain/position/fx-prepare.js +280 -0
  91. package/src/domain/position/fx-timeout-reserved.js +159 -0
  92. package/src/domain/position/index.js +1 -0
  93. package/src/domain/position/prepare.js +69 -49
  94. package/src/domain/position/timeout-reserved.js +162 -0
  95. package/src/domain/timeout/index.js +26 -2
  96. package/src/domain/transfer/index.js +22 -5
  97. package/src/domain/transfer/transform.js +19 -6
  98. package/src/handlers/admin/handler.js +0 -2
  99. package/src/handlers/bulk/fulfil/handler.js +5 -5
  100. package/src/handlers/bulk/get/handler.js +5 -5
  101. package/src/handlers/bulk/prepare/handler.js +9 -9
  102. package/src/handlers/bulk/processing/handler.js +8 -7
  103. package/src/handlers/bulk/shared/validator.js +1 -1
  104. package/src/handlers/positions/handler.js +23 -10
  105. package/src/handlers/positions/handlerBatch.js +54 -26
  106. package/src/handlers/register.js +2 -1
  107. package/src/handlers/timeouts/handler.js +212 -68
  108. package/src/handlers/transfers/FxFulfilService.js +387 -0
  109. package/src/handlers/transfers/createRemittanceEntity.js +106 -0
  110. package/src/handlers/transfers/dto.js +53 -0
  111. package/src/handlers/transfers/handler.js +609 -571
  112. package/src/handlers/transfers/prepare.js +572 -0
  113. package/src/handlers/transfers/validator.js +75 -14
  114. package/src/lib/cache.js +1 -1
  115. package/src/lib/config.js +6 -3
  116. package/src/lib/healthCheck/subServiceHealth.js +12 -2
  117. package/src/lib/proxyCache.js +131 -0
  118. package/src/models/bulkTransfer/facade.js +58 -82
  119. package/src/models/fxTransfer/duplicateCheck.js +153 -0
  120. package/src/models/fxTransfer/fxTransfer.js +578 -0
  121. package/src/models/fxTransfer/fxTransferError.js +53 -0
  122. package/src/models/fxTransfer/fxTransferExtension.js +41 -0
  123. package/src/models/fxTransfer/fxTransferTimeout.js +68 -0
  124. package/src/models/fxTransfer/index.js +15 -0
  125. package/src/models/fxTransfer/stateChange.js +47 -0
  126. package/src/models/fxTransfer/watchList.js +49 -0
  127. package/src/models/ledgerAccountType/ledgerAccountType.js +8 -32
  128. package/src/models/misc/segment.js +0 -1
  129. package/src/models/participant/externalParticipant.js +96 -0
  130. package/src/models/participant/externalParticipantCached.js +148 -0
  131. package/src/models/participant/facade.js +192 -123
  132. package/src/models/participant/participant.js +2 -1
  133. package/src/models/participant/participantCurrency.js +1 -1
  134. package/src/models/participant/participantPosition.js +2 -8
  135. package/src/models/position/batch.js +90 -1
  136. package/src/models/position/facade.js +5 -5
  137. package/src/models/position/participantPositionChanges.js +68 -0
  138. package/src/models/settlement/settlementModel.js +5 -23
  139. package/src/models/transfer/facade.js +806 -447
  140. package/src/shared/constants.js +52 -0
  141. package/src/shared/fspiopErrorFactory.js +131 -0
  142. package/src/shared/logger/index.js +8 -0
  143. package/src/shared/loggingPlugin.js +43 -0
  144. package/src/shared/plugins.js +6 -0
  145. package/src/shared/setup.js +10 -0
  146. package/test-integration.Dockerfile +1 -1
  147. package/test.Dockerfile +1 -1
@@ -0,0 +1,43 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ * ModusBox
22
+ - Vijay Kumar Guthi <vijaya.guthi@infitx.com>
23
+ --------------
24
+ ******/
25
+
26
+ 'use strict'
27
+
28
+ exports.up = function (knex) {
29
+ return knex.schema.table('fxTransferFulfilment', (t) => {
30
+ t.index('commitRequestId')
31
+ t.index('settlementWindowId')
32
+ // TODO: Need to check if this is required
33
+ t.unique(['commitRequestId', 'ilpFulfilment'])
34
+ })
35
+ }
36
+
37
+ exports.down = function (knex) {
38
+ return knex.schema.table('fxTransferFulfilment', (t) => {
39
+ t.dropIndex('transferId')
40
+ t.dropIndex('settlementWindowId')
41
+ t.unique(['transferId', 'ilpFulfilment'])
42
+ })
43
+ }
@@ -0,0 +1,47 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ * Infitx
22
+ - Kalin Krustev <kalin.krustev@infitx.com>
23
+ --------------
24
+ ******/
25
+
26
+ 'use strict'
27
+
28
+ exports.up = async (knex) => {
29
+ return await knex.schema.hasTable('fxTransferExtension').then(function(exists) {
30
+ if (!exists) {
31
+ return knex.schema.createTable('fxTransferExtension', (t) => {
32
+ t.bigIncrements('fxTransferExtensionId').primary().notNullable()
33
+ t.string('commitRequestId', 36).notNullable()
34
+ t.foreign('commitRequestId').references('commitRequestId').inTable('fxTransfer')
35
+ t.boolean('isFulfilment').defaultTo(false).notNullable()
36
+ t.boolean('isError').defaultTo(false).notNullable()
37
+ t.string('key', 128).notNullable()
38
+ t.text('value').notNullable()
39
+ t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
40
+ })
41
+ }
42
+ })
43
+ }
44
+
45
+ exports.down = function (knex) {
46
+ return knex.schema.dropTableIfExists('fxTransferExtension')
47
+ }
@@ -0,0 +1,43 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ - Eugen Klymniuk <eugen.klymniuk@infitx.com>
22
+ --------------
23
+ ******/
24
+
25
+ 'use strict'
26
+
27
+ exports.up = async (knex) => {
28
+ return await knex.schema.hasTable('fxTransferTimeout').then(function(exists) {
29
+ if (!exists) {
30
+ return knex.schema.createTable('fxTransferTimeout', (t) => {
31
+ t.bigIncrements('fxTransferTimeoutId').primary().notNullable()
32
+ t.string('commitRequestId', 36).notNullable()
33
+ t.foreign('commitRequestId').references('commitRequestId').inTable('fxTransfer')
34
+ t.dateTime('expirationDate').notNullable()
35
+ t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
36
+ })
37
+ }
38
+ })
39
+ }
40
+
41
+ exports.down = function (knex) {
42
+ return knex.schema.dropTableIfExists('fxTransferTimeout')
43
+ }
@@ -0,0 +1,37 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ - Eugen Klymniuk <eugen.klymniuk@infitx.com>
22
+ --------------
23
+ ******/
24
+
25
+ 'use strict'
26
+
27
+ exports.up = function (knex) {
28
+ return knex.schema.table('fxTransferTimeout', (t) => {
29
+ t.unique('commitRequestId')
30
+ })
31
+ }
32
+
33
+ exports.down = function (knex) {
34
+ return knex.schema.table('fxTransferTimeout', (t) => {
35
+ t.dropUnique('commitRequestId')
36
+ })
37
+ }
@@ -0,0 +1,44 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ - Eugen Klymniuk <eugen.klymniuk@infitx.com>
22
+ --------------
23
+ ******/
24
+
25
+ 'use strict'
26
+
27
+ exports.up = async (knex) => {
28
+ return await knex.schema.hasTable('fxTransferError').then(function(exists) {
29
+ if (!exists) {
30
+ return knex.schema.createTable('fxTransferError', (t) => {
31
+ t.string('commitRequestId', 36).primary().notNullable()
32
+ t.bigInteger('fxTransferStateChangeId').unsigned().notNullable()
33
+ t.foreign('fxTransferStateChangeId').references('fxTransferStateChangeId').inTable('fxTransferStateChange')
34
+ t.integer('errorCode').unsigned().notNullable()
35
+ t.string('errorDescription', 128).notNullable()
36
+ t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
37
+ })
38
+ }
39
+ })
40
+ }
41
+
42
+ exports.down = function (knex) {
43
+ return knex.schema.dropTableIfExists('fxTransferError')
44
+ }
@@ -0,0 +1,37 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ - Eugen Klymniuk <eugen.klymniuk@infitx.com>
22
+ --------------
23
+ ******/
24
+
25
+ 'use strict'
26
+
27
+ exports.up = function (knex) {
28
+ return knex.schema.table('fxTransferError', (t) => {
29
+ t.index('fxTransferStateChangeId')
30
+ })
31
+ }
32
+
33
+ exports.down = function (knex) {
34
+ return knex.schema.table('fxTransferError', (t) => {
35
+ t.dropIndex('fxTransferStateChangeId')
36
+ })
37
+ }
@@ -0,0 +1,52 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ * INFITX
22
+ - Vijay Kumar Guthi <vijaya.guthi@infitx.com>
23
+ --------------
24
+ ******/
25
+
26
+ 'use strict'
27
+
28
+ exports.up = async (knex) => {
29
+ return await knex.schema.hasTable('fxTransferParticipant').then(function(exists) {
30
+ if (!exists) {
31
+ return knex.schema.createTable('fxTransferParticipant', (t) => {
32
+ t.bigIncrements('fxTransferParticipantId').primary().notNullable()
33
+ t.string('commitRequestId', 36).notNullable()
34
+ t.foreign('commitRequestId').references('commitRequestId').inTable('fxTransfer')
35
+ t.integer('participantCurrencyId').unsigned().notNullable()
36
+ t.foreign('participantCurrencyId').references('participantCurrencyId').inTable('participantCurrency')
37
+ t.integer('transferParticipantRoleTypeId').unsigned().notNullable()
38
+ t.foreign('transferParticipantRoleTypeId').references('transferParticipantRoleTypeId').inTable('transferParticipantRoleType')
39
+ t.integer('ledgerEntryTypeId').unsigned().notNullable()
40
+ t.foreign('ledgerEntryTypeId').references('ledgerEntryTypeId').inTable('ledgerEntryType')
41
+ t.integer('fxParticipantCurrencyTypeId').unsigned()
42
+ t.foreign('fxParticipantCurrencyTypeId').references('fxParticipantCurrencyTypeId').inTable('fxParticipantCurrencyType')
43
+ t.decimal('amount', 18, 4).notNullable()
44
+ t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
45
+ })
46
+ }
47
+ })
48
+ }
49
+
50
+ exports.down = function (knex) {
51
+ return knex.schema.dropTableIfExists('fxTransferParticipant')
52
+ }
@@ -0,0 +1,44 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ * INFITX
22
+ - Vijay Kumar Guthi <vijaya.guthi@infitx.com>
23
+ --------------
24
+ ******/
25
+
26
+ 'use strict'
27
+
28
+ exports.up = function (knex) {
29
+ return knex.schema.table('fxTransferParticipant', (t) => {
30
+ t.index('commitRequestId')
31
+ t.index('participantCurrencyId')
32
+ t.index('transferParticipantRoleTypeId')
33
+ t.index('ledgerEntryTypeId')
34
+ })
35
+ }
36
+
37
+ exports.down = function (knex) {
38
+ return knex.schema.table('fxTransferParticipant', (t) => {
39
+ t.dropIndex('commitRequestId')
40
+ t.dropIndex('participantCurrencyId')
41
+ t.dropIndex('transferParticipantRoleTypeId')
42
+ t.dropIndex('ledgerEntryTypeId')
43
+ })
44
+ }
@@ -0,0 +1,52 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ * INFITX
22
+ - Vijay Kumar Guthi <vijaya.guthi@infitx.com>
23
+ --------------
24
+ ******/
25
+
26
+ 'use strict'
27
+
28
+ exports.up = async (knex) => {
29
+ return await knex.schema.hasTable('fxTransferParticipant').then(function(exists) {
30
+ if (exists) {
31
+ return knex.schema.alterTable('fxTransferParticipant', (t) => {
32
+ t.integer('participantId').unsigned().notNullable()
33
+ // Disabling this as its throwing error while running the migration with existing data in the table
34
+ // t.foreign('participantId').references('participantId').inTable('participant')
35
+ t.index('participantId')
36
+ t.integer('participantCurrencyId').unsigned().nullable().alter()
37
+ })
38
+ }
39
+ })
40
+ }
41
+
42
+ exports.down = async (knex) => {
43
+ return await knex.schema.hasTable('fxTransferParticipant').then(function(exists) {
44
+ if (exists) {
45
+ return knex.schema.alterTable('fxTransferParticipant', (t) => {
46
+ t.dropIndex('participantId')
47
+ t.dropColumn('participantId')
48
+ t.integer('participantCurrencyId').unsigned().notNullable().alter()
49
+ })
50
+ }
51
+ })
52
+ }
@@ -0,0 +1,46 @@
1
+ /*****
2
+ License
3
+ --------------
4
+ Copyright © 2017 Bill & Melinda Gates Foundation
5
+ 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
6
+ http://www.apache.org/licenses/LICENSE-2.0
7
+ 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.
8
+ Contributors
9
+ --------------
10
+ This is the official list of the Mojaloop project contributors for this file.
11
+ Names of the original copyright holders (individuals or organizations)
12
+ should be listed with a '*' in the first column. People who have
13
+ contributed from an organization can be listed under the organization
14
+ that actually holds the copyright for their contributions (see the
15
+ Gates Foundation organization for an example). Those individuals should have
16
+ their names indented and be marked with a '-'. Email address can be added
17
+ optionally within square brackets <email>.
18
+ * Gates Foundation
19
+ - Name Surname <name.surname@gatesfoundation.com>
20
+
21
+ * INFITX
22
+ - Vijay Kumar Guthi <vijaya.guthi@infitx.com>
23
+ --------------
24
+ ******/
25
+
26
+ 'use strict'
27
+
28
+ exports.up = async (knex) => {
29
+ return await knex.schema.hasTable('participantPositionChange').then(function(exists) {
30
+ if (exists) {
31
+ return knex.schema.alterTable('participantPositionChange', (t) => {
32
+ t.bigInteger('transferStateChangeId').unsigned().defaultTo(null).alter()
33
+ t.bigInteger('fxTransferStateChangeId').unsigned().defaultTo(null)
34
+ t.foreign('fxTransferStateChangeId').references('fxTransferStateChangeId').inTable('fxTransferStateChange')
35
+ })
36
+ }
37
+ })
38
+ }
39
+
40
+ exports.down = function (knex) {
41
+ return knex.schema.alterTable('participantPositionChange', (t) => {
42
+ t.dropForeign('fxTransferStateChangeId')
43
+ t.dropColumn('fxTransferStateChangeId')
44
+ t.bigInteger('transferStateChangeId').unsigned().notNullable().alter()
45
+ })
46
+ }
@@ -44,62 +44,56 @@ const tableNameSuffix = Time.getYMDString(new Date())
44
44
  */
45
45
  const migrateData = async (knex) => {
46
46
  return knex.transaction(async trx => {
47
- try {
48
- let exists = false
49
- exists = await knex.schema.hasTable(`transferExtension${tableNameSuffix}`)
50
- if (exists) {
51
- await knex.transacting(trx).raw(`
52
- insert into transferExtension (transferExtensionId, transferId, \`key\`, \`value\`, isFulfilment, isError, createdDate)
53
- select te.transferExtensionId, te.transferId, te.\`key\`, te.\`value\`,
54
- case when te.transferFulfilmentId is null then 0 else 1 end,
55
- case when te.transferErrorId is null then 0 else 1 end,
56
- te.createdDate
57
- from transferExtension${tableNameSuffix} as te`)
58
- }
59
- exists = await knex.schema.hasTable(`transferFulfilmentDuplicateCheck${tableNameSuffix}`) &&
60
- await knex.schema.hasTable(`transferFulfilment${tableNameSuffix}`)
61
- if (exists) {
62
- await knex.transacting(trx).raw(`
63
- insert into transferFulfilmentDuplicateCheck (transferId, \`hash\`, createdDate)
64
- select transferId, \`hash\`, createdDate from transferFulfilmentDuplicateCheck${tableNameSuffix}
65
- where transferFulfilmentId in(
66
- select transferFulfilmentId
67
- from (
68
- select transferFulfilmentId, transferId, ilpFulfilment, completedDate, isValid, settlementWindowId, createdDate,
69
- row_number() over(partition by transferId order by isValid desc, createdDate) rowNumber
70
- from transferFulfilment${tableNameSuffix}) t
71
- where t.rowNumber = 1)`)
72
- }
73
- exists = await knex.schema.hasTable(`transferFulfilment${tableNameSuffix}`)
74
- if (exists) {
75
- await knex.transacting(trx).raw(`
76
- insert into transferFulfilment (transferId, ilpFulfilment, completedDate, isValid, settlementWindowId, createdDate)
77
- select t.transferId, t.ilpFulfilment, t.completedDate, t.isValid, t.settlementWindowId, t.createdDate
47
+ let exists = false
48
+ exists = await knex.schema.hasTable(`transferExtension${tableNameSuffix}`)
49
+ if (exists) {
50
+ await knex.transacting(trx).raw(`
51
+ insert into transferExtension (transferExtensionId, transferId, \`key\`, \`value\`, isFulfilment, isError, createdDate)
52
+ select te.transferExtensionId, te.transferId, te.\`key\`, te.\`value\`,
53
+ case when te.transferFulfilmentId is null then 0 else 1 end,
54
+ case when te.transferErrorId is null then 0 else 1 end,
55
+ te.createdDate
56
+ from transferExtension${tableNameSuffix} as te`)
57
+ }
58
+ exists = await knex.schema.hasTable(`transferFulfilmentDuplicateCheck${tableNameSuffix}`) &&
59
+ await knex.schema.hasTable(`transferFulfilment${tableNameSuffix}`)
60
+ if (exists) {
61
+ await knex.transacting(trx).raw(`
62
+ insert into transferFulfilmentDuplicateCheck (transferId, \`hash\`, createdDate)
63
+ select transferId, \`hash\`, createdDate from transferFulfilmentDuplicateCheck${tableNameSuffix}
64
+ where transferFulfilmentId in(
65
+ select transferFulfilmentId
78
66
  from (
79
67
  select transferFulfilmentId, transferId, ilpFulfilment, completedDate, isValid, settlementWindowId, createdDate,
80
68
  row_number() over(partition by transferId order by isValid desc, createdDate) rowNumber
81
69
  from transferFulfilment${tableNameSuffix}) t
82
- where t.rowNumber = 1`)
83
- }
84
- exists = await knex.schema.hasTable(`transferErrorDuplicateCheck${tableNameSuffix}`)
85
- if (exists) {
86
- await knex.transacting(trx).raw(`
87
- insert into transferErrorDuplicateCheck (transferId, \`hash\`, createdDate)
88
- select transferId, \`hash\`, createdDate
89
- from transferErrorDuplicateCheck${tableNameSuffix}`)
90
- }
91
- exists = await knex.schema.hasTable(`transferError${tableNameSuffix}`)
92
- if (exists) {
93
- await knex.transacting(trx).raw(`
94
- insert into transferError (transferId, transferStateChangeId, errorCode, errorDescription, createdDate)
95
- select tsc.transferId, te.transferStateChangeId, te.errorCode, te.errorDescription, te.createdDate
96
- from transferError${tableNameSuffix} te
97
- join transferStateChange tsc on tsc.transferStateChangeId = te.transferStateChangeId`)
98
- }
99
- await trx.commit
100
- } catch (err) {
101
- await trx.rollback
102
- throw err
70
+ where t.rowNumber = 1)`)
71
+ }
72
+ exists = await knex.schema.hasTable(`transferFulfilment${tableNameSuffix}`)
73
+ if (exists) {
74
+ await knex.transacting(trx).raw(`
75
+ insert into transferFulfilment (transferId, ilpFulfilment, completedDate, isValid, settlementWindowId, createdDate)
76
+ select t.transferId, t.ilpFulfilment, t.completedDate, t.isValid, t.settlementWindowId, t.createdDate
77
+ from (
78
+ select transferFulfilmentId, transferId, ilpFulfilment, completedDate, isValid, settlementWindowId, createdDate,
79
+ row_number() over(partition by transferId order by isValid desc, createdDate) rowNumber
80
+ from transferFulfilment${tableNameSuffix}) t
81
+ where t.rowNumber = 1`)
82
+ }
83
+ exists = await knex.schema.hasTable(`transferErrorDuplicateCheck${tableNameSuffix}`)
84
+ if (exists) {
85
+ await knex.transacting(trx).raw(`
86
+ insert into transferErrorDuplicateCheck (transferId, \`hash\`, createdDate)
87
+ select transferId, \`hash\`, createdDate
88
+ from transferErrorDuplicateCheck${tableNameSuffix}`)
89
+ }
90
+ exists = await knex.schema.hasTable(`transferError${tableNameSuffix}`)
91
+ if (exists) {
92
+ await knex.transacting(trx).raw(`
93
+ insert into transferError (transferId, transferStateChangeId, errorCode, errorDescription, createdDate)
94
+ select tsc.transferId, te.transferStateChangeId, te.errorCode, te.errorDescription, te.createdDate
95
+ from transferError${tableNameSuffix} te
96
+ join transferStateChange tsc on tsc.transferStateChangeId = te.transferStateChangeId`)
103
97
  }
104
98
  })
105
99
  }