mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
// Courses gain a publish-state lifecycle (draft/published/unpublished),
|
||||
// separate from the existing soft-delete Archive feature. `status` is added
|
||||
// as STRING + an explicit CHECK constraint (addColumn doesn't auto-generate
|
||||
// one on this CockroachDB instance, unlike createTable), matching the
|
||||
// pattern used in 20260709000002-add-review-fields-to-task-completions.js.
|
||||
// Existing non-deleted courses are backfilled to 'published' since they're
|
||||
// already live/consumed by learners; new courses default to 'draft'.
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface, Sequelize) {
|
||||
await queryInterface.addColumn('courses', 'status', {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
defaultValue: 'draft',
|
||||
after: 'subscription',
|
||||
});
|
||||
await queryInterface.sequelize.query(
|
||||
`ALTER TABLE courses ADD CONSTRAINT check_status
|
||||
CHECK (status IN ('draft', 'published', 'unpublished'))`
|
||||
);
|
||||
await queryInterface.sequelize.query(
|
||||
`UPDATE courses SET status = 'published' WHERE "deletedAt" IS NULL`
|
||||
);
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.sequelize.query(
|
||||
`ALTER TABLE courses DROP CONSTRAINT IF EXISTS check_status`
|
||||
);
|
||||
await queryInterface.removeColumn('courses', 'status');
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user