add auth otp migration
This commit is contained in:
@@ -5,3 +5,9 @@ POSTGRES_PASSWORD=change_me
|
|||||||
POSTGRES_DB=montime
|
POSTGRES_DB=montime
|
||||||
# Dev only: auto-sync schema from entities (do not use true in production)
|
# Dev only: auto-sync schema from entities (do not use true in production)
|
||||||
DB_SYNC=true
|
DB_SYNC=true
|
||||||
|
|
||||||
|
JWT_SECRET=change_me_to_a_long_random_secret
|
||||||
|
OTP_HASH_SECRET=change_me_to_a_long_random_secret
|
||||||
|
SUPER_ADMIN_MOBILE=09123456789
|
||||||
|
# Dev/test only: returns OTP code in API response instead of sending SMS
|
||||||
|
AUTH_RETURN_OTP=true
|
||||||
|
|||||||
@@ -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"');
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user