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

export class AddUserToken1739891080452 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      create table user_token (
        id integer generated by default as identity,
        account_id integer not null,
        user_id integer not null,
        name text not null,
        code text not null,
        created_at timestamp without time zone not null default now(),
        expires_at timestamp without time zone,
        last_used_at timestamp without time zone,
        primary key (id),
        foreign key (account_id) references account(id) on delete cascade,
        foreign key (user_id) references users(id) on delete cascade
      );

      create index if not exists idx_account_user_code on user_token(account_id, user_id, code);
    `);
  }

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