Incluindo tabela carModels e rotas para pegar lista de carros
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
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');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user