greenly-hiring-test/migrations/1738106535803-foodProduct.ts

19 lines
1.6 KiB
TypeScript

import { MigrationInterface, QueryRunner } from "typeorm";
export class FoodProduct1738106535803 implements MigrationInterface {
name = 'FoodProduct1738106535803'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE "food_products" ("id" SERIAL NOT NULL, "name" character varying NOT NULL, "footprint" double precision, CONSTRAINT "PK_3aca8796e89325904061ed18b12" PRIMARY KEY ("id"))`);
await queryRunner.query(`CREATE TABLE "food_products_ingredients" ("id" SERIAL NOT NULL, "name" character varying NOT NULL, "quantity" double precision NOT NULL, "unit" character varying NOT NULL, "foodProductId" integer NOT NULL, "carbonEmissionFactorId" integer, CONSTRAINT "PK_fbf9b2563664e5f4dbb4f2dbac6" PRIMARY KEY ("id"))`);
await queryRunner.query(`ALTER TABLE "food_products_ingredients" ADD CONSTRAINT "FK_34cb9f791c7b07183b47521431e" FOREIGN KEY ("foodProductId") REFERENCES "food_products"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE "food_products_ingredients" ADD CONSTRAINT "FK_311390501389e8467a7cd001ff3" FOREIGN KEY ("carbonEmissionFactorId") REFERENCES "carbon_emission_factors"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "food_products_ingredients" DROP CONSTRAINT "FK_311390501389e8467a7cd001ff3"`);
await queryRunner.query(`ALTER TABLE "food_products_ingredients" DROP CONSTRAINT "FK_34cb9f791c7b07183b47521431e"`);
await queryRunner.query(`DROP TABLE "food_products_ingredients"`);
await queryRunner.query(`DROP TABLE "food_products"`);
}
}