-
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
Changes from 7 commits
09c3331
4749733
83f3c42
d8ea382
d1cca1c
dba4176
bc761b0
b7fc854
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,159 @@ | ||||
/** | ||||
* @param { import("knex").Knex } knex | ||||
* @returns { Promise<void> } | ||||
*/ | ||||
exports.up = function (knex) { | ||||
return Promise.all([ | ||||
knex.schema.renameTable('paymentPointers', 'walletAddresses'), | ||||
knex.schema.alterTable('walletAddresses', function (table) { | ||||
table.foreign(['assetId']).references('assets.id') | ||||
table.unique('url') | ||||
}), | ||||
knex.raw( | ||||
'ALTER INDEX "paymentPointers_pkey" RENAME TO "walletAddresses_pkey"' | ||||
), | ||||
knex.raw( | ||||
'ALTER INDEX "paymentpointers_url_index" RENAME TO "walletAddresses_url_index"' | ||||
), | ||||
knex.raw( | ||||
'ALTER INDEX "paymentpointers_processat_index" RENAME TO "walletAddresses_processat_index"' | ||||
), | ||||
knex.raw( | ||||
'ALTER TABLE "walletAddresses" DROP CONSTRAINT "paymentpointers_url_unique"' | ||||
), | ||||
knex.raw( | ||||
'ALTER TABLE "walletAddresses" DROP CONSTRAINT "paymentpointers_assetid_foreign"' | ||||
), | ||||
knex.schema.renameTable('paymentPointerKeys', 'walletAddressKeys'), | ||||
knex.schema.alterTable('walletAddressKeys', function (table) { | ||||
table.renameColumn('paymentPointerId', 'walletAddressId') | ||||
table.foreign('walletAddressId').references('walletAddresses.id') | ||||
}), | ||||
knex.raw( | ||||
'ALTER INDEX "paymentPointerKeys_pkey" RENAME TO "walletAddressKeys_pkey"' | ||||
), | ||||
knex.raw( | ||||
'ALTER TABLE "walletAddressKeys" DROP CONSTRAINT "paymentpointerkeys_paymentpointerid_foreign"' | ||||
), | ||||
knex.schema.alterTable('quotes', function (table) { | ||||
table.dropForeign(['paymentPointerId']) | ||||
table.dropIndex(['paymentPointerId', 'createdAt', 'id']) | ||||
table.renameColumn('paymentPointerId', 'walletAddressId') | ||||
table.foreign('walletAddressId').references('walletAddresses.id') | ||||
table.index(['walletAddressId']) | ||||
table.index(['createdAt']) | ||||
table.index(['id']) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indexes are not aggregated because the original indexes weren't either. Aggregating them produces, for example:
Whereas originally the indexes were not aggregated:
So There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It seems like they are originally 1 composite index to me but maybe I'm missing something... without running this migration I see rafiki/packages/backend/migrations/20221129213751_create_outgoing_payments_table.js Line 28 in 07cff89
If they were seperate indexes I also don't think we'd need to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, they're composite. A misreading on my part earlier. So we'll keep the composite dropping & adding of these indexes. |
||||
}), | ||||
knex.schema.alterTable('incomingPayments', function (table) { | ||||
table.dropForeign(['paymentPointerId']) | ||||
table.dropIndex(['paymentPointerId', 'createdAt', 'id']) | ||||
table.renameColumn('paymentPointerId', 'walletAddressId') | ||||
table.foreign('walletAddressId').references('walletAddresses.id') | ||||
table.index(['walletAddressId']) | ||||
table.index(['createdAt']) | ||||
table.index(['id']) | ||||
}), | ||||
knex.schema.alterTable('outgoingPayments', function (table) { | ||||
table.dropForeign(['paymentPointerId']) | ||||
table.dropIndex(['paymentPointerId', 'createdAt', 'id']) | ||||
table.renameColumn('paymentPointerId', 'walletAddressId') | ||||
table.foreign('walletAddressId').references('walletAddresses.id') | ||||
table.index(['walletAddressId']) | ||||
table.index(['createdAt']) | ||||
table.index(['id']) | ||||
}), | ||||
knex('webhookEvents') | ||||
.update({ | ||||
// renames paymentPointer keys (if any) to walletAddress in data json column | ||||
data: knex.raw( | ||||
"data::jsonb - 'paymentPointer' || jsonb_build_object('walletAddress', data::jsonb->'paymentPointer')" | ||||
) | ||||
}) | ||||
.whereRaw("data->'paymentPointer' is not null"), | ||||
knex('webhookEvents') | ||||
.update({ | ||||
// renames paymentPointerId keys (if any) to walletAddressId in data json column | ||||
data: knex.raw( | ||||
"data::jsonb - 'paymentPointerId' || jsonb_build_object('walletAddressId', data::jsonb->'paymentPointerId')" | ||||
) | ||||
}) | ||||
.whereRaw("data->'paymentPointerId' is not null"), | ||||
knex('webhookEvents') | ||||
.update({ | ||||
// renames paymentPointerUrl keys (if any) to walletAddressUrl in data json column | ||||
data: knex.raw( | ||||
"data::jsonb - 'paymentPointerUrl' || jsonb_build_object('walletAddressUrl', data::jsonb->'paymentPointerUrl')" | ||||
) | ||||
}) | ||||
.whereRaw("data->'paymentPointerUrl' is not null"), | ||||
knex('webhookEvents') | ||||
.update({ | ||||
// renames payment_pointer.not_found values (if any) to wallet_address.not_found for type key in data json column | ||||
type: knex.raw("REPLACE(type, 'payment_pointer.', 'wallet_address.')") | ||||
}) | ||||
.whereLike('type', 'payment_pointer%') | ||||
]) | ||||
Comment on lines
+78
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i inserted some dummy data before this migration and this and similar all seem to be working correctly |
||||
} | ||||
|
||||
/** | ||||
* @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.dropForeign(['walletAddressId']) | ||||
table.renameColumn('walletAddressId', 'paymentPointerId') | ||||
table.foreign('paymentPointerId').references('paymentPointers.id') | ||||
}), | ||||
knex.schema.alterTable('quotes', function (table) { | ||||
table.dropForeign(['walletAddressId']) | ||||
table.dropIndex(['walletAddressId', 'createdAt', 'id']) | ||||
table.renameColumn('walletAddressId', 'paymentPointerId') | ||||
table.foreign('paymentPointerId').references('paymentPointers.id') | ||||
table.index(['paymentPointerId', 'createdAt', 'id']) | ||||
}), | ||||
knex.schema.alterTable('incomingPayments', function (table) { | ||||
table.dropForeign(['walletAddressId']) | ||||
table.dropIndex(['walletAddressId', 'createdAt', 'id']) | ||||
table.renameColumn('walletAddressId', 'paymentPointerId') | ||||
table.foreign('paymentPointerId').references('paymentPointers.id') | ||||
table.index(['paymentPointerId', 'createdAt', 'id']) | ||||
}), | ||||
knex.schema.alterTable('outgoingPayments', function (table) { | ||||
table.dropForeign(['walletAddressId']) | ||||
table.dropIndex(['walletAddressId', 'createdAt', 'id']) | ||||
table.renameColumn('walletAddressId', 'paymentPointerId') | ||||
table.foreign('paymentPointerId').references('paymentPointers.id') | ||||
table.index(['paymentPointerId', 'createdAt', 'id']) | ||||
}), | ||||
knex('webhookEvents') | ||||
.update({ | ||||
data: knex.raw( | ||||
"data::jsonb - 'walletAddress' || jsonb_build_object('paymentPointer', data::jsonb->'walletAddress')" | ||||
) | ||||
}) | ||||
.whereRaw("data->'walletAddress' is not null"), | ||||
knex('webhookEvents') | ||||
.update({ | ||||
data: knex.raw( | ||||
"data::jsonb - 'walletAddressId' || jsonb_build_object('paymentPointerId', data::jsonb->'walletAddressId')" | ||||
) | ||||
}) | ||||
.whereRaw("data->'walletAddressId' is not null"), | ||||
knex('webhookEvents') | ||||
.update({ | ||||
data: knex.raw( | ||||
"data::jsonb - 'walletAddressUrl' || jsonb_build_object('paymentPointerUrl', data::jsonb->'walletAddressUrl')" | ||||
) | ||||
}) | ||||
.whereRaw("data->'walletAddressUrl' is not null"), | ||||
knex('webhookEvents') | ||||
.update({ | ||||
type: knex.raw("REPLACE(type, 'wallet_address.', 'payment_pointer.')") | ||||
}) | ||||
.whereLike('type', 'wallet_address%') | ||||
]) | ||||
} |
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: