LocChat/server/database/migrations/1648605030863-AddChatRoom.ts
2022-03-30 22:15:20 -06:00

59 lines
1.4 KiB
TypeScript

import { MigrationInterface, QueryRunner, Table, TableForeignKey } from 'typeorm';
export class AddChatRoom1648605030863 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'chat_room',
columns: [
{
name: 'id',
type: 'int',
isPrimary: true,
isGenerated: true,
},
{
name: 'userId',
type: 'int',
isNullable: false,
},
{
name: 'latitude',
type: 'float',
isNullable: false,
},
{
name: 'longitude',
type: 'float',
isNullable: false,
},
{
name: 'radius',
type: 'float',
isNullable: false,
},
{
name: 'name',
type: 'varchar',
isNullable: true,
},
],
}),
);
await queryRunner.createForeignKey(
'chat_room',
new TableForeignKey({
columnNames: ['userId'],
referencedColumnNames: ['id'],
referencedTableName: 'user',
onDelete: 'CASCADE',
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('chat_room');
}
}