-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Tier price and currency data to products table (#15366)
refs TryGhost/Product#1765 In order to better handle deleted objects in Stripe we want to decouple Members from Stripe. These changes allow us to have the Tier concept completely independent of the Stripe tables, such that the Stripe data can be generated as/when it's needed - which will help to protect against missing data.
- Loading branch information
Showing
13 changed files
with
196 additions
and
41 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...re/server/data/migrations/versions/5.19/2022-09-02-20-25-add-columns-to-products-table.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,19 @@ | ||
const {createAddColumnMigration, combineNonTransactionalMigrations} = require('../../utils'); | ||
|
||
module.exports = combineNonTransactionalMigrations( | ||
createAddColumnMigration('products', 'monthly_price', { | ||
type: 'integer', | ||
unsigned: true, | ||
nullable: true | ||
}), | ||
createAddColumnMigration('products', 'yearly_price', { | ||
type: 'integer', | ||
unsigned: true, | ||
nullable: true | ||
}), | ||
createAddColumnMigration('products', 'currency', { | ||
type: 'string', | ||
maxlength: 50, | ||
nullable: true | ||
}) | ||
); |
37 changes: 37 additions & 0 deletions
37
...ore/server/data/migrations/versions/5.19/2022-09-02-20-52-backfill-new-product-columns.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,37 @@ | ||
const logging = require('@tryghost/logging'); | ||
|
||
const {createTransactionalMigration} = require('../../utils'); | ||
|
||
module.exports = createTransactionalMigration( | ||
async function up(knex) { | ||
const rows = await knex('products as t') // eslint-disable-line no-restricted-syntax | ||
.select( | ||
't.id as id', | ||
'mp.amount as monthly_price', | ||
'yp.amount as yearly_price', | ||
knex.raw('coalesce(yp.currency, mp.currency) as currency') | ||
) | ||
.leftJoin('stripe_prices AS mp', 't.monthly_price_id', 'mp.id') | ||
.leftJoin('stripe_prices AS yp', 't.yearly_price_id', 'yp.id') | ||
.where('t.type', 'paid'); | ||
|
||
if (!rows.length) { | ||
logging.info('Did not find any active paid Tiers'); | ||
return; | ||
} else { | ||
logging.info(`Updating ${rows.length} Tiers with price and currency information`); | ||
} | ||
|
||
for (const row of rows) { // eslint-disable-line no-restricted-syntax | ||
await knex('products').update(row).where('id', row.id); | ||
} | ||
}, | ||
async function down(knex) { | ||
logging.info('Removing currency and price information for all tiers'); | ||
await knex('products').update({ | ||
currency: null, | ||
monthly_price: null, | ||
yearly_price: null | ||
}); | ||
} | ||
); |
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
Oops, something went wrong.