/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-empty-function */
import type { MigrationInterface, QueryRunner } from 'typeorm';

export class AddRentalOrder1691411118591 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      create table rental_order (
        id integer generated by default as identity,
        section_id integer not null,
        warehouse_id integer,
        entity_id integer not null,
        created_by integer not null,
        start_date timestamp without time zone not null,
        end_date timestamp without time zone not null,
        status character varying not null,
        account_id integer not null,
        created_at timestamp without time zone not null,
        primary key (id),
        foreign key (section_id) references products_section(id) on delete cascade,
        foreign key (warehouse_id) references warehouse(id),
        foreign key (entity_id) references entity(id) on delete cascade,
        foreign key (created_by) references users(id),
        foreign key (account_id) references account(id) on delete cascade
      );
  
      create table rental_order_item (
        id integer generated by default as identity,
        order_id integer not null,
        product_id integer not null,
        warehouse_id integer,
        sort_order integer not null,
        account_id integer not null,
        primary key (id),
        foreign key (order_id) references rental_order(id) on delete cascade,
        foreign key (product_id) references product(id),
        foreign key (warehouse_id) references warehouse(id),
        foreign key (account_id) references account(id) on delete cascade
      );    
    `);
  }

  public async down(_queryRunner: QueryRunner): Promise<void> {}
}
