0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Remove orphaned Stripe data from SQLite (#12704)

refs https://github.com/TryGhost/Team/issues/476

* Moved paid subscription events population migration

This migration relies on the members_stripe_customers and
members_stripe_customer_subscriptions tables having no orphaned records
in order for it to correcly generate its data.

The migration to clean up orphaned records in those tables has not been
implemented yet, moving this migration free's up the "14" slot

* Removed orphaned stripe data from SQLite3

SQLite databases do not handle removing orphaned stripe records after a
member has been deleted. Our migration to populate the paid subscription
events relies on each customer and subscription being associated with a
member.
This commit is contained in:
Fabien 'egg' O'Carroll 2021-03-01 14:32:49 +00:00 committed by GitHub
parent fa89adda3b
commit 3b6c55ec53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View file

@ -0,0 +1,35 @@
const {createIrreversibleMigration} = require('../../utils');
const logging = require('../../../../../shared/logging');
module.exports = createIrreversibleMigration(async function up(connection) {
if (connection.client.config.client === 'mysql') {
logging.info('Skipping removal of orphaned stripe records for MySQL');
return;
}
logging.info('Removing orphaned rows from members_stripe_customers');
await connection.raw(`
DELETE FROM
members_stripe_customers
WHERE
member_id
NOT IN (
SELECT
id
FROM members
);
`);
logging.info('Removing orphaned rows from members_stripe_customers_subscriptions');
await connection.raw(`
DELETE FROM
members_stripe_customers_subscriptions
WHERE
customer_id
NOT IN (
SELECT
customer_id
FROM members_stripe_customers
);
`);
});