mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
101 lines
3.2 KiB
JavaScript
101 lines
3.2 KiB
JavaScript
'use strict';
|
|
|
|
module.exports = {
|
|
async up(queryInterface, Sequelize) {
|
|
await queryInterface.createTable('announcement_courses', {
|
|
id: {
|
|
type: Sequelize.BIGINT,
|
|
autoIncrement: true,
|
|
primaryKey: true,
|
|
},
|
|
announcement_id: {
|
|
type: Sequelize.BIGINT,
|
|
allowNull: false,
|
|
references: { model: 'announcements', key: 'id' },
|
|
onDelete: 'CASCADE',
|
|
},
|
|
course_id: {
|
|
type: Sequelize.BIGINT,
|
|
allowNull: false,
|
|
references: { model: 'courses', key: 'course_id' },
|
|
onDelete: 'CASCADE',
|
|
},
|
|
});
|
|
|
|
await queryInterface.addConstraint('announcement_courses', {
|
|
fields: ['announcement_id', 'course_id'],
|
|
type: 'unique',
|
|
name: 'uq_announcement_courses',
|
|
});
|
|
|
|
await queryInterface.addIndex('announcement_courses', { fields: ['announcement_id'], name: 'idx_announcement_courses_ann_id' });
|
|
await queryInterface.addIndex('announcement_courses', { fields: ['course_id'], name: 'idx_announcement_courses_course_id' });
|
|
|
|
await queryInterface.createTable('announcement_roles', {
|
|
id: {
|
|
type: Sequelize.BIGINT,
|
|
autoIncrement: true,
|
|
primaryKey: true,
|
|
},
|
|
announcement_id: {
|
|
type: Sequelize.BIGINT,
|
|
allowNull: false,
|
|
references: { model: 'announcements', key: 'id' },
|
|
onDelete: 'CASCADE',
|
|
},
|
|
role: {
|
|
type: Sequelize.STRING(50),
|
|
allowNull: false,
|
|
},
|
|
});
|
|
|
|
await queryInterface.addConstraint('announcement_roles', {
|
|
fields: ['announcement_id', 'role'],
|
|
type: 'unique',
|
|
name: 'uq_announcement_roles',
|
|
});
|
|
|
|
await queryInterface.addIndex('announcement_roles', { fields: ['announcement_id'], name: 'idx_announcement_roles_ann_id' });
|
|
|
|
await queryInterface.createTable('announcement_reads', {
|
|
id: {
|
|
type: Sequelize.BIGINT,
|
|
autoIncrement: true,
|
|
primaryKey: true,
|
|
},
|
|
announcement_id: {
|
|
type: Sequelize.BIGINT,
|
|
allowNull: false,
|
|
references: { model: 'announcements', key: 'id' },
|
|
onDelete: 'CASCADE',
|
|
},
|
|
user_id: {
|
|
type: Sequelize.BIGINT,
|
|
allowNull: false,
|
|
references: { model: 'users', key: 'user_id' },
|
|
onDelete: 'CASCADE',
|
|
},
|
|
read_at: {
|
|
type: Sequelize.DATE,
|
|
allowNull: false,
|
|
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
|
|
},
|
|
});
|
|
|
|
await queryInterface.addConstraint('announcement_reads', {
|
|
fields: ['announcement_id', 'user_id'],
|
|
type: 'unique',
|
|
name: 'uq_announcement_reads',
|
|
});
|
|
|
|
await queryInterface.addIndex('announcement_reads', { fields: ['announcement_id'], name: 'idx_announcement_reads_ann_id' });
|
|
await queryInterface.addIndex('announcement_reads', { fields: ['user_id'], name: 'idx_announcement_reads_user_id' });
|
|
},
|
|
|
|
async down(queryInterface) {
|
|
await queryInterface.dropTable('announcement_reads');
|
|
await queryInterface.dropTable('announcement_roles');
|
|
await queryInterface.dropTable('announcement_courses');
|
|
},
|
|
};
|