From fb250fc63fd9a6e76f4d83feb5f55ef1a2627d36 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 19 May 2019 20:50:08 +0900 Subject: [PATCH] Add unique index --- migration/1558266512381-UserListJoining.ts | 13 +++++++++++++ src/models/entities/user-list-joining.ts | 1 + 2 files changed, 14 insertions(+) create mode 100644 migration/1558266512381-UserListJoining.ts diff --git a/migration/1558266512381-UserListJoining.ts b/migration/1558266512381-UserListJoining.ts new file mode 100644 index 000000000..f4a917045 --- /dev/null +++ b/migration/1558266512381-UserListJoining.ts @@ -0,0 +1,13 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class UserListJoining1558266512381 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE UNIQUE INDEX "IDX_90f7da835e4c10aca6853621e1" ON "user_list_joining" ("userId", "userListId") `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX "IDX_90f7da835e4c10aca6853621e1"`); + } + +} diff --git a/src/models/entities/user-list-joining.ts b/src/models/entities/user-list-joining.ts index 8af4efb6a..bb7dc40b9 100644 --- a/src/models/entities/user-list-joining.ts +++ b/src/models/entities/user-list-joining.ts @@ -4,6 +4,7 @@ import { UserList } from './user-list'; import { id } from '../id'; @Entity() +@Index(['userId', 'userListId'], { unique: true }) export class UserListJoining { @PrimaryColumn(id()) public id: string;