import { MigrationInterface, QueryRunner } from 'typeorm';

export class SessionTokens1000000000011 implements MigrationInterface {
  name = 'SessionTokens1000000000011';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      CREATE TABLE IF NOT EXISTS "session_tokens" (
        "token"     TEXT PRIMARY KEY NOT NULL,
        "userId"    TEXT NOT NULL,
        "issuedAt"  INTEGER NOT NULL,
        "expiresAt" INTEGER NOT NULL
      )
    `);

    await queryRunner.query(`CREATE INDEX IF NOT EXISTS "idx_session_tokens_user_id" ON "session_tokens" ("userId")`);
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`DROP TABLE IF EXISTS "session_tokens"`);
  }
}
