billing_product.cjs
1.12 KB
const tableName = 'billing_product'
function buildTable(t) {
t.string('id', 96).primary()
t.string('kind', 32).notNullable()
t.string('title', 160).nullable()
t.bigInteger('points').nullable()
t.bigInteger('paid_points').unsigned().nullable()
t.bigInteger('bonus_points').unsigned().nullable()
t.decimal('price_usd', 10, 2).nullable()
t.bigInteger('price_cents').nullable()
t.string('currency', 8).nullable()
t.string('stripe_price_id', 191).nullable()
t.text('metadata_json', 'longtext').nullable()
t.boolean('active').notNullable().defaultTo(true)
t.datetime('created_at', { precision: 3 }).nullable()
t.datetime('updated_at', { precision: 3 }).nullable()
t.index(['active', 'kind'], 'idx_billing_product_active_kind')
t.unique(['stripe_price_id'], { indexName: 'uq_billing_product_stripe_price' })
t.check("kind <> 'points_pack' or (points is not null and paid_points is not null and bonus_points is not null and points = paid_points + bonus_points and price_cents > 0 and currency = 'usd' and price_usd = price_cents / 100)", [], 'ck_billing_product_points_pack')
}
module.exports = { tableName, buildTable }