refactor: ♻️ Renomeia a tabela Routes para Itineraries e seus index e fks

This commit is contained in:
Hugo Falcao
2022-08-15 23:49:23 -03:00
parent 26cac96cc6
commit 46de772370
5 changed files with 36 additions and 32 deletions

View File

@@ -1,13 +1,13 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from 'typeorm'; import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from 'typeorm';
export class CreateRoutes1659404395471 implements MigrationInterface { export class CreateItineraries1659404395471 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> { public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable( await queryRunner.createTable(
new Table({ new Table({
name: 'routes', name: 'routes',
columns: [ columns: [
{ {
name: 'id_route', name: 'id_itinerary',
type: 'integer', type: 'integer',
isPrimary: true, isPrimary: true,
isGenerated: true, isGenerated: true,
@@ -43,6 +43,10 @@ export class CreateRoutes1659404395471 implements MigrationInterface {
name: 'available_seats', name: 'available_seats',
type: 'integer', type: 'integer',
}, },
{
name: 'itinerary_nickname',
type: 'varchar',
},
{ {
name: 'created_at', name: 'created_at',
type: 'timestamp', type: 'timestamp',

View File

@@ -16,7 +16,7 @@ export class CreateNeighborhoodsServed1660009211327
generationStrategy: 'increment', generationStrategy: 'increment',
}, },
{ {
name: 'route_id', name: 'itinerary_id',
type: 'integer', type: 'integer',
}, },
{ {
@@ -38,10 +38,10 @@ export class CreateNeighborhoodsServed1660009211327
await queryRunner.createForeignKey( await queryRunner.createForeignKey(
'neighborhoods_served', 'neighborhoods_served',
new TableForeignKey({ new TableForeignKey({
name: 'neighborhoods_served_route_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário name: 'neighborhoods_served_itinerary_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
columnNames: ['route_id'], // coluna que vai virar FK columnNames: ['itinerary_id'], // coluna que vai virar FK
referencedColumnNames: ['id_route'], // coluna PK da tabela referenciada referencedColumnNames: ['id_itinerary'], // coluna PK da tabela referenciada
referencedTableName: 'routes', // nome da tabela que possui a PK referencedTableName: 'itineraries', // nome da tabela que possui a PK
onDelete: 'SET NULL', onDelete: 'SET NULL',
onUpdate: 'CASCADE', onUpdate: 'CASCADE',
}), }),
@@ -50,6 +50,6 @@ export class CreateNeighborhoodsServed1660009211327
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('neighborhoods_served'); await queryRunner.dropTable('neighborhoods_served');
await queryRunner.dropForeignKey('neighborhoods_served', 'neighborhoods_served_route_id_fk'); await queryRunner.dropForeignKey('neighborhoods_served', 'neighborhoods_served_itinerary_id_fk');
} }
} }

View File

@@ -14,7 +14,7 @@ export class CreateDestinations1660009323138 implements MigrationInterface {
generationStrategy: 'increment', generationStrategy: 'increment',
}, },
{ {
name: 'route_id', name: 'itinerary_id',
type: 'integer', type: 'integer',
}, },
{ {
@@ -36,10 +36,10 @@ export class CreateDestinations1660009323138 implements MigrationInterface {
await queryRunner.createForeignKey( await queryRunner.createForeignKey(
'destinations', 'destinations',
new TableForeignKey({ new TableForeignKey({
name: 'destinations_route_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário name: 'destinations_itinerary_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
columnNames: ['route_id'], // coluna que vai virar FK columnNames: ['itinerary_id'], // coluna que vai virar FK
referencedColumnNames: ['id_route'], // coluna PK da tabela referenciada referencedColumnNames: ['id_itinerary'], // coluna PK da tabela referenciada
referencedTableName: 'routes', // nome da tabela que possui a PK referencedTableName: 'itineraries', // nome da tabela que possui a PK
onDelete: 'SET NULL', onDelete: 'SET NULL',
onUpdate: 'CASCADE', onUpdate: 'CASCADE',
}), }),
@@ -48,6 +48,6 @@ export class CreateDestinations1660009323138 implements MigrationInterface {
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('destinations'); await queryRunner.dropTable('destinations');
await queryRunner.dropForeignKey('destinations', 'destinations_route_id_fk'); await queryRunner.dropForeignKey('destinations', 'destinations_itinerary_id_fk');
} }
} }

View File

@@ -14,7 +14,7 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
generationStrategy: 'increment', generationStrategy: 'increment',
}, },
{ {
name: 'route_id', name: 'itinerary_id',
type: 'integer', type: 'integer',
}, },
{ {
@@ -28,10 +28,10 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
await queryRunner.createForeignKey( await queryRunner.createForeignKey(
'passengers', 'passengers',
new TableForeignKey({ new TableForeignKey({
name: 'passengers_route_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário name: 'passengers_itinerary_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
columnNames: ['route_id'], // coluna que vai virar FK columnNames: ['itinerary_id'], // coluna que vai virar FK
referencedColumnNames: ['id_route'], // coluna PK da tabela referenciada referencedColumnNames: ['id_itinerary'], // coluna PK da tabela referenciada
referencedTableName: 'routes', // nome da tabela que possui a PK referencedTableName: 'itineraries', // nome da tabela que possui a PK
onDelete: 'SET NULL', onDelete: 'SET NULL',
onUpdate: 'CASCADE', onUpdate: 'CASCADE',
}), }),
@@ -52,8 +52,8 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
await queryRunner.createIndex( await queryRunner.createIndex(
'passengers', 'passengers',
new TableIndex({ new TableIndex({
name: 'passengers_route_user_idx', name: 'passengers_itinerary_user_idx',
columnNames: ['route_id', 'user_id'], columnNames: ['itinerary_id', 'user_id'],
isUnique: true, isUnique: true,
}), }),
); );
@@ -61,8 +61,8 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('passengers'); await queryRunner.dropTable('passengers');
await queryRunner.dropForeignKey('passengers', 'passengers_route_id_fk'); await queryRunner.dropForeignKey('passengers', 'passengers_itinerary_id_fk');
await queryRunner.dropForeignKey('passengers', 'passengers_user_id_fk'); await queryRunner.dropForeignKey('passengers', 'passengers_user_id_fk');
await queryRunner.dropIndex('passengers', 'passengers_route_user_idx'); await queryRunner.dropIndex('passengers', 'passengers_itinerary_user_idx');
} }
} }

View File

@@ -14,7 +14,7 @@ export class CreateRouteHistoric1660010491828 implements MigrationInterface {
generationStrategy: 'increment', generationStrategy: 'increment',
}, },
{ {
name: 'route_id', name: 'itinerary_id',
type: 'integer', type: 'integer',
}, },
{ {
@@ -36,10 +36,10 @@ export class CreateRouteHistoric1660010491828 implements MigrationInterface {
await queryRunner.createForeignKey( await queryRunner.createForeignKey(
'route_historic', 'route_historic',
new TableForeignKey({ new TableForeignKey({
name: 'route_historic_route_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário name: 'route_historic_itinerary_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
columnNames: ['route_id'], // coluna que vai virar FK columnNames: ['itinerary_id'], // coluna que vai virar FK
referencedColumnNames: ['id_route'], // coluna PK da tabela referenciada referencedColumnNames: ['id_itinerary'], // coluna PK da tabela referenciada
referencedTableName: 'routes', // nome da tabela que possui a PK referencedTableName: 'itineraries', // nome da tabela que possui a PK
onDelete: 'SET NULL', onDelete: 'SET NULL',
onUpdate: 'CASCADE', onUpdate: 'CASCADE',
}), }),
@@ -60,8 +60,8 @@ export class CreateRouteHistoric1660010491828 implements MigrationInterface {
await queryRunner.createIndex( await queryRunner.createIndex(
'route_historic', 'route_historic',
new TableIndex({ new TableIndex({
name: 'route_historic_idx', name: 'itinerary_historic_idx',
columnNames: ['route_id', 'user_id', 'is_return', 'date'], columnNames: ['itinerary_id', 'user_id', 'is_return', 'date'],
isUnique: true, isUnique: true,
}), }),
); );
@@ -69,8 +69,8 @@ export class CreateRouteHistoric1660010491828 implements MigrationInterface {
public async down(queryRunner: QueryRunner): Promise<void> { public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('route_historic'); await queryRunner.dropTable('route_historic');
await queryRunner.dropForeignKey('route_historic', 'route_historic_route_id_fk'); await queryRunner.dropForeignKey('route_historic', 'route_historic_itinerary_id_fk');
await queryRunner.dropForeignKey('route_historic', 'route_historic_user_id_fk'); await queryRunner.dropForeignKey('route_historic', 'route_historic_user_id_fk');
await queryRunner.dropIndex('route_historic', 'route_historic_idx'); await queryRunner.dropIndex('route_historic', 'itinerary_historic_idx');
} }
} }