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,33 @@
'use strict';
module.exports = {
async up(queryInterface, Sequelize) {
await queryInterface.createTable('user_notifications', {
notification_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'user_id' }, onDelete: 'CASCADE' },
type: { type: Sequelize.STRING(64), allowNull: false },
title: { type: Sequelize.STRING(255), allowNull: false },
message: { type: Sequelize.TEXT, allowNull: false },
data: { type: Sequelize.JSONB, allowNull: true, defaultValue: null },
seen: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false },
seen_at: { type: Sequelize.DATE, allowNull: true, defaultValue: null },
show_in_notifications: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: true },
show_in_sticky: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false },
color: { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'indigo' },
start_date: { type: Sequelize.DATE, allowNull: true },
end_date: { type: Sequelize.DATE, allowNull: true },
broadcast_id: { type: Sequelize.BIGINT, allowNull: true, references: { model: 'notification_broadcasts', key: 'broadcast_id' }, onDelete: 'SET NULL' },
createdAt: { type: Sequelize.DATE, allowNull: false },
updatedAt: { type: Sequelize.DATE, allowNull: false },
});
await queryInterface.addIndex('user_notifications', { fields: ['user_id'], name: 'idx_un_user_id' });
await queryInterface.addIndex('user_notifications', { fields: ['user_id', 'seen'], name: 'idx_un_seen' });
await queryInterface.addIndex('user_notifications', { fields: ['type'], name: 'idx_un_type' });
await queryInterface.addIndex('user_notifications', { fields: ['createdAt'], name: 'idx_un_created_at' });
},
async down(queryInterface) {
await queryInterface.dropTable('user_notifications');
},
};