'use strict'; // Raw SQL for the same CockroachDB DO-block/CREATE TYPE reason as // 20260714000002-create-completion-requirement-progress.js. // // Decoupled from completion_requirements entirely — tracks last-known playback // position for ANY video/audio block, regardless of whether the lesson has a // watch-type completion requirement configured. Powers resume-on-reopen only. module.exports = { async up(queryInterface) { await queryInterface.sequelize.query(` CREATE TABLE media_playback_positions ( position_id UUID PRIMARY KEY, user_id BIGINT NOT NULL REFERENCES users (user_id) ON DELETE CASCADE, lesson_id BIGINT NOT NULL REFERENCES lessons (lesson_id) ON DELETE CASCADE, block_id STRING NOT NULL, percent INTEGER NOT NULL, "createdAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT CURRENT_TIMESTAMP, CONSTRAINT uq_mpp_user_lesson_block UNIQUE (user_id, lesson_id, block_id) ); `); await queryInterface.sequelize.query( `CREATE INDEX idx_mpp_user_lesson ON media_playback_positions (user_id, lesson_id);` ); }, async down(queryInterface) { await queryInterface.sequelize.query(`DROP TABLE IF EXISTS media_playback_positions;`); }, };