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

export class MigrateModuleToProductModule1690456178510 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      delete from product_module;

      alter table product_module
        alter column id set not null,
        alter column id add generated by default as identity;
      
      drop sequence product_module_id_seq;

      insert into product_module(name, icon, account_id)
        select m.name as name, 'box' as icon, am.account_id as account_id
        from account_module am
        join module m on m.id = am.module_id;
    `);
  }

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