mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
added new requirements for lessons and units
Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
'use strict';
|
||||
|
||||
// Sequelize's createTable() wraps ENUM creation in a `DO $$...$$` block for
|
||||
// idempotency, which CockroachDB rejects ("CREATE TYPE usage inside a function
|
||||
// definition is not supported"). Built as raw SQL with STRING + CHECK
|
||||
// constraints instead, matching the pattern established in
|
||||
// 20260710000001-add-status-to-courses.js. Sequelize's DataTypes.ENUM at the
|
||||
// model layer works fine against a STRING+CHECK column — no model-side change
|
||||
// needed.
|
||||
|
||||
module.exports = {
|
||||
async up(queryInterface) {
|
||||
await queryInterface.sequelize.query(`
|
||||
CREATE TABLE completion_requirements (
|
||||
requirement_id UUID PRIMARY KEY,
|
||||
entity_type STRING NOT NULL,
|
||||
entity_id BIGINT NOT NULL,
|
||||
type STRING NOT NULL,
|
||||
min_percent INTEGER NULL,
|
||||
button_label STRING NULL,
|
||||
is_required BOOLEAN NOT NULL DEFAULT true,
|
||||
"order" INTEGER NOT NULL DEFAULT 0,
|
||||
"createdBy" BIGINT NULL,
|
||||
"updatedBy" BIGINT NULL,
|
||||
"deletedBy" BIGINT NULL,
|
||||
"createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"deletedAt" TIMESTAMPTZ NULL,
|
||||
CONSTRAINT check_cr_entity_type CHECK (entity_type IN ('course', 'unit', 'lesson')),
|
||||
CONSTRAINT check_cr_type CHECK (type IN ('read_all_content', 'pass_quiz', 'watch_percent', 'manual_complete'))
|
||||
);
|
||||
`);
|
||||
|
||||
await queryInterface.sequelize.query(
|
||||
`CREATE INDEX idx_cr_entity_type_entity_id ON completion_requirements (entity_type, entity_id);`
|
||||
);
|
||||
await queryInterface.sequelize.query(
|
||||
`CREATE INDEX idx_cr_type ON completion_requirements (type);`
|
||||
);
|
||||
},
|
||||
|
||||
async down(queryInterface) {
|
||||
await queryInterface.sequelize.query(`DROP TABLE IF EXISTS completion_requirements;`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user