Skip to content

Commit

Permalink
feat: added db migration scripts for fx
Browse files Browse the repository at this point in the history
  • Loading branch information
vijayg10 committed Nov 8, 2023
1 parent bdff6c7 commit 0b62904
Show file tree
Hide file tree
Showing 10 changed files with 406 additions and 0 deletions.
42 changes: 42 additions & 0 deletions migrations/600100_fxTransferDuplicateCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*****
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.
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]>
* INFITX
- Vijay Kumar Guthi <[email protected]>
--------------
******/

'use strict'

exports.up = async (knex) => {
return await knex.schema.hasTable('fxTransferDuplicateCheck').then(function(exists) {
if (!exists) {
return knex.schema.createTable('fxTransferDuplicateCheck', (t) => {
t.string('commitRequestId', 36).primary().notNullable()

This comment has been minimized.

Copy link
@geka-evk

geka-evk Nov 10, 2023

Contributor

maybe, it's better to have the same table structure as transferDuplicateCheck (use transferId field instead on commitRequestId)?
Or even use the same table (just add a new optional boolean field isFx)

t.string('hash', 256).notNullable()
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
})
}
})
}

exports.down = function (knex) {
return knex.schema.dropTableIfExists('fxTransferDuplicateCheck')
}
51 changes: 51 additions & 0 deletions migrations/600200_fxTransfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*****
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.
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]>
* INFITX
- Vijay Kumar Guthi <[email protected]>
--------------
******/

'use strict'

exports.up = async (knex) => {
return await knex.schema.hasTable('fxTransfer').then(function(exists) {
if (!exists) {
return knex.schema.createTable('fxTransfer', (t) => {
t.string('commitRequestId', 36).primary().notNullable()
t.foreign('commitRequestId').references('commitRequestId').inTable('fxTransferDuplicateCheck')
t.string('determiningTransferId', 36).defaultTo(null).nullable()
t.decimal('sourceAmount', 18, 4).notNullable()
t.decimal('targetAmount', 18, 4).notNullable()
t.string('sourceCurrency', 3).notNullable()
t.foreign('sourceCurrency').references('currencyId').inTable('currency')
t.string('targetCurrency', 3).notNullable()
t.foreign('targetCurrency').references('currencyId').inTable('currency')
t.string('ilpCondition', 256).notNullable()
t.dateTime('expirationDate').notNullable()
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
})
}
})
}

exports.down = function (knex) {
return knex.schema.dropTableIfExists('fxTransfer')
}
40 changes: 40 additions & 0 deletions migrations/600201_fxTransfer-indexes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*****
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.
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]>
* INFITX
- Vijay Kumar Guthi <[email protected]>
--------------
******/

'use strict'

exports.up = function (knex) {
return knex.schema.table('fxTransfer', (t) => {
t.index('sourceCurrency')
t.index('targetCurrency')
})
}

exports.down = function (knex) {
return knex.schema.table('fxTransfer', (t) => {
t.dropIndex('sourceCurrency')
t.dropIndex('targetCurrency')
})
}
46 changes: 46 additions & 0 deletions migrations/600400_fxTransferStateChange.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*****
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.
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]>
* INFITX
- Vijay Kumar Guthi <[email protected]>
--------------
******/

'use strict'

exports.up = async (knex) => {
return await knex.schema.hasTable('fxTransferStateChange').then(function(exists) {
if (!exists) {
return knex.schema.createTable('fxTransferStateChange', (t) => {
t.bigIncrements('fxTransferStateChangeId').primary().notNullable()
t.string('commitRequestId', 36).notNullable()
t.foreign('commitRequestId').references('commitRequestId').inTable('fxTransfer')
t.string('transferStateId', 50).notNullable()
t.foreign('transferStateId').references('transferStateId').inTable('transferState')
t.string('reason', 512).defaultTo(null).nullable()
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
})
}
})
}

exports.down = function (knex) {
return knex.schema.dropTableIfExists('fxTransferStateChange')
}
40 changes: 40 additions & 0 deletions migrations/600401_fxTransferStateChange-indexes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*****
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.
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]>
* INFITX
- Vijay Kumar Guthi <[email protected]>
--------------
******/

'use strict'

exports.up = function (knex) {
return knex.schema.table('fxTransferStateChange', (t) => {
t.index('commitRequestId')
t.index('transferStateId')
})
}

exports.down = function (knex) {
return knex.schema.table('fxTransferStateChange', (t) => {
t.dropIndex('commitRequestId')
t.dropIndex('transferStateId')
})
}
44 changes: 44 additions & 0 deletions migrations/600501_fxWatchList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*****
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.
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]>
* INFITX
- Vijay Kumar Guthi <[email protected]>
--------------
******/

'use strict'

exports.up = async (knex) => {
return await knex.schema.hasTable('fxWatchList').then(function(exists) {
if (!exists) {
return knex.schema.createTable('fxWatchList', (t) => {
t.bigIncrements('fxWatchListId').primary().notNullable()
t.string('commitRequestId', 36).notNullable()
t.foreign('commitRequestId').references('commitRequestId').inTable('fxTransfer')
t.string('transferId', 36).notNullable()
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
})
}
})
}

exports.down = function (knex) {
return knex.schema.dropTableIfExists('fxWatchList')
}
40 changes: 40 additions & 0 deletions migrations/600502_fxWatchList-indexes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*****
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.
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]>
* INFITX
- Vijay Kumar Guthi <[email protected]>
--------------
******/

'use strict'

exports.up = function (knex) {
return knex.schema.table('fxWatchList', (t) => {
t.index('commitRequestId')
t.index('transferId')
})
}

exports.down = function (knex) {
return knex.schema.table('fxWatchList', (t) => {
t.dropIndex('commitRequestId')
t.dropIndex('transferId')
})
}
50 changes: 50 additions & 0 deletions migrations/610200_fxTransferParticipant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*****
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.
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]>
* INFITX
- Vijay Kumar Guthi <[email protected]>
--------------
******/

'use strict'

exports.up = async (knex) => {
return await knex.schema.hasTable('fxTransferParticipant').then(function(exists) {
if (!exists) {
return knex.schema.createTable('fxTransferParticipant', (t) => {
t.bigIncrements('fxTransferParticipantId').primary().notNullable()
t.string('commitRequestId', 36).notNullable()
t.foreign('commitRequestId').references('commitRequestId').inTable('fxTransfer')
t.integer('participantCurrencyId').unsigned().notNullable()
t.foreign('participantCurrencyId').references('participantCurrencyId').inTable('participantCurrency')
t.integer('transferParticipantRoleTypeId').unsigned().notNullable()
t.foreign('transferParticipantRoleTypeId').references('transferParticipantRoleTypeId').inTable('transferParticipantRoleType')
t.integer('ledgerEntryTypeId').unsigned().notNullable()
t.foreign('ledgerEntryTypeId').references('ledgerEntryTypeId').inTable('ledgerEntryType')
t.decimal('amount', 18, 4).notNullable()
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
})
}
})
}

exports.down = function (knex) {
return knex.schema.dropTableIfExists('fxTransferParticipant')
}
Loading

0 comments on commit 0b62904

Please sign in to comment.