Correcting entity and adding migration

This commit is contained in:
Collin Duncan 2023-06-29 10:39:27 +02:00
parent 699b8445ff
commit 1a57f8e2e9
No known key found for this signature in database
3 changed files with 19 additions and 5 deletions

View file

@ -5,7 +5,7 @@ export const AppDataSource = new DataSource({
type: 'sqlite',
database: resolve('./db/autobaan_db'),
logging: true,
entities: [resolve('./src/reservations/entity.ts')],
entities: [resolve('./src/**/entity.ts')],
migrations: [resolve('./database/migrations/*.ts')],
subscribers: [],
})

View file

@ -0,0 +1,15 @@
import { MigrationInterface, QueryRunner } from 'typeorm'
export class RecurringReservations1688027875660 implements MigrationInterface {
name = 'RecurringReservations1688027875660'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE "recurring_reservations" ("id" varchar PRIMARY KEY NOT NULL, "username" varchar(64) NOT NULL, "password" varchar(255) NOT NULL, "dayOfWeek" integer NOT NULL, "timeStart" varchar(6) NOT NULL, "timeEnd" varchar(6) NOT NULL, "opponentId" varchar(32) NOT NULL, "opponentName" varchar(255) NOT NULL)`,
)
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP TABLE "recurring_reservations"`)
}
}

View file

@ -1,4 +1,5 @@
import { Exclude, Transform } from 'class-transformer'
import { IsEnum } from 'class-validator'
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'
import dayjs from '../common/dayjs'
@ -28,10 +29,8 @@ export class RecurringReservation {
@Column('varchar', { length: 255, nullable: false })
password: string
@Column('enum', {
nullable: false,
enum: DayOfWeek,
})
@Column('int', { nullable: false })
@IsEnum(DayOfWeek)
dayOfWeek: DayOfWeek
@Column('varchar', { length: 6, nullable: false })