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

66 lines
1.6 KiB
TypeScript
Raw Normal View History

import { MigrationInterface, QueryRunner, Table, TableForeignKey } from 'typeorm';
2022-04-01 16:16:35 -04:00
import { uniqueId } from 'lodash';
2022-03-29 22:17:08 -04:00
export class AddChatRoom1648605030863 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
2022-04-01 16:16:35 -04:00
// uuid from https://github.com/typeorm/typeorm/issues/3770
await queryRunner.query(`CREATE EXTENSION IF NOT EXISTS "uuid-ossp"`);
2022-03-29 22:17:08 -04:00
await queryRunner.createTable(
new Table({
name: 'chat_room',
2022-03-29 22:17:08 -04:00
columns: [
{
name: 'id',
2022-04-01 16:16:35 -04:00
type: 'text',
2022-03-29 22:17:08 -04:00
isPrimary: true,
2022-04-01 16:16:35 -04:00
isUnique: true,
generationStrategy: 'uuid',
default: 'uuid_generate_v4()',
2022-03-29 22:17:08 -04:00
},
{
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,
},
2022-03-31 00:15:20 -04:00
{
name: 'name',
type: 'varchar',
isNullable: true,
},
2022-03-29 22:17:08 -04:00
],
}),
2022-04-01 16:16:35 -04:00
true,
2022-03-29 22:17:08 -04:00
);
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
}
}