updated db migration

This commit is contained in:
2026-07-20 12:28:46 +08:00
parent a2c9936f79
commit d665897ef5
129 changed files with 574 additions and 1878 deletions
@@ -0,0 +1,31 @@
'use strict';
// `tier` started as ENUM('free','premium','exclusive') but 20260101000065
// dropped its CHECK constraint entirely — free-form STRING now, matching
// any tier_categories.slug value.
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('user_tiers', {
tier_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'user_id' }, onDelete: 'CASCADE' },
tier: { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'free' },
status: { type: Sequelize.ENUM('active', 'expired', 'revoked'), allowNull: false, defaultValue: 'active' },
starts_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
expires_at: { type: Sequelize.DATE, allowNull: true },
granted_by: { type: Sequelize.BIGINT, allowNull: true },
revoked_by: { type: Sequelize.BIGINT, allowNull: true },
revoked_at: { type: Sequelize.DATE, allowNull: true },
notes: { type: Sequelize.TEXT, allowNull: true },
plan_id: { type: Sequelize.BIGINT, allowNull: true, references: { model: 'tier_plans', key: 'plan_id' }, onUpdate: 'CASCADE', onDelete: 'SET NULL' },
createdAt: { type: Sequelize.DATE, allowNull: false },
updatedAt: { type: Sequelize.DATE, allowNull: false },
});
await queryInterface.addIndex('user_tiers', ['user_id']);
await queryInterface.addIndex('user_tiers', ['status']);
},
async down(queryInterface) {
await queryInterface.dropTable('user_tiers');
},
};