-
Notifications
You must be signed in to change notification settings - Fork 90
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(backend): rename "payment pointer" tables & columns to use "wallet address" #1937
Merged
njlie
merged 8 commits into
nl-open-payments-updates
from
nl-rename-payment-pointer-tables
Oct 12, 2023
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
09c3331
feat(backend): rename payment pointer tables & payment columns to use…
4749733
feat: rename column in walletAddressKeys
83f3c42
feat: remove .then in table column rename
d8ea382
chore: formatting
njlie d1cca1c
feat: rename paymentPointer keys in webhook event json column
njlie dba4176
feat: rename more data fields, type values
njlie bc761b0
feat: rename/drop indices & constraints
njlie b7fc854
feat: update rollbacks
njlie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
packages/backend/migrations/20230918113102_rename_payment_pointer_tables.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.up = function (knex) { | ||
return Promise.all([ | ||
knex.schema.renameTable('paymentPointers', 'walletAddresses'), | ||
knex.schema.renameTable('paymentPointerKeys', 'walletAddressKeys'), | ||
knex.schema.alterTable('walletAddressKeys', function (table) { | ||
table.renameColumn('paymentPointerId', 'walletAddressId') | ||
table.foreign('walletAddressId').references('walletAddresses.id') | ||
}), | ||
knex.schema.alterTable('quotes', function (table) { | ||
table.renameColumn('paymentPointerId', 'walletAddressId') | ||
table.foreign('walletAddressId').references('walletAddresses.id') | ||
table.index(['walletAddressId', 'createdAt', 'id']) | ||
}), | ||
knex.schema.alterTable('incomingPayments', function (table) { | ||
table.renameColumn('paymentPointerId', 'walletAddressId') | ||
table.foreign('walletAddressId').references('walletAddresses.id') | ||
table.index(['walletAddressId', 'createdAt', 'id']) | ||
}), | ||
knex.schema.alterTable('outgoingPayments', function (table) { | ||
table.renameColumn('paymentPointerId', 'walletAddressId') | ||
table.foreign('walletAddressId').references('walletAddresses.id') | ||
table.index(['walletAddressId', 'createdAt', 'id']) | ||
}), | ||
knex('webhookEvents') | ||
.update({ | ||
// renames paymentPointer keys (if any) to walletAddress in data json column | ||
data: knex.raw( | ||
"data - 'paymentPointer' || json_build_object('walletAddress', data->'paymentPointer')" | ||
) | ||
}) | ||
.whereRaw("data \\? 'paymentPonter'") | ||
BlairCurrey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return Promise.all([ | ||
knex.schema.renameTable('walletAddresses', 'paymentPointers'), | ||
knex.schema.renameTable('walletAddressKeys', 'paymentPointerKeys'), | ||
knex.schema.alterTable('paymentPointerKeys', function (table) { | ||
table.renameColumn('walletAddressId', 'paymentPointerId') | ||
table.foreign('paymentPointerId').references('paymentPointers.id') | ||
}), | ||
knex.schema.alterTable('quotes', function (table) { | ||
table.renameColumn('walletAddressId', 'paymentPointerId') | ||
table.foreign('paymentPointerId').references('paymentPointers.id') | ||
table.index(['paymentPointerId', 'createdAt', 'id']) | ||
}), | ||
knex.schema.alterTable('incomingPayments', function (table) { | ||
table.renameColumn('walletAddressId', 'paymentPointerId') | ||
table.foreign('paymentPointerId').references('paymentPointers.id') | ||
table.index(['paymentPointerId', 'createdAt', 'id']) | ||
}), | ||
knex.schema.alterTable('outgoingPayments', function (table) { | ||
table.renameColumn('walletAddressId', 'paymentPointerId') | ||
table.foreign('paymentPointerId').references('paymentPointers.id') | ||
table.index(['paymentPointerId', 'createdAt', 'id']) | ||
}), | ||
knex('webhookEvents') | ||
.update({ | ||
data: knex.raw( | ||
"data - 'walletAddress' || json_build_object('paymentPointer', data->'walletAddress')" | ||
) | ||
}) | ||
.whereRaw("data \\? 'walletAddress'") | ||
]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not actually sure, what happens to the existing
paymentPointer.id
foreign key here? Does it get properly handled in the rename, or dropped?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also applies the indexes (not pictured above) in line 16:
table.index(['walletAddressId', 'createdAt', 'id'])
.Looks like the migration is duplicating these. Two fkey constraints with different fkey names but the same relationship. I think we can just remove the
table.foreign('walletAddressId').references('walletAddresses.id')
line (and the indexes). This is what I see inIndexes
andForeign-key constraints:
from doing a\d quotes
after this migration.quote:
and here is some of
\d "walletAddresses"
for good measure (see the duplicate quote fkey):There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually instead of removing these lines we might want to just drop the old one. This way we end up with
"quotes_walletaddressid_foreign" FOREIGN KEY ("walletAddressId") REFERENCES "walletAddresses"(id)
instead of"quotes_paymentpointerid_foreign" FOREIGN KEY ("walletAddressId") REFERENCES "walletAddresses"(id).
So doing like: