Files
starr-philproperties/database/migrations/20260715000001-add-missing-task-requirement-types.js
T
2026-07-15 16:26:09 +08:00

32 lines
1.5 KiB
JavaScript

'use strict';
// task_requirements.type IS a real DB enum (task_requirement_type), despite
// 20260709000001-add-requires-review-and-prompt-to-task-requirements.js's comment
// claiming otherwise ("Sequelize enforces the ENUM only at the application layer
// for this table, so no constraint migration is needed") — that assumption was
// wrong. submit_text and pass_quiz were added to the Sequelize model (task.mdl.js)
// and the admin RequirementBuilder.jsx UI at the same time, but never to the actual
// DB enum, so creating/querying either type has been failing with
// "invalid input value for enum task_requirement_type" ever since (found while
// verifying the new completion_requirements feature's task auto-complete path,
// which happened to be the first thing to actually query a pass_quiz-typed
// TaskRequirement against this DB).
//
// ALTER TYPE ... ADD VALUE (not CREATE TYPE) is a plain top-level statement, not
// wrapped in Sequelize's problematic DO $$...$$ block, so this runs fine as a
// normal migration — no raw-SQL-outside-migrations workaround needed here.
module.exports = {
async up(queryInterface) {
await queryInterface.sequelize.query(
`ALTER TYPE task_requirement_type ADD VALUE IF NOT EXISTS 'submit_text'`
);
await queryInterface.sequelize.query(
`ALTER TYPE task_requirement_type ADD VALUE IF NOT EXISTS 'pass_quiz'`
);
},
// Postgres/CockroachDB cannot remove a value from an enum type — down is a no-op.
async down() {},
};