mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
make default_group as utility and added more things
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
'use strict';
|
||||
|
||||
// Backfill migration: this table already exists live (created outside of
|
||||
// sequelize-cli before migration coverage was complete). Written to match
|
||||
// the live CockroachDB schema exactly so a fresh install/cutover recreates
|
||||
// it. On the existing production DB, mark this filename as already applied
|
||||
// in SequelizeMeta instead of running it — see project notes.
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('certificates', {
|
||||
certificate_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
uuid: { type: Sequelize.UUID, allowNull: false, unique: true, defaultValue: Sequelize.literal('gen_random_uuid()') },
|
||||
cert_no: { type: Sequelize.STRING(25), allowNull: false, unique: true },
|
||||
ref_no: { type: Sequelize.STRING(50), allowNull: false },
|
||||
user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'user_id' }, onDelete: 'CASCADE' },
|
||||
course_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'courses', key: 'course_id' }, onDelete: 'CASCADE' },
|
||||
instructors: { type: Sequelize.TEXT, allowNull: true },
|
||||
score: { type: Sequelize.BIGINT, allowNull: true },
|
||||
length_str: { type: Sequelize.STRING(50), allowNull: true },
|
||||
issued_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
|
||||
created_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
|
||||
updated_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
|
||||
});
|
||||
|
||||
await queryInterface.addConstraint('certificates', {
|
||||
fields: ['user_id', 'course_id'],
|
||||
type: 'unique',
|
||||
name: 'certificates_user_id_course_id_key',
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('certificates', ['course_id'], { name: 'idx_certificates_course_id' });
|
||||
await queryInterface.addIndex('certificates', ['user_id'], { name: 'idx_certificates_user_id' });
|
||||
await queryInterface.addIndex('certificates', ['uuid'], { name: 'idx_certificates_uuid' });
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.dropTable('certificates');
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
|
||||
// Backfill migration: this table already exists live (created outside of
|
||||
// sequelize-cli before migration coverage was complete). Written to match
|
||||
// the live CockroachDB schema exactly so a fresh install/cutover recreates
|
||||
// it. On the existing production DB, mark this filename as already applied
|
||||
// in SequelizeMeta instead of running it — see project notes.
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('course_instructors', {
|
||||
id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
course_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'courses', key: 'course_id' }, onDelete: 'CASCADE' },
|
||||
user_id: { type: Sequelize.BIGINT, allowNull: true, references: { model: 'users', key: 'user_id' }, onDelete: 'CASCADE' },
|
||||
order_index: { type: Sequelize.BIGINT, allowNull: false, defaultValue: 0 },
|
||||
display_name: { type: Sequelize.STRING(255), allowNull: false, defaultValue: '' },
|
||||
created_by: { type: Sequelize.BIGINT, allowNull: true },
|
||||
created_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
|
||||
updated_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
|
||||
});
|
||||
|
||||
await queryInterface.addConstraint('course_instructors', {
|
||||
fields: ['course_id', 'user_id'],
|
||||
type: 'unique',
|
||||
name: 'course_instructors_course_id_user_id_key',
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('course_instructors', ['course_id'], { name: 'idx_course_instructors_course' });
|
||||
|
||||
// Partial unique index — same columns as the constraint above, scoped to
|
||||
// non-null user_id, matching what's live. Raw SQL since queryInterface
|
||||
// addIndex's `where` support is unreliable for IS NOT NULL across dialects.
|
||||
await queryInterface.sequelize.query(`
|
||||
CREATE UNIQUE INDEX idx_course_instructors_user
|
||||
ON course_instructors (course_id, user_id)
|
||||
WHERE user_id IS NOT NULL;
|
||||
`);
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.dropTable('course_instructors');
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
// Backfill migration: this table already exists live (created outside of
|
||||
// sequelize-cli before migration coverage was complete). Written to match
|
||||
// the live CockroachDB schema exactly so a fresh install/cutover recreates
|
||||
// it. On the existing production DB, mark this filename as already applied
|
||||
// in SequelizeMeta instead of running it — see project notes.
|
||||
//
|
||||
// Note: started_at/last_saved_at/createdAt/updatedAt are TIMESTAMP WITHOUT
|
||||
// TIME ZONE live (unlike most other tables' TIMESTAMPTZ columns), so raw
|
||||
// type strings are used instead of Sequelize.DATE to match exactly.
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('quiz_sessions', {
|
||||
session_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
uuid: { type: Sequelize.UUID, allowNull: false, unique: true, defaultValue: Sequelize.literal('gen_random_uuid()') },
|
||||
user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'user_id' }, onDelete: 'CASCADE' },
|
||||
quiz_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'unit_quizzes', key: 'quiz_id' }, onDelete: 'CASCADE' },
|
||||
course_id: { type: Sequelize.BIGINT, allowNull: true },
|
||||
unit_id: { type: Sequelize.BIGINT, allowNull: true },
|
||||
status: { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'in_progress' },
|
||||
draft_answers: { type: Sequelize.JSONB, allowNull: true },
|
||||
started_at: { type: 'TIMESTAMP', allowNull: false, defaultValue: Sequelize.NOW },
|
||||
last_saved_at: { type: 'TIMESTAMP', allowNull: true },
|
||||
createdAt: { type: 'TIMESTAMP', allowNull: false, defaultValue: Sequelize.NOW },
|
||||
updatedAt: { type: 'TIMESTAMP', allowNull: false, defaultValue: Sequelize.NOW },
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('quiz_sessions', ['quiz_id'], { name: 'idx_qs_quiz_id' });
|
||||
await queryInterface.addIndex('quiz_sessions', ['status'], { name: 'idx_qs_status' });
|
||||
await queryInterface.addIndex('quiz_sessions', ['user_id'], { name: 'idx_qs_user_id' });
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.dropTable('quiz_sessions');
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
'use strict';
|
||||
|
||||
// Backfill migration: this table already exists live (created outside of
|
||||
// sequelize-cli before migration coverage was complete). Written to match
|
||||
// the live CockroachDB schema exactly so a fresh install/cutover recreates
|
||||
// it. On the existing production DB, mark this filename as already applied
|
||||
// in SequelizeMeta instead of running it — see project notes.
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('user_bans', {
|
||||
ban_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
|
||||
user_id: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'user_id' }, onDelete: 'CASCADE' },
|
||||
banned_by: { type: Sequelize.BIGINT, allowNull: false, references: { model: 'users', key: 'user_id' } },
|
||||
reason: { type: Sequelize.TEXT, allowNull: false },
|
||||
ban_type: { type: Sequelize.STRING(20), allowNull: false },
|
||||
banned_at: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
|
||||
expires_at: { type: Sequelize.DATE, allowNull: true },
|
||||
is_lifted: { type: Sequelize.BOOLEAN, allowNull: false, defaultValue: false },
|
||||
lifted_at: { type: Sequelize.DATE, allowNull: true },
|
||||
lifted_by: { type: Sequelize.BIGINT, allowNull: true, references: { model: 'users', key: 'user_id' } },
|
||||
lift_reason: { type: Sequelize.TEXT, allowNull: true },
|
||||
createdAt: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
|
||||
updatedAt: { type: Sequelize.DATE, allowNull: false, defaultValue: Sequelize.NOW },
|
||||
});
|
||||
|
||||
await queryInterface.addConstraint('user_bans', {
|
||||
fields: ['ban_type'],
|
||||
type: 'check',
|
||||
name: 'check_ban_type',
|
||||
where: { ban_type: { [Sequelize.Op.in]: ['temporary', 'permanent'] } },
|
||||
});
|
||||
|
||||
await queryInterface.addIndex('user_bans', ['user_id'], { name: 'idx_user_bans_user_id' });
|
||||
|
||||
// Partial index — only rows relevant to the ban-expiry cron sweep.
|
||||
await queryInterface.sequelize.query(`
|
||||
CREATE INDEX idx_user_bans_expires_at
|
||||
ON user_bans (expires_at)
|
||||
WHERE is_lifted = false AND ban_type = 'temporary';
|
||||
`);
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.dropTable('user_bans');
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user