Linkando van com usuário

This commit is contained in:
Matheus Albino Brunhara
2022-06-20 05:40:56 -05:00
parent 04de75faf6
commit 2f55141bdf
13 changed files with 287 additions and 1159 deletions

View File

@@ -0,0 +1,24 @@
import { MigrationInterface, QueryRunner, TableForeignKey } from 'typeorm';
export class AddFKUserIdToVansTable1655720873936 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createForeignKey(
'vans',
new TableForeignKey({
name: 'UserIdVan', // 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(
'vans',
'UserIdVan',
);
}
}