27 lines
928 B
TypeScript
27 lines
928 B
TypeScript
import { UNIQUE_QUESTION_MULTI_CHOICE } from '@/modules/questions/constants';
|
|
import { QuestionTransitionType } from '@/modules/questions/enums/question-transition-type.enum';
|
|
import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
|
|
export class MultiChoiceTransitionUniqueIndex1787294625900 implements MigrationInterface {
|
|
name = 'MultiChoiceTransitionUniqueIndex1787294625900';
|
|
|
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
await queryRunner.query(`
|
|
CREATE UNIQUE INDEX ${UNIQUE_QUESTION_MULTI_CHOICE}
|
|
ON "question_transition" (
|
|
"fromQuestionId",
|
|
"type",
|
|
(("condition" ->> 'operator')),
|
|
(("condition" -> 'choiceIds'))
|
|
)
|
|
WHERE "type" = '${QuestionTransitionType.MULTI_CHOICE}'
|
|
`);
|
|
}
|
|
|
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
await queryRunner.query(`
|
|
DROP INDEX ${UNIQUE_QUESTION_MULTI_CHOICE}
|
|
`);
|
|
}
|
|
}
|