Refatora Van para Vehicle

This commit is contained in:
Matheus Albino Brunhara
2022-09-03 19:39:07 -03:00
parent 7ce2e602cc
commit 0ff59fcfea
23 changed files with 368 additions and 469 deletions

View File

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