-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): rename "payment pointer" tables & columns to use "wall…
…et address" (#1937) Co-authored-by: Nathan Lie <[email protected]>
- Loading branch information
Showing
17 changed files
with
199 additions
and
22 deletions.
There are no files selected for viewing
177 changes: 177 additions & 0 deletions
177
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,177 @@ | ||
/** | ||
* @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', 'createdAt', 'id']) | ||
}), | ||
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', 'createdAt', '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', 'createdAt', '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%') | ||
]) | ||
} | ||
|
||
/** | ||
* @param { import("knex").Knex } knex | ||
* @returns { Promise<void> } | ||
*/ | ||
exports.down = function (knex) { | ||
return Promise.all([ | ||
knex.schema.renameTable('walletAddresses', 'paymentPointers'), | ||
knex.schema.alterTable('paymentPointers', function (table) { | ||
table.foreign(['assetId']).references('assets.id') | ||
table.unique('url') | ||
}), | ||
knex.raw( | ||
'ALTER INDEX "walletAddresses_pkey" RENAME TO "paymentPointers_pkey"' | ||
), | ||
knex.raw( | ||
'ALTER INDEX "walletAddresses_url_index" RENAME TO "paymentPointers_url_index"' | ||
), | ||
knex.raw( | ||
'ALTER INDEX "walletaddresses_processat_index" RENAME TO "paymentpointers_processat_index"' | ||
), | ||
knex.raw( | ||
'ALTER TABLE "paymentPointers" DROP CONSTRAINT "walletaddresses_url_unique"' | ||
), | ||
knex.raw( | ||
'ALTER TABLE "paymentPointers" DROP CONSTRAINT "walletaddreses_assetid_foreign"' | ||
), | ||
knex.schema.renameTable('walletAddressKeys', 'paymentPointerKeys'), | ||
knex.schema.alterTable('paymentPointerKeys', function (table) { | ||
table.renameColumn('walletAddressId', 'paymentPointerId') | ||
table.foreign('paymentPointerId').references('paymentPointers.id') | ||
}), | ||
knex.raw( | ||
'ALTER INDEX "walletAddressKeys_pkey" RENAME TO "paymentPointerKeys_pkey"' | ||
), | ||
knex.raw( | ||
'ALTER TABLE "paymentpointerKeys" DROP CONSTRAINT "walletaddresskeys_paymentpointerid_foreign"' | ||
), | ||
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%') | ||
]) | ||
} |
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