mnml/ops/migrations/20190624170147_stripe.js
2019-06-28 16:08:55 +10:00

76 lines
1.9 KiB
JavaScript

// INSERT into stripe_customers (account, customer, checkout)
// INSERT into stripe_subscriptions (account, customer, checkout, subscription)
// INSERT into stripe_purchases (account, customer, checkout, amount)
exports.up = async knex => {
await knex.schema.createTable('stripe_customers', table => {
table.string('customer', 128)
.primary();
table.uuid('account')
.notNullable()
.index();
table.foreign('account')
.references('id')
.inTable('accounts')
.onDelete('RESTRICT');
table.string('checkout', 128)
.notNullable()
.unique();
table.timestamps(true, true);
});
await knex.schema.createTable('stripe_subscriptions', table => {
table.string('subscription', 128)
.primary();
table.uuid('account')
.notNullable()
.index();
table.foreign('account')
.references('id')
.inTable('accounts')
.onDelete('RESTRICT');
table.string('customer', 128)
.notNullable();
table.string('checkout', 128)
.notNullable();
table.timestamps(true, true);
});
await knex.schema.createTable('stripe_purchases', table => {
table.string('checkout', 128)
.primary();
table.uuid('account')
.notNullable()
.index();
table.foreign('account')
.references('id')
.inTable('accounts')
.onDelete('RESTRICT');
table.string('customer', 128)
.notNullable();
table.bigInteger('amount')
.notNullable();
table.timestamps(true, true);
});
await knex.schema.raw(`
ALTER TABLE stripe_purchases
ADD CHECK (amount > 0);
`);
};
exports.down = async () => {};