Merge develop

This commit is contained in:
Matheus Albino Brunhara
2022-09-09 20:50:33 -03:00
4 changed files with 289 additions and 6 deletions

View File

@@ -1,4 +1,10 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from 'typeorm';
import {
MigrationInterface,
QueryRunner,
Table,
TableForeignKey,
TableIndex,
} from 'typeorm';
export class CreateItineraries1659404395471 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
@@ -47,6 +53,22 @@ export class CreateItineraries1659404395471 implements MigrationInterface {
name: 'itinerary_nickname',
type: 'varchar',
},
{
name: 'is_active',
type: 'boolean',
},
{
name: 'estimated_departure_address',
type: 'varchar',
},
{
name: 'departure_latitude',
type: 'numeric',
},
{
name: 'departure_longitude',
type: 'numeric',
},
{
name: 'created_at',
type: 'timestamp',
@@ -77,9 +99,15 @@ export class CreateItineraries1659404395471 implements MigrationInterface {
'itineraries',
new TableIndex({
name: 'itineraries_idx',
columnNames: ['vehicle_plate', 'days_of_week', 'specific_day', 'estimated_departure_time'],
columnNames: [
'vehicle_plate',
'days_of_week',
'specific_day',
'estimated_departure_time',
'is_active',
],
isUnique: true,
})
}),
);
}

View File

@@ -0,0 +1,123 @@
import {
MigrationInterface,
QueryRunner,
Table,
TableForeignKey,
TableIndex,
} from 'typeorm';
export class CreateItineraries1659404395471 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'itineraries',
columns: [
{
name: 'id_itinerary',
type: 'integer',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'vehicle_plate',
type: 'varchar',
},
{
name: 'price',
type: 'float',
},
{
name: 'days_of_week',
type: 'varchar',
isNullable: true,
},
{
name: 'specific_day',
type: 'date',
isNullable: true,
},
{
name: 'estimated_departure_time',
type: 'time',
},
{
name: 'estimated_arrival_time',
type: 'time',
},
{
name: 'available_seats',
type: 'integer',
},
{
name: 'itinerary_nickname',
type: 'varchar',
},
{
name: 'is_active',
type: 'boolean',
},
{
name: 'estimated_departure_address',
type: 'varchar',
},
{
name: 'departure_latitude',
type: 'numeric',
},
{
name: 'departure_longitude',
type: 'numeric',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
await queryRunner.createForeignKey(
'itineraries',
new TableForeignKey({
name: 'itineraries_vehicle_plate_fk', // nome da FK, serve para referenciar numa exclusão pelo QueryRunner se necessário
columnNames: ['vehicle_plate'], // coluna que vai virar FK
referencedColumnNames: ['plate'], // coluna PK da primeira tabela
referencedTableName: 'vehicles', // nome da tabela que possui a PK
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
await queryRunner.createIndex(
'itineraries',
new TableIndex({
name: 'itineraries_idx',
<<<<<<< HEAD
columnNames: ['vehicle_plate', 'days_of_week', 'specific_day', 'estimated_departure_time'],
=======
columnNames: [
'van_plate',
'days_of_week',
'specific_day',
'estimated_departure_time',
'is_active',
],
>>>>>>> c1c8dc7a5ec1043bff7ae027e0b959e0cc561254
isUnique: true,
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('itineraries');
await queryRunner.dropForeignKey('itineraries', 'itineraries_vehicle_plate_fk');
await queryRunner.dropIndex('itineraries', 'itineraries_idx');
}
}

View File

@@ -1,4 +1,10 @@
import { MigrationInterface, QueryRunner, Table, TableForeignKey, TableIndex } from 'typeorm';
import {
MigrationInterface,
QueryRunner,
Table,
TableForeignKey,
TableIndex,
} from 'typeorm';
export class CreatePassengers1660010452826 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
@@ -21,6 +27,22 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
name: 'user_id',
type: 'uuid',
},
{
name: 'address',
type: 'varchar',
},
{
name: 'latitude_address',
type: 'numeric',
},
{
name: 'longitude_address',
type: 'numeric',
},
{
name: 'payment_status',
type: 'boolean',
},
],
}),
);
@@ -50,7 +72,7 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
);
await queryRunner.createIndex(
'passengers',
'passengers',
new TableIndex({
name: 'passengers_itinerary_user_idx',
columnNames: ['itinerary_id', 'user_id'],
@@ -61,7 +83,10 @@ export class CreatePassengers1660010452826 implements MigrationInterface {
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('passengers');
await queryRunner.dropForeignKey('passengers', 'passengers_itinerary_id_fk');
await queryRunner.dropForeignKey(
'passengers',
'passengers_itinerary_id_fk',
);
await queryRunner.dropForeignKey('passengers', 'passengers_user_id_fk');
await queryRunner.dropIndex('passengers', 'passengers_itinerary_user_idx');
}

View File

@@ -0,0 +1,107 @@
import {
MigrationInterface,
QueryRunner,
Table,
TableForeignKey,
TableIndex,
} from 'typeorm';
export class CreatePassengersRequests1662081949950
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'passengers_requests',
columns: [
{
name: 'id_request',
type: 'integer',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'itinerary_id',
type: 'integer',
},
{
name: 'user_id',
type: 'uuid',
},
{
name: 'status',
type: 'enum',
enum: ['pending', 'accepted', 'rejected'],
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'address',
type: 'varchar',
},
{
name: 'latitude_address',
type: 'numeric',
},
{
name: 'longitude_address',
type: 'numeric',
},
],
}),
);
await queryRunner.createForeignKey(
'passengers_requests',
new TableForeignKey({
name: 'passengers_requests_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',
}),
);
await queryRunner.createForeignKey(
'passengers_requests',
new TableForeignKey({
name: 'passengers_requests_user_id_fk', // 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 tabela referenciada
referencedTableName: 'users', // nome da tabela que possui a PK
onDelete: 'SET NULL',
onUpdate: 'CASCADE',
}),
);
await queryRunner.createIndex(
'passengers_requests',
new TableIndex({
name: 'passengers_requests_idx',
columnNames: ['itinerary_id', 'user_id', 'status', 'created_at'],
isUnique: true,
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('passengers_requests');
await queryRunner.dropForeignKey(
'passengers_requests',
'passengers_requests_itinerary_id_fk',
);
await queryRunner.dropForeignKey(
'passengers_requests',
'passengers_requests_user_id_fk',
);
await queryRunner.dropIndex(
'passengers_requests',
'passengers_requests_idx',
);
}
}