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

export class AddSubscription1673447442894 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      create table subscription (
        id integer generated by default as identity,
        account_id integer not null,
        created_at timestamp without time zone not null,
        expired_at timestamp without time zone,
        is_trial boolean not null,
        user_limit integer not null,
        primary key (id),
        foreign key (account_id) references account(id) on delete cascade
      );

      insert into subscription(account_id, created_at, expired_at, is_trial, user_limit)
        select id as account_id, created_at, created_at + INTERVAL '14 day' as expired_at, true as is_trial, 5 as user_limit from account;
    `);
  }

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