0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00
ghost/core/server/data/migrations/versions/3.29
Fabien 'egg' O'Carroll d3384975da
Cleaned up members_stripe_* tables on MySQL (#12103)
refs #12100

For performance reasons we want to add foreign key and unique constraints
to the members_stripe_* tables so we can utilised cascading deletes and 
joins across the tables when querying.

In order to do this we must first ensure that:
- There are no duplicate entries in the `subscription_id` or `customer_id` columns
- There are no orphaned rows in the subscription or customers tables

If the first is not true, the unique constraint will fail, and if the second is not true,
the foreign key constraint will fail.

As we are only adding the indexes to existing MySQL databases at this point, the
cleanup migrations will also only be done for existing MySQL databases too.

The migrations for removing orphaned rows splits the deletion into a `SELECT`
followed by a `WHERE IN` to avoid the database "optimising" the query into a
`JOIN` which ends up taking much longer due to the lack of indexes.
2020-08-06 11:13:41 +02:00
..
01-remove-duplicate-subscriptions.js Cleaned up members_stripe_* tables on MySQL (#12103) 2020-08-06 11:13:41 +02:00
02-remove-duplicate-customers.js Cleaned up members_stripe_* tables on MySQL (#12103) 2020-08-06 11:13:41 +02:00
03-remove-orphaned-customers.js Cleaned up members_stripe_* tables on MySQL (#12103) 2020-08-06 11:13:41 +02:00
04-remove-orphaned-subscriptions.js Cleaned up members_stripe_* tables on MySQL (#12103) 2020-08-06 11:13:41 +02:00