54 lines
1.3 KiB
TypeScript
54 lines
1.3 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,
|
|
},
|
|
],
|
|
}),
|
|
);
|
|
|
|
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');
|
|
}
|
|
}
|