From 342ffae3619dcf21a50802b66f7f5b83b49a043b Mon Sep 17 00:00:00 2001 From: ppodds Date: Fri, 20 Jan 2023 23:23:55 +0800 Subject: [PATCH] feat: add migration for Ratings --- .../src/course-feedback/rating,entity.ts | 2 +- .../src/migration/1674226154798-Rating.ts | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 apps/backend/src/migration/1674226154798-Rating.ts diff --git a/apps/backend/src/course-feedback/rating,entity.ts b/apps/backend/src/course-feedback/rating,entity.ts index 7c66f753..7b4dbb1f 100644 --- a/apps/backend/src/course-feedback/rating,entity.ts +++ b/apps/backend/src/course-feedback/rating,entity.ts @@ -15,7 +15,7 @@ export enum RatingType { RECOMMEND = 2, } -@Entity('Rating') +@Entity('Ratings') export class Rating { @PrimaryGeneratedColumn() id: number; diff --git a/apps/backend/src/migration/1674226154798-Rating.ts b/apps/backend/src/migration/1674226154798-Rating.ts new file mode 100644 index 00000000..67b6598f --- /dev/null +++ b/apps/backend/src/migration/1674226154798-Rating.ts @@ -0,0 +1,70 @@ +import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm'; + +export class Rating1674226154798 implements MigrationInterface { + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.createTable( + new Table({ + name: 'Ratings', + columns: [ + { + name: 'id', + type: 'int', + isPrimary: true, + isGenerated: true, + generationStrategy: 'increment', + }, + { + name: 'authorId', + type: 'int', + isNullable: false, + }, + { + name: 'type', + type: 'tinyint', + isNullable: false, + }, + { + name: 'value', + type: 'tinyint', + isNullable: false, + }, + { + name: 'createdAt', + type: 'datetime', + default: 'CURRENT_TIMESTAMP', + isNullable: false, + }, + { + name: 'updatedAt', + type: 'datetime', + default: 'CURRENT_TIMESTAMP', + isNullable: false, + }, + { + name: 'courseFeedbackClassNo', + type: 'varchar', + isNullable: false, + }, + ], + foreignKeys: [ + { + columnNames: ['courseFeedbackClassNo'], + referencedTableName: 'CourseFeedbacks', + referencedColumnNames: ['classNo'], + onDelete: 'CASCADE', + }, + ], + }), + ); + await queryRunner.createIndex( + 'Ratings', + new TableIndex({ + columnNames: ['type'], + }), + ); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropTable('Ratings'); + } +}