feat(migrations): 🚧 Create migrations of tables (routes, neighborhoods served, destinations, passengers and route historic

This commit is contained in:
Hugo Falcao
2022-08-09 00:38:22 -03:00
parent d0cce0b3cc
commit ef1e3c578b
5 changed files with 210 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
export class CreateRoutes1659404395471 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'routes',
columns: [
{
name: 'id_route',
type: 'integer',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'van_plate',
type: 'varchar',
},
{
name: 'price',
type: 'float',
},
{
name: 'estimated_departure_time',
type: 'time',
},
{
name: 'estimated_arrival_time',
type: 'time',
},
{
name: 'available_seats',
type: 'integer',
},
{
name: 'created_at',
type: 'timestamp',
default: 'now()',
},
{
name: 'updated_at',
type: 'timestamp',
default: 'now()',
},
],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('routes');
}
}

View File

@@ -0,0 +1,42 @@
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
export class CreateNeighborhoodsServed1660009211327
implements MigrationInterface
{
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'neighborhoods_served',
columns: [
{
name: 'id_neighborhood',
type: 'integer',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'route_id',
type: 'integer',
},
{
name: 'name',
type: 'varchar',
},
{
name: 'latitude',
type: 'numeric',
},
{
name: 'longitude',
type: 'numeric',
}
],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('neighborhoods_served');
}
}

View File

@@ -0,0 +1,42 @@
import {MigrationInterface, QueryRunner, Table} from "typeorm";
export class CreateDestinations1660009323138 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'destinations',
columns: [
{
name: 'id_destination',
type: 'integer',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'route_id',
type: 'integer',
},
{
name: 'name',
type: 'varchar',
},
{
name: 'latitude',
type: 'numeric',
},
{
name: 'longitude',
type: 'numeric',
}
],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('destinations');
}
}

View File

@@ -0,0 +1,34 @@
import {MigrationInterface, QueryRunner, Table} from "typeorm";
export class CreatePassengers1660010452826 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'passengers',
columns: [
{
name: 'id_passenger',
type: 'integer',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'route_id',
type: 'integer',
},
{
name: 'user_id',
type: 'uuid',
}
],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('passengers');
}
}

View File

@@ -0,0 +1,38 @@
import {MigrationInterface, QueryRunner, Table} from "typeorm";
export class CreateRouteHistory1660010491828 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'route_historic',
columns: [
{
name: 'id_historic',
type: 'integer',
isPrimary: true,
isGenerated: true,
generationStrategy: 'increment',
},
{
name: 'route_id',
type: 'integer',
},
{
name: 'user_id',
type: 'uuid',
},
{
name: 'date',
type: 'date',
},
],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('route_historic');
}
}