Skip to content

Commit

Permalink
feat: add migration for Ratings (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppodds authored Jan 20, 2023
2 parents 83b7832 + 342ffae commit 7d8ad7b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion apps/backend/src/course-feedback/rating,entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export enum RatingType {
RECOMMEND = 2,
}

@Entity('Rating')
@Entity('Ratings')
export class Rating {
@PrimaryGeneratedColumn()
id: number;
Expand Down
70 changes: 70 additions & 0 deletions apps/backend/src/migration/1674226154798-Rating.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { MigrationInterface, QueryRunner, Table, TableIndex } from 'typeorm';

export class Rating1674226154798 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
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<void> {
await queryRunner.dropTable('Ratings');
}
}

0 comments on commit 7d8ad7b

Please sign in to comment.