Otimiza migrations com gambiarra
This commit is contained in:
@@ -17,12 +17,25 @@ export class CreateUsers1617210132141 implements MigrationInterface {
|
|||||||
name: 'name',
|
name: 'name',
|
||||||
type: 'varchar',
|
type: 'varchar',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'lastname',
|
||||||
|
type: 'varchar',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'email',
|
name: 'email',
|
||||||
type: 'varchar',
|
type: 'varchar',
|
||||||
length: '255',
|
|
||||||
isUnique: true,
|
isUnique: true,
|
||||||
},
|
},
|
||||||
|
// {
|
||||||
|
// name: 'cpf',
|
||||||
|
// type: 'varchar',
|
||||||
|
// isUnique: true,
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: 'cnpj',
|
||||||
|
// type: 'varchar',
|
||||||
|
// isUnique: true,
|
||||||
|
// },
|
||||||
{
|
{
|
||||||
name: 'phone_number',
|
name: 'phone_number',
|
||||||
type: 'varchar',
|
type: 'varchar',
|
||||||
@@ -32,7 +45,7 @@ export class CreateUsers1617210132141 implements MigrationInterface {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'birth_date',
|
name: 'birth_date',
|
||||||
type: 'date',
|
type: 'varchar',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'password',
|
name: 'password',
|
||||||
@@ -55,6 +68,16 @@ export class CreateUsers1617210132141 implements MigrationInterface {
|
|||||||
scale: 2,
|
scale: 2,
|
||||||
isNullable: true
|
isNullable: true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'document',
|
||||||
|
type: 'varchar',
|
||||||
|
isNullable: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'document_type',
|
||||||
|
type: 'varchar',
|
||||||
|
isNullable: true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'created_at',
|
name: 'created_at',
|
||||||
type: 'timestamp',
|
type: 'timestamp',
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
import {MigrationInterface, QueryRunner, TableColumn} from "typeorm";
|
|
||||||
|
|
||||||
export class AlterUsersTableAddLastnameColumn1653437653433 implements MigrationInterface {
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.addColumn('users', new TableColumn({
|
|
||||||
name: 'lastname',
|
|
||||||
type: 'varchar',
|
|
||||||
isNullable: true
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropColumn('users', 'lastname')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
|
|
||||||
|
|
||||||
export class CreateCarModelsTable1653768789073 implements MigrationInterface {
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.createTable(
|
|
||||||
new Table({
|
|
||||||
name: 'carModels',
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
name: 'id_model',
|
|
||||||
type: 'uuid',
|
|
||||||
isPrimary: true,
|
|
||||||
generationStrategy: 'uuid',
|
|
||||||
default: 'uuid_generate_v4()',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'name',
|
|
||||||
type: 'varchar',
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropTable('carModels');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { getConnection, MigrationInterface, QueryRunner } from "typeorm";
|
|
||||||
|
|
||||||
import carModels from '../../constants/carModels'
|
|
||||||
import CarModels from "../../models/CarModels";
|
|
||||||
|
|
||||||
export class InsertDataIntoCarModelsTable1653769103891 implements MigrationInterface {
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
carModels.forEach(async (car) => {
|
|
||||||
const GBP = await queryRunner.manager.save(queryRunner.manager.create<CarModels>(CarModels, { name: car.name }))
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await getConnection()
|
|
||||||
.createQueryBuilder()
|
|
||||||
.delete()
|
|
||||||
.from(CarModels)
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddCpfAndCnpjFieldToUsers1654814986232
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.addColumns('users', [
|
|
||||||
new TableColumn({
|
|
||||||
name: 'cpf',
|
|
||||||
type: 'varchar',
|
|
||||||
isNullable: true,
|
|
||||||
}),
|
|
||||||
new TableColumn({
|
|
||||||
name: 'cnpj',
|
|
||||||
type: 'varchar',
|
|
||||||
isNullable: true,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropColumns('users', ['cnpj', 'cpf']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,10 @@ export class CreateVansTable1655691282002 implements MigrationInterface {
|
|||||||
new Table({
|
new Table({
|
||||||
name: 'vans',
|
name: 'vans',
|
||||||
columns: [
|
columns: [
|
||||||
|
{
|
||||||
|
name: 'user_id',
|
||||||
|
type: 'uuid',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'plate',
|
name: 'plate',
|
||||||
type: 'varchar',
|
type: 'varchar',
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
|
|
||||||
|
|
||||||
export class RemoveCpfAndCnpjFieldsFromUsersTable1655711281662
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropColumns('users', ['cnpj', 'cpf']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.addColumns('users', [
|
|
||||||
new TableColumn({
|
|
||||||
name: 'cpf',
|
|
||||||
type: 'varchar',
|
|
||||||
isNullable: true,
|
|
||||||
}),
|
|
||||||
new TableColumn({
|
|
||||||
name: 'cnpj',
|
|
||||||
type: 'varchar',
|
|
||||||
isNullable: true,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddDocumentAndDocumentTypeFieldsToUsersTable1655711315251
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.addColumns('users', [
|
|
||||||
new TableColumn({
|
|
||||||
name: 'document',
|
|
||||||
type: 'varchar',
|
|
||||||
isNullable: true,
|
|
||||||
}),
|
|
||||||
new TableColumn({
|
|
||||||
name: 'document_type',
|
|
||||||
type: 'varchar',
|
|
||||||
isNullable: true,
|
|
||||||
}),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropColumns('users', ['document_type', 'document']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
|
|
||||||
|
|
||||||
export class AddUserIdFieldToVansTable1655720865095
|
|
||||||
implements MigrationInterface
|
|
||||||
{
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.addColumn(
|
|
||||||
'vans',
|
|
||||||
new TableColumn({
|
|
||||||
name: 'user_id',
|
|
||||||
type: 'uuid',
|
|
||||||
isNullable: true,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropColumn('vans', 'user_id');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -23,7 +23,7 @@ export class CreateItineraries1659404395471 implements MigrationInterface {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'days_of_week',
|
name: 'days_of_week',
|
||||||
type: 'bit',
|
type: 'varchar',
|
||||||
isNullable: true,
|
isNullable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export class CreateNeighborhoodsServed1660009211327
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
await queryRunner.dropTable('neighborhoods_served');
|
|
||||||
await queryRunner.dropForeignKey('neighborhoods_served', 'neighborhoods_served_itinerary_id_fk');
|
await queryRunner.dropForeignKey('neighborhoods_served', 'neighborhoods_served_itinerary_id_fk');
|
||||||
|
await queryRunner.dropTable('neighborhoods_served');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
import {MigrationInterface, QueryRunner, TableColumn} from "typeorm";
|
|
||||||
|
|
||||||
export class AlterUsersTableEditBirthDateFieldTypeToString1661199963221 implements MigrationInterface {
|
|
||||||
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropColumn('users', 'birth_date')
|
|
||||||
|
|
||||||
await queryRunner.addColumn('users', new TableColumn(
|
|
||||||
{
|
|
||||||
name: 'birth_date',
|
|
||||||
type: 'varchar',
|
|
||||||
isNullable: true
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropColumn('users', 'birth_date')
|
|
||||||
|
|
||||||
await queryRunner.addColumn('users', new TableColumn(
|
|
||||||
{
|
|
||||||
name: 'birth_date',
|
|
||||||
type: 'date',
|
|
||||||
isNullable: true
|
|
||||||
},
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
import {MigrationInterface, QueryRunner} from "typeorm";
|
|
||||||
|
|
||||||
export class RenameCarModelsTableToCarBrands1661212542739 implements MigrationInterface {
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.renameTable('carModels', 'carBrands')
|
|
||||||
|
|
||||||
await queryRunner.renameColumn('carBrands', 'id_model', 'id_brand')
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.renameTable('carBrands', 'carModels')
|
|
||||||
|
|
||||||
await queryRunner.renameColumn('carBrands', 'id_brand', 'id_model')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
import {MigrationInterface, QueryRunner, Table} from "typeorm";
|
|
||||||
|
|
||||||
export class DropCarBrandsTable1661745915711 implements MigrationInterface {
|
|
||||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.dropTable('carBrands')
|
|
||||||
}
|
|
||||||
|
|
||||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
||||||
await queryRunner.createTable(
|
|
||||||
new Table({
|
|
||||||
name: 'carModels',
|
|
||||||
columns: [
|
|
||||||
{
|
|
||||||
name: 'id_brand',
|
|
||||||
type: 'uuid',
|
|
||||||
isPrimary: true,
|
|
||||||
generationStrategy: 'uuid',
|
|
||||||
default: 'uuid_generate_v4()',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'name',
|
|
||||||
type: 'varchar',
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user