Migrations da tabela socialInformation

This commit is contained in:
Matheus Albino Brunhara
2022-05-30 19:51:29 -05:00
parent 5505b9981a
commit 0d2b7a6884
2 changed files with 84 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
export class CreateSocialInformationTable1653956028190
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'socialInformation',
columns: [
{
name: 'id_social',
type: 'integer',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'user_id',
type: 'uuid',
isNullable: true,
},
{
name: 'phone',
type: 'varchar',
isNullable: true,
},
{
name: 'whatsapp',
type: 'varchar',
isNullable: true,
},
{
name: 'facebook',
type: 'varchar',
isNullable: true,
},
{
name: 'telegram',
type: 'varchar',
isNullable: true,
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('socials');
}
}

View File

@@ -0,0 +1,23 @@
import { MigrationInterface, QueryRunner, TableForeignKey } from 'typeorm';
export class AddFKUserIdToSocialInformationTable1653956193180
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createForeignKey(
'socialInformation',
new TableForeignKey({
name: 'SocialInformationUser', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
columnNames: ['user_id'], // coluna que vai virar FK
referencedColumnNames: ['id_user'], // coluna PK da primeira tabela
referencedTableName: 'users', // nome da tabela que possui a PK
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropForeignKey('socialInformation', 'SocialInformationUser');
}
}