mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -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'))`
|
||||
);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user