LocChat/server/database/migrations/1648605030863-AddChatRoom.ts

54 lines
1.3 KiB
TypeScript
Raw Normal View History

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