Adicionando rotas e lógica para Vans e Locadores de Vans
This commit is contained in:
50
src/database/migrations/1655691282002-CreateVansTable.ts
Normal file
50
src/database/migrations/1655691282002-CreateVansTable.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
|
||||
|
||||
export class CreateVansTable1655691282002 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: 'vans',
|
||||
columns: [
|
||||
{
|
||||
name: 'id_van',
|
||||
type: 'uuid',
|
||||
isPrimary: true,
|
||||
generationStrategy: 'uuid',
|
||||
default: 'uuid_generate_v4()',
|
||||
},
|
||||
{
|
||||
name: 'plate',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'brand',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'model',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'seats_number',
|
||||
type: 'numeric',
|
||||
},
|
||||
{
|
||||
name: 'created_at',
|
||||
type: 'timestamp',
|
||||
default: 'now()',
|
||||
},
|
||||
{
|
||||
name: 'updated_at',
|
||||
type: 'timestamp',
|
||||
default: 'now()',
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable('vans');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
|
||||
|
||||
export class CreateVanLocatorTable1655692363126 implements MigrationInterface {
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: 'vanLocator',
|
||||
columns: [
|
||||
{
|
||||
name: 'id_vanLocator',
|
||||
type: 'uuid',
|
||||
isPrimary: true,
|
||||
generationStrategy: 'uuid',
|
||||
default: 'uuid_generate_v4()',
|
||||
},
|
||||
{
|
||||
name: 'name',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'address',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'complement',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'city',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'state',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'created_at',
|
||||
type: 'timestamp',
|
||||
default: 'now()',
|
||||
},
|
||||
{
|
||||
name: 'updated_at',
|
||||
type: 'timestamp',
|
||||
default: 'now()',
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable('vanLocator');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
|
||||
|
||||
export class CreateVanDocumentsTable1655692498005
|
||||
implements MigrationInterface
|
||||
{
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: 'vanDocuments',
|
||||
columns: [
|
||||
{
|
||||
name: 'id_vanDocuments',
|
||||
type: 'uuid',
|
||||
isPrimary: true,
|
||||
generationStrategy: 'uuid',
|
||||
default: 'uuid_generate_v4()',
|
||||
},
|
||||
{
|
||||
name: 'vanLocator_id',
|
||||
type: 'uuid',
|
||||
},
|
||||
{
|
||||
name: 'document_status',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'created_at',
|
||||
type: 'timestamp',
|
||||
default: 'now()',
|
||||
},
|
||||
{
|
||||
name: 'updated_at',
|
||||
type: 'timestamp',
|
||||
default: 'now()',
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable('vanDocuments');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { MigrationInterface, QueryRunner, TableForeignKey } from 'typeorm';
|
||||
|
||||
export class AddFKVanLocatorIdToVanDocumentsTable1655692624024
|
||||
implements MigrationInterface
|
||||
{
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.createForeignKey(
|
||||
'vanDocuments',
|
||||
new TableForeignKey({
|
||||
name: 'VanLocatorVanDocuments', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
|
||||
columnNames: ['vanLocator_id'], // coluna que vai virar FK
|
||||
referencedColumnNames: ['id_vanLocator'], // coluna PK da primeira tabela
|
||||
referencedTableName: 'vanLocator', // nome da tabela que possui a PK
|
||||
onDelete: 'SET NULL',
|
||||
onUpdate: 'CASCADE',
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropForeignKey(
|
||||
'vanDocuments',
|
||||
'VanLocatorVanDocuments',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user