add auth otp migration

This commit is contained in:
2026-05-11 14:17:20 +03:30
parent dd37a46ee4
commit d8f71efdd5
2 changed files with 35 additions and 0 deletions
@@ -0,0 +1,29 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class CreateAuthOtps1789039400000 implements MigrationInterface {
name = 'CreateAuthOtps1789039400000';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query('CREATE EXTENSION IF NOT EXISTS "pgcrypto"');
await queryRunner.query(`
CREATE TABLE IF NOT EXISTS "auth_otps" (
"id" uuid NOT NULL DEFAULT gen_random_uuid(),
"mobile" character varying(20) NOT NULL,
"codeHash" character varying(128) NOT NULL,
"expiresAt" TIMESTAMP WITH TIME ZONE NOT NULL,
"consumedAt" TIMESTAMP WITH TIME ZONE,
"attempts" integer NOT NULL DEFAULT 0,
"createdAt" TIMESTAMP NOT NULL DEFAULT now(),
CONSTRAINT "PK_auth_otps_id" PRIMARY KEY ("id")
)
`);
await queryRunner.query(
'CREATE INDEX IF NOT EXISTS "IDX_auth_otps_mobile" ON "auth_otps" ("mobile")',
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query('DROP INDEX IF EXISTS "IDX_auth_otps_mobile"');
await queryRunner.query('DROP TABLE IF EXISTS "auth_otps"');
}
}