mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
44 lines
2.3 KiB
JavaScript
44 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
// subscription/status are STRING + explicit CHECK constraints, not native
|
|
// Sequelize.ENUM — matches the live schema after 20260101000058 collapsed
|
|
// `subscription` from ENUM to a CockroachDB-compatible VARCHAR+CHECK column,
|
|
// and 20260710000001 added `status` the same way from the start.
|
|
module.exports = {
|
|
async up(queryInterface, Sequelize) {
|
|
await queryInterface.createTable('courses', {
|
|
course_id: { type: Sequelize.BIGINT, primaryKey: true, autoIncrement: true },
|
|
uuid: { type: Sequelize.UUID, defaultValue: Sequelize.UUIDV4, allowNull: false, unique: true },
|
|
title: { type: Sequelize.STRING(255), allowNull: false },
|
|
description: { type: Sequelize.TEXT, allowNull: true },
|
|
course_code: { type: Sequelize.STRING(50), allowNull: true, unique: true },
|
|
order_index: { type: Sequelize.INTEGER, allowNull: false, defaultValue: 0 },
|
|
level: { type: Sequelize.ENUM('beginner', 'intermediate', 'advanced'), allowNull: true },
|
|
subscription: { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'free' },
|
|
status: { type: Sequelize.STRING(20), allowNull: false, defaultValue: 'draft' },
|
|
duration_seconds: { type: Sequelize.INTEGER, allowNull: true, defaultValue: 0 },
|
|
createdBy: { type: Sequelize.BIGINT, allowNull: true },
|
|
updatedBy: { type: Sequelize.BIGINT, allowNull: true },
|
|
deletedBy: { type: Sequelize.BIGINT, allowNull: true },
|
|
createdAt: { type: Sequelize.DATE, allowNull: false },
|
|
updatedAt: { type: Sequelize.DATE, allowNull: false },
|
|
deletedAt: { type: Sequelize.DATE, allowNull: true },
|
|
});
|
|
|
|
await queryInterface.sequelize.query(
|
|
`ALTER TABLE courses ADD CONSTRAINT check_subscription CHECK (subscription IN ('free', 'premium', 'exclusive'))`
|
|
);
|
|
await queryInterface.sequelize.query(
|
|
`ALTER TABLE courses ADD CONSTRAINT check_status CHECK (status IN ('draft', 'published', 'unpublished'))`
|
|
);
|
|
|
|
await queryInterface.addIndex('courses', ['uuid']);
|
|
await queryInterface.addIndex('courses', ['subscription']);
|
|
await queryInterface.addIndex('courses', ['deletedAt']);
|
|
},
|
|
|
|
async down(queryInterface) {
|
|
await queryInterface.dropTable('courses');
|
|
},
|
|
};
|