Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(mojaloop/#3885): add migrations for storing fxQuotes #1076

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion audit-ci.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"GHSA-7hx8-2rxv-66xv", // https://github.com/advisories/GHSA-7hx8-2rxv-66xv
"GHSA-c429-5p7v-vgjp", // https://github.com/advisories/GHSA-c429-5p7v-vgjp
"GHSA-g64q-3vg8-8f93", // https://github.com/advisories/GHSA-g64q-3vg8-8f93
"GHSA-mg85-8mv5-ffjr" // https://github.com/advisories/GHSA-mg85-8mv5-ffjr
"GHSA-mg85-8mv5-ffjr", // https://github.com/advisories/GHSA-mg85-8mv5-ffjr
"GHSA-8hc4-vh64-cxmj" // https://github.com/advisories/GHSA-8hc4-vh64-cxmj
]
}
20 changes: 20 additions & 0 deletions migrations/950109_fxQuote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Notes: these changes are required for the quoting-service and are not used by central-ledger
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxQuote').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxQuote', (t) => {
t.string('conversionRequestId', 36).primary().notNullable()

// time keeping
t.dateTime('expirationDate').defaultTo(null).nullable().comment('Optional expiration for the requested transaction')
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable().comment('System dateTime stamp pertaining to the inserted record')
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('fxQuote')
}
26 changes: 26 additions & 0 deletions migrations/950110_fxQuoteResponse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxQuoteResponse').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxQuoteResponse', (t) => {
t.bigIncrements('fxQuoteResponseId').primary().notNullable()

// reference to the original fxQuote
t.string('conversionRequestId', 36).notNullable()
t.foreign('conversionRequestId').references('conversionRequestId').inTable('fxQuote')

// ilpCondition sent in FXP response
t.string('ilpCondition', 256).notNullable()

// time keeping
t.dateTime('expirationDate').defaultTo(null).nullable().comment('Optional expiration for the requested transaction')
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable().comment('System dateTime stamp pertaining to the inserted record')
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('fxQuoteResponse')
}
23 changes: 23 additions & 0 deletions migrations/950111_fxQuoteError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Notes: these changes are required for the quoting-service and are not used by central-ledger
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxQuoteError').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxQuoteError', (t) => {
t.bigIncrements('fxQuoteErrorId').primary().notNullable()
t.string('conversionRequestId', 36).notNullable()
t.foreign('conversionRequestId').references('conversionRequestId').inTable('fxQuote')
t.bigInteger('fxQuoteResponseId').unsigned().defaultTo(null).nullable().comment('The response to the initial fxQuote')
t.foreign('fxQuoteResponseId').references('fxQuoteResponseId').inTable('fxQuoteResponse')
t.integer('errorCode').unsigned().notNullable()
t.string('errorDescription', 128).notNullable()
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable()
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('quoteError')
}
18 changes: 18 additions & 0 deletions migrations/950113_fxQuoteDuplicateCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Notes: these changes are required for the quoting-service and are not used by central-ledger
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxQuoteDuplicateCheck').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxQuoteDuplicateCheck', (t) => {
t.string('conversionRequestId', 36).primary().notNullable()
t.string('hash', 1024).defaultTo(null).nullable().comment('hash value received for the quote request')
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable().comment('System dateTime stamp pertaining to the inserted record')
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('fxQuoteDuplicateCheck')
}
21 changes: 21 additions & 0 deletions migrations/950114_fxQuoteResponseDuplicateCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Notes: these changes are required for the quoting-service and are not used by central-ledger
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxQuoteResponseDuplicateCheck').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxQuoteResponseDuplicateCheck', (t) => {
t.bigIncrements('fxQuoteResponseId').primary().unsigned().comment('The response to the initial quote')
t.foreign('fxQuoteResponseId').references('fxQuoteResponseId').inTable('fxQuoteResponse')
t.string('conversionRequestId', 36).notNullable()
t.foreign('conversionRequestId').references('conversionRequestId').inTable('fxQuote')
t.string('hash', 255).defaultTo(null).nullable().comment('hash value received for the quote response')
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable().comment('System dateTime stamp pertaining to the inserted record')
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('fxQuoteResponseDuplicateCheck')
}
33 changes: 33 additions & 0 deletions migrations/950115_fxQuoteConversionTerms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxQuoteConversionTerms').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxQuoteConversionTerms', (t) => {
t.string('conversionId').primary().notNullable()

// reference to the original fxQuote
t.string('conversionRequestId', 36).notNullable()
t.foreign('conversionRequestId').references('conversionRequestId').inTable('fxQuote')

t.integer('amountTypeId').unsigned().notNullable().comment('This is part of the transaction type that contains valid elements for - Amount Type')
t.foreign('amountTypeId').references('amountTypeId').inTable('amountType')
t.string('initiatingFsp', 255)
t.string('counterPartyFsp', 255)
t.decimal('sourceAmount', 18, 4).notNullable()
t.string('sourceCurrency', 3).notNullable()
t.foreign('sourceCurrency').references('currencyId').inTable('currency')
t.decimal('targetAmount', 18, 4).notNullable()
t.string('targetCurrency', 3).notNullable()
t.foreign('targetCurrency').references('currencyId').inTable('currency')

// time keeping
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable().comment('System dateTime stamp pertaining to the inserted record')
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('fxQuoteConversionTerms')
}
21 changes: 21 additions & 0 deletions migrations/950116_fxQuoteConversionTermExtension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Notes: these changes are required for the quoting-service and are not used by central-ledger
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxQuoteConversionTermExtension').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxQuoteConversionTermExtension', (t) => {
t.bigIncrements('fxQuoteConversionTermExtension').primary().notNullable()
t.string('conversionId', 36).notNullable()
t.foreign('conversionId').references('conversionId').inTable('fxQuoteConversionTerms')
t.string('key', 128).notNullable()
t.text('value').notNullable()
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable().comment('System dateTime stamp pertaining to the inserted record')
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('fxQuoteConversionTermExtension')
}
37 changes: 37 additions & 0 deletions migrations/950117_fxQuoteResponseConversionTerms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxQuoteResponseConversionTerms').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxQuoteResponseConversionTerms', (t) => {
t.string('conversionId').primary().notNullable()

// reference to the original fxQuote
t.string('conversionRequestId', 36).notNullable()
t.foreign('conversionRequestId').references('conversionRequestId').inTable('fxQuote')

// reference to the original fxQuoteResponse
t.bigIncrements('fxQuoteResponseId', 36).notNullable()
t.foreign('fxQuoteResponseId').references('fxQuoteResponseId').inTable('fxQuoteResponse')

t.integer('amountTypeId').unsigned().notNullable().comment('This is part of the transaction type that contains valid elements for - Amount Type')
t.foreign('amountTypeId').references('amountTypeId').inTable('amountType')
t.string('initiatingFsp', 255)
t.string('counterPartyFsp', 255)
t.decimal('sourceAmount', 18, 4).notNullable()
t.string('sourceCurrency', 3).notNullable()
t.foreign('sourceCurrency').references('currencyId').inTable('currency')
t.decimal('targetAmount', 18, 4).notNullable()
t.string('targetCurrency', 3).notNullable()
t.foreign('targetCurrency').references('currencyId').inTable('currency')

// time keeping
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable().comment('System dateTime stamp pertaining to the inserted record')
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('fxQuoteResponseConversionTerms')
}
21 changes: 21 additions & 0 deletions migrations/950118_fxQuoteResponseConversionTermExtension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Notes: these changes are required for the quoting-service and are not used by central-ledger
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxQuoteResponseConversionTermExtension').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxQuoteResponseConversionTermExtension', (t) => {
t.bigIncrements('fxQuoteResponseConversionTermExtension').primary().notNullable()
t.string('conversionId', 36).notNullable()
t.foreign('conversionId').references('conversionId').inTable('fxQuoteResponseConversionTerms')
t.string('key', 128).notNullable()
t.text('value').notNullable()
t.dateTime('createdDate').defaultTo(knex.fn.now()).notNullable().comment('System dateTime stamp pertaining to the inserted record')
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('fxQuoteResponseConversionTermExtension')
}
27 changes: 27 additions & 0 deletions migrations/950119_fxCharge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict'

exports.up = (knex) => {
return knex.schema.hasTable('fxCharge').then((exists) => {
if (!exists) {
return knex.schema.createTable('fxCharge', (t) => {
t.bigIncrements('fxChargeId').primary().notNullable()
t.string('chargeType', 32).notNullable().comment('A description of the charge which is being levied.')

// fxCharge should only be sent back in the response to an fxQuote
// so reference the terms in fxQuoteResponse `conversionTerms`
t.string('conversionId', 36).notNullable()
t.foreign('conversionId').references('conversionId').inTable('fxQuoteResponseConversionTerms')

t.decimal('sourceAmount', 18, 4).nullable().comment('The amount of the charge which is being levied, expressed in the source currency.')
t.string('sourceCurrency', 3).nullable().comment('The currency in which the source amount charge is being levied.')

t.decimal('targetAmount', 18, 4).nullable().comment('The amount of the charge which is being levied, expressed in the target currency.')
t.string('targetCurrency', 3).nullable().comment('The currency in which the target amount charge is being levied.')
})
}
})
}

exports.down = (knex) => {
return knex.schema.dropTableIfExists('fxCharge')
}
42 changes: 21 additions & 21 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"glob": "10.4.3",
"hapi-auth-basic": "5.0.0",
"hapi-auth-bearer-token": "8.0.0",
"hapi-swagger": "17.2.1",
"hapi-swagger": "17.3.0",
"ilp-packet": "2.2.0",
"knex": "3.1.0",
"lodash": "4.17.21",
Expand All @@ -133,7 +133,7 @@
"jsdoc": "4.0.3",
"jsonpath": "1.1.1",
"nodemon": "3.1.4",
"npm-check-updates": "17.0.3",
"npm-check-updates": "17.0.6",
"nyc": "17.0.0",
"pre-commit": "1.2.2",
"proxyquire": "2.1.3",
Expand Down