mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
updated db migration
This commit is contained in:
@@ -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;`);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user