updated db migration

This commit is contained in:
2026-07-20 12:28:46 +08:00
parent a2c9936f79
commit d665897ef5
129 changed files with 574 additions and 1878 deletions
@@ -0,0 +1,32 @@
'use strict';
// Raw SQL for the same CockroachDB DO-block/CREATE TYPE reason as
// 20270101000067-create-completion-requirements.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.
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;`);
},
};