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
Migration payment_intent_unique_on_transaction takes too long if indexes are deleted #190
Comments
We just came across the exact same issue. If I move these lines in
Is there a particular reason it needs to happen in this order? |
Oof. We're running into this as well. About 30k payment intents and 56k transactions. It's been running for over 30 minutes. The query that's taking so long is this one:
The rub is that we don't have any records where |
Our team ended up running this migration manually with this script that marks this migration as done to skip it and mimics the migration with database commands. This ran pretty fast, took a few minutes. No problems ever since running this a few months ago. USE database;
## Add migration row for skipping
INSERT INTO craft_migrations (track, name, applyTime, dateCreated, dateUpdated, uid) VALUES ('plugin:commerce-stripe', 'm210903_040320_payment_intent_unique_on_transaction', NOW(), NOW(), NOW(), UUID())
## Add transactionHash column
ALTER TABLE craft_stripe_paymentintents
ADD transactionHash varchar(255) null
AFTER orderId;
## Join transactionHashes
UPDATE craft_stripe_paymentintents pi
INNER JOIN craft_commerce_transactions t ON t.reference = pi.reference
SET pi.transactionHash = t.hash
WHERE pi.transactionHash IS NULL;
## Drop foreign keys
alter table craft_stripe_paymentintents drop foreign key craft_stripe_paymentintents_customerId_fk;
alter table craft_stripe_paymentintents drop foreign key craft_stripe_paymentintents_gatewayId_fk;
alter table craft_stripe_paymentintents drop foreign key craft_stripe_paymentintents_orderId_fk;
## Drop indexes
drop index craft_stripe_paymentintents_customerId_fk on craft_stripe_paymentintents;
drop index craft_stripe_paymentintents_gatewayId_fk on craft_stripe_paymentintents;
drop index craft_stripe_paymentintents_orderId_gatewayId_customerId_unq_idx on craft_stripe_paymentintents;
drop index craft_stripe_paymentintents_reference_unq_idx on craft_stripe_paymentintents;
## Add foreign keys
alter table craft_stripe_paymentintents
add constraint craft_stripe_paymentintents_gatewayId_fk
foreign key (gatewayId) references craft_commerce_gateways (id)
on delete cascade;
alter table craft_stripe_paymentintents
add constraint craft_stripe_paymentintents_customerId_fk
foreign key (customerId) references craft_stripe_customers (id)
on delete cascade;
alter table craft_stripe_paymentintents
add constraint craft_stripe_paymentintents_orderId_fk
foreign key (orderId) references craft_commerce_orders (id)
on delete cascade;
## Add indexes
CREATE UNIQUE INDEX craft_stripe_paymentintents_reference_unq_idx
ON craft_stripe_paymentintents (reference);
## Add back old index but include transactionHash
CREATE UNIQUE INDEX craft_idx_pi_orderId_gtId_custId_transHash
ON craft_stripe_paymentintents (orderId ASC, gatewayId ASC, customerId ASC, transactionHash ASC); |
Description
Related #185
When running the update from 2.3.2.1 to 2.4.2 on our production database which has:
m210903_040320_payment_intent_unique_on_transaction takes more than 3 hours on my local when running its running this SQL command #L34-L38
I noticed before this SQL update in the migration, it deletes all the indexes on the stripe_paymentintents table, I tried running the same SQL update without deleting the indexes and it takes 13 seconds.
Is there any reason those indexes are deleted before the update? It's blocking our team from updating commerce-stripe since the migration would theoretically block our prod db for hours.
Steps to reproduce
Can send my database privately if needed
Additional info
The text was updated successfully, but these errors were encountered: