Files
starr-philproperties/database/migrations/20260710000001-add-status-to-courses.js
T
kennethobsequio 82ea9c77c4 merged
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
2026-07-11 12:12:29 +08:00

35 lines
1.3 KiB
JavaScript

'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');
},
};