mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
chore: relocate backend into apps/api ahead of monorepo merge
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
|
||||
// Tier Plans v2: bundle items (courses/units/lessons) may now belong to more
|
||||
// than one plan simultaneously — the old single-column unique constraints
|
||||
// enforced "one item = at most one plan ever", which blocks that. Replace
|
||||
// each with a composite unique on (plan_id, item_id), which still prevents
|
||||
// the same item being added twice to the *same* plan.
|
||||
module.exports = {
|
||||
async up(queryInterface) {
|
||||
await queryInterface.removeConstraint('plan_courses', 'plan_courses_course_id_key').catch(() => {});
|
||||
await queryInterface.removeIndex('plan_courses', 'plan_courses_course_id_key').catch(() => {});
|
||||
await queryInterface.addIndex('plan_courses', ['plan_id', 'course_id'], {
|
||||
unique: true,
|
||||
name: 'plan_courses_plan_id_course_id_unique',
|
||||
});
|
||||
|
||||
await queryInterface.removeConstraint('plan_units', 'plan_units_unit_id_key').catch(() => {});
|
||||
await queryInterface.removeIndex('plan_units', 'plan_units_unit_id_key').catch(() => {});
|
||||
await queryInterface.addIndex('plan_units', ['plan_id', 'unit_id'], {
|
||||
unique: true,
|
||||
name: 'plan_units_plan_id_unit_id_unique',
|
||||
});
|
||||
|
||||
await queryInterface.removeConstraint('plan_lessons', 'plan_lessons_lesson_id_key').catch(() => {});
|
||||
await queryInterface.removeIndex('plan_lessons', 'plan_lessons_lesson_id_key').catch(() => {});
|
||||
await queryInterface.addIndex('plan_lessons', ['plan_id', 'lesson_id'], {
|
||||
unique: true,
|
||||
name: 'plan_lessons_plan_id_lesson_id_unique',
|
||||
});
|
||||
},
|
||||
|
||||
async down(queryInterface, Sequelize) {
|
||||
await queryInterface.removeIndex('plan_courses', 'plan_courses_plan_id_course_id_unique');
|
||||
await queryInterface.changeColumn('plan_courses', 'course_id', { type: Sequelize.BIGINT, allowNull: false, unique: true });
|
||||
|
||||
await queryInterface.removeIndex('plan_units', 'plan_units_plan_id_unit_id_unique');
|
||||
await queryInterface.changeColumn('plan_units', 'unit_id', { type: Sequelize.BIGINT, allowNull: false, unique: true });
|
||||
|
||||
await queryInterface.removeIndex('plan_lessons', 'plan_lessons_plan_id_lesson_id_unique');
|
||||
await queryInterface.changeColumn('plan_lessons', 'lesson_id', { type: Sequelize.BIGINT, allowNull: false, unique: true });
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user