// 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 () => {};