import { MigrationInterface, QueryRunner } from "typeorm";

export class AddContainerNumberToBookingContainer1750900000000 implements MigrationInterface {
    name = "AddContainerNumberToBookingContainer1750900000000";

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`
            ALTER TABLE freight.booking_container
            ALTER COLUMN container_type_id DROP NOT NULL;
        `);

        await queryRunner.query(`
            ALTER TABLE freight.booking_container
            ADD COLUMN container_number varchar(64);
        `);

        await queryRunner.query(`
            ALTER TABLE freight.wagon_allocation_container_items
            ALTER COLUMN container_type_id DROP NOT NULL;
        `);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`
            ALTER TABLE freight.wagon_allocation_container_items
            ALTER COLUMN container_type_id SET NOT NULL;
        `);

        await queryRunner.query(`
            ALTER TABLE freight.booking_container
            DROP COLUMN container_number;
        `);

        await queryRunner.query(`
            ALTER TABLE freight.booking_container
            ALTER COLUMN container_type_id SET NOT NULL;
        `);
    }
}
