import { MigrationInterface, QueryRunner, Table, TableColumn } from "typeorm";

export class UpdateIngredientTable1758988727469 implements MigrationInterface {

    public async up(queryRunner: QueryRunner): Promise<void> {
        // rename title column to name
        await queryRunner.renameColumn(
            "recipe_ingredient",
            "title",
            "name"
        )
        // add missing columns
        await queryRunner.addColumns(
            "recipe_ingredient",
             [
                new TableColumn({
                    name: "amount",
                    type: "numeric",
                    isNullable: true,
                }),
                new TableColumn({
                    name: "unit",
                    type: "varchar",
                    isNullable: true,
                }),
                new TableColumn({
                    name: "subtext",
                    type: "varchar",
                    isNullable: true,
                })
            ]
        )
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
          // rename name column to title
        await queryRunner.renameColumn(
            "recipe_ingredient",
            "name",
            "title"
        )
        // remove columns
        await queryRunner.dropColumns(
            "recipe_ingredient",
            ["amount", "unit", "subtext"]
        )
    }

}
