'use strict'; // Raw SQL for the same CockroachDB DO-block/CREATE TYPE reason as // 20260714000001-create-completion-requirements.js. module.exports = { async up(queryInterface) { await queryInterface.sequelize.query(` CREATE TABLE completion_requirement_progress ( progress_id UUID PRIMARY KEY, requirement_id UUID NOT NULL REFERENCES completion_requirements (requirement_id) ON DELETE CASCADE, user_id BIGINT NOT NULL REFERENCES users (user_id) ON DELETE CASCADE, entity_type STRING NOT NULL, entity_id BIGINT NOT NULL, progress_percent INTEGER NULL, completed BOOLEAN NOT NULL DEFAULT false, completed_at TIMESTAMPTZ NULL, "createdBy" BIGINT NULL, "updatedBy" BIGINT NULL, "createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT check_crp2_entity_type CHECK (entity_type IN ('course', 'unit', 'lesson')), CONSTRAINT uq_crp2_requirement_user UNIQUE (requirement_id, user_id) ); `); await queryInterface.sequelize.query( `CREATE INDEX idx_crp2_user_id ON completion_requirement_progress (user_id);` ); await queryInterface.sequelize.query( `CREATE INDEX idx_crp2_entity_type_entity_id ON completion_requirement_progress (entity_type, entity_id);` ); }, async down(queryInterface) { await queryInterface.sequelize.query(`DROP TABLE IF EXISTS completion_requirement_progress;`); }, };