import { MigrationInterface, QueryRunner } from 'typeorm'; export class AddApiClientAndUserRoles1659715371348 implements MigrationInterface { name = 'AddApiClientAndUserRoles1659715371348'; public async up(queryRunner: QueryRunner): Promise { await queryRunner.query( `CREATE TABLE "api_client" ("id" uuid NOT NULL DEFAULT uuid_generate_v4(), "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), "updatedAt" TIMESTAMP WITH TIME ZONE DEFAULT now(), "deletedAt" TIMESTAMP WITH TIME ZONE, "clientId" character varying NOT NULL, "userId" uuid NOT NULL, "passwordAlgorithmversion" integer NOT NULL, "passwordSalt" character varying NOT NULL, "passwordSaltencoding" character varying NOT NULL, "passwordHash" character varying NOT NULL, "passwordIterations" integer NOT NULL, "passwordLength" integer NOT NULL, "passwordHashfunction" character varying NOT NULL, CONSTRAINT "PK_82a5ec6981d2be903a9eb1d9b9a" PRIMARY KEY ("id"))` ); await queryRunner.query( `CREATE UNIQUE INDEX "IDX_3f93e3481d765915e0daa39c98" ON "api_client" ("clientId") ` ); await queryRunner.query( `CREATE TYPE "public"."users_roles_enum" AS ENUM('SYSTEM', 'USER', 'ADMIN')` ); await queryRunner.query( `ALTER TABLE "users" ADD "roles" "public"."users_roles_enum" array NOT NULL DEFAULT '{}'` ); await queryRunner.query( `ALTER TABLE "api_client" ADD CONSTRAINT "FK_de7e4aa46a0d9a38c195e95e24b" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE NO ACTION ON UPDATE NO ACTION` ); } public async down(queryRunner: QueryRunner): Promise { await queryRunner.query( `ALTER TABLE "api_client" DROP CONSTRAINT "FK_de7e4aa46a0d9a38c195e95e24b"` ); await queryRunner.query(`ALTER TABLE "users" DROP COLUMN "roles"`); await queryRunner.query(`DROP TYPE "public"."users_roles_enum"`); await queryRunner.query( `DROP INDEX "public"."IDX_3f93e3481d765915e0daa39c98"` ); await queryRunner.query(`DROP TABLE "api_client"`); } }