refactor: ♻️ Renomeia a tabela Routes para Itineraries e seus index e fks
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
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> {
|
||||
await queryRunner.createTable(
|
||||
new Table({
|
||||
name: 'routes',
|
||||
columns: [
|
||||
{
|
||||
name: 'id_route',
|
||||
name: 'id_itinerary',
|
||||
type: 'integer',
|
||||
isPrimary: true,
|
||||
isGenerated: true,
|
||||
@@ -43,6 +43,10 @@ export class CreateRoutes1659404395471 implements MigrationInterface {
|
||||
name: 'available_seats',
|
||||
type: 'integer',
|
||||
},
|
||||
{
|
||||
name: 'itinerary_nickname',
|
||||
type: 'varchar',
|
||||
},
|
||||
{
|
||||
name: 'created_at',
|
||||
type: 'timestamp',
|
||||
@@ -16,7 +16,7 @@ export class CreateNeighborhoodsServed1660009211327
|
||||
generationStrategy: 'increment',
|
||||
},
|
||||
{
|
||||
name: 'route_id',
|
||||
name: 'itinerary_id',
|
||||
type: 'integer',
|
||||
},
|
||||
{
|
||||
@@ -38,10 +38,10 @@ export class CreateNeighborhoodsServed1660009211327
|
||||
await queryRunner.createForeignKey(
|
||||
'neighborhoods_served',
|
||||
new TableForeignKey({
|
||||
name: 'neighborhoods_served_route_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
|
||||
columnNames: ['route_id'], // coluna que vai virar FK
|
||||
referencedColumnNames: ['id_route'], // coluna PK da tabela referenciada
|
||||
referencedTableName: 'routes', // nome da tabela que possui a PK
|
||||
name: 'neighborhoods_served_itinerary_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
|
||||
columnNames: ['itinerary_id'], // coluna que vai virar FK
|
||||
referencedColumnNames: ['id_itinerary'], // coluna PK da tabela referenciada
|
||||
referencedTableName: 'itineraries', // nome da tabela que possui a PK
|
||||
onDelete: 'SET NULL',
|
||||
onUpdate: 'CASCADE',
|
||||
}),
|
||||
@@ -50,6 +50,6 @@ export class CreateNeighborhoodsServed1660009211327
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export class CreateDestinations1660009323138 implements MigrationInterface {
|
||||
generationStrategy: 'increment',
|
||||
},
|
||||
{
|
||||
name: 'route_id',
|
||||
name: 'itinerary_id',
|
||||
type: 'integer',
|
||||
},
|
||||
{
|
||||
@@ -36,10 +36,10 @@ export class CreateDestinations1660009323138 implements MigrationInterface {
|
||||
await queryRunner.createForeignKey(
|
||||
'destinations',
|
||||
new TableForeignKey({
|
||||
name: 'destinations_route_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
|
||||
columnNames: ['route_id'], // coluna que vai virar FK
|
||||
referencedColumnNames: ['id_route'], // coluna PK da tabela referenciada
|
||||
referencedTableName: 'routes', // nome da tabela que possui a PK
|
||||
name: 'destinations_itinerary_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
|
||||
columnNames: ['itinerary_id'], // coluna que vai virar FK
|
||||
referencedColumnNames: ['id_itinerary'], // coluna PK da tabela referenciada
|
||||
referencedTableName: 'itineraries', // nome da tabela que possui a PK
|
||||
onDelete: 'SET NULL',
|
||||
onUpdate: 'CASCADE',
|
||||
}),
|
||||
@@ -48,6 +48,6 @@ export class CreateDestinations1660009323138 implements MigrationInterface {
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.dropTable('destinations');
|
||||
await queryRunner.dropForeignKey('destinations', 'destinations_route_id_fk');
|
||||
await queryRunner.dropForeignKey('destinations', 'destinations_itinerary_id_fk');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
|
||||
generationStrategy: 'increment',
|
||||
},
|
||||
{
|
||||
name: 'route_id',
|
||||
name: 'itinerary_id',
|
||||
type: 'integer',
|
||||
},
|
||||
{
|
||||
@@ -28,10 +28,10 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
|
||||
await queryRunner.createForeignKey(
|
||||
'passengers',
|
||||
new TableForeignKey({
|
||||
name: 'passengers_route_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
|
||||
columnNames: ['route_id'], // coluna que vai virar FK
|
||||
referencedColumnNames: ['id_route'], // coluna PK da tabela referenciada
|
||||
referencedTableName: 'routes', // nome da tabela que possui a PK
|
||||
name: 'passengers_itinerary_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
|
||||
columnNames: ['itinerary_id'], // coluna que vai virar FK
|
||||
referencedColumnNames: ['id_itinerary'], // coluna PK da tabela referenciada
|
||||
referencedTableName: 'itineraries', // nome da tabela que possui a PK
|
||||
onDelete: 'SET NULL',
|
||||
onUpdate: 'CASCADE',
|
||||
}),
|
||||
@@ -52,8 +52,8 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
|
||||
await queryRunner.createIndex(
|
||||
'passengers',
|
||||
new TableIndex({
|
||||
name: 'passengers_route_user_idx',
|
||||
columnNames: ['route_id', 'user_id'],
|
||||
name: 'passengers_itinerary_user_idx',
|
||||
columnNames: ['itinerary_id', 'user_id'],
|
||||
isUnique: true,
|
||||
}),
|
||||
);
|
||||
@@ -61,8 +61,8 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
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.dropIndex('passengers', 'passengers_route_user_idx');
|
||||
await queryRunner.dropIndex('passengers', 'passengers_itinerary_user_idx');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ export class CreateRouteHistoric1660010491828 implements MigrationInterface {
|
||||
generationStrategy: 'increment',
|
||||
},
|
||||
{
|
||||
name: 'route_id',
|
||||
name: 'itinerary_id',
|
||||
type: 'integer',
|
||||
},
|
||||
{
|
||||
@@ -36,10 +36,10 @@ export class CreateRouteHistoric1660010491828 implements MigrationInterface {
|
||||
await queryRunner.createForeignKey(
|
||||
'route_historic',
|
||||
new TableForeignKey({
|
||||
name: 'route_historic_route_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
|
||||
columnNames: ['route_id'], // coluna que vai virar FK
|
||||
referencedColumnNames: ['id_route'], // coluna PK da tabela referenciada
|
||||
referencedTableName: 'routes', // nome da tabela que possui a PK
|
||||
name: 'route_historic_itinerary_id_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
|
||||
columnNames: ['itinerary_id'], // coluna que vai virar FK
|
||||
referencedColumnNames: ['id_itinerary'], // coluna PK da tabela referenciada
|
||||
referencedTableName: 'itineraries', // nome da tabela que possui a PK
|
||||
onDelete: 'SET NULL',
|
||||
onUpdate: 'CASCADE',
|
||||
}),
|
||||
@@ -60,8 +60,8 @@ export class CreateRouteHistoric1660010491828 implements MigrationInterface {
|
||||
await queryRunner.createIndex(
|
||||
'route_historic',
|
||||
new TableIndex({
|
||||
name: 'route_historic_idx',
|
||||
columnNames: ['route_id', 'user_id', 'is_return', 'date'],
|
||||
name: 'itinerary_historic_idx',
|
||||
columnNames: ['itinerary_id', 'user_id', 'is_return', 'date'],
|
||||
isUnique: true,
|
||||
}),
|
||||
);
|
||||
@@ -69,8 +69,8 @@ export class CreateRouteHistoric1660010491828 implements MigrationInterface {
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
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.dropIndex('route_historic', 'route_historic_idx');
|
||||
await queryRunner.dropIndex('route_historic', 'itinerary_historic_idx');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user