pushy

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-06-28 11:29:07 +08:00
parent 463a8d3978
commit 89acdfc239
67 changed files with 2736 additions and 306 deletions
@@ -0,0 +1,39 @@
'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
// Add the FK column
await queryInterface.addColumn('tier_plans', 'tier_category_id', {
type: Sequelize.BIGINT,
allowNull: true,
references: { model: 'tier_categories', key: 'tier_category_id' },
onUpdate: 'CASCADE',
onDelete: 'SET NULL',
});
// Populate from the existing tier slug → tier_categories row
await queryInterface.sequelize.query(`
UPDATE tier_plans tp
SET tier_category_id = tc.tier_category_id
FROM tier_categories tc
WHERE tc.slug = tp.tier
`);
// CockroachDB stores Sequelize ENUMs as VARCHAR + CHECK constraint.
// Drop the constraint so `tier` becomes a free-form slug that can hold
// any value matching a tier_categories.slug (including admin-created ones).
await queryInterface.sequelize.query(
`ALTER TABLE tier_plans DROP CONSTRAINT IF EXISTS check_tier`
);
await queryInterface.sequelize.query(
`ALTER TABLE tier_plans DROP CONSTRAINT IF EXISTS "tier_plans_tier_check"`
);
},
async down(queryInterface) {
await queryInterface.removeColumn('tier_plans', 'tier_category_id');
await queryInterface.sequelize.query(
`ALTER TABLE tier_plans ADD CONSTRAINT check_tier CHECK (tier IN ('premium', 'exclusive'))`
);
},
};