// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors
// SPDX-License-Identifier: Apache-2.0
/*
* Generated by @medplum/generator
* Do not edit manually.
*/
import type { PoolClient } from 'pg';
export async function run(client: PoolClient): Promise<void> {
await client.query(`CREATE TABLE IF NOT EXISTS "SubscriptionStatus_References" (
"resourceId" UUID NOT NULL,
"targetId" UUID NOT NULL,
"code" TEXT NOT NULL
)`);
await client.query(
'ALTER TABLE IF EXISTS "SubscriptionStatus_References" ADD PRIMARY KEY ("resourceId", "targetId", "code")'
);
await client.query(`CREATE TABLE IF NOT EXISTS "UserSecurityRequest" (
"id" UUID NOT NULL PRIMARY KEY,
"content" TEXT NOT NULL,
"lastUpdated" TIMESTAMPTZ NOT NULL,
"deleted" BOOLEAN NOT NULL DEFAULT FALSE,
"compartments" UUID[] NOT NULL,
"projectId" UUID,
"_source" TEXT,
"_tag" TEXT[],
"_profile" TEXT[],
"_security" TEXT[],
"user" TEXT
)`);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_lastUpdated_idx ON "UserSecurityRequest" ("lastUpdated")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_compartments_idx ON "UserSecurityRequest" USING gin ("compartments")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_projectId_idx ON "UserSecurityRequest" ("projectId")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest__source_idx ON "UserSecurityRequest" ("_source")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest__tag_idx ON "UserSecurityRequest" USING gin ("_tag")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest__profile_idx ON "UserSecurityRequest" USING gin ("_profile")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest__security_idx ON "UserSecurityRequest" ("_security")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_user_idx ON "UserSecurityRequest" ("user")'
);
await client.query(`CREATE TABLE IF NOT EXISTS "UserSecurityRequest_History" (
"versionId" UUID NOT NULL PRIMARY KEY,
"id" UUID NOT NULL,
"content" TEXT NOT NULL,
"lastUpdated" TIMESTAMPTZ NOT NULL
)`);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_History_id_idx ON "UserSecurityRequest_History" ("id")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_History_lastUpdated_idx ON "UserSecurityRequest_History" ("lastUpdated")'
);
await client.query(`CREATE TABLE IF NOT EXISTS "UserSecurityRequest_Token" (
"resourceId" UUID NOT NULL,
"index" INTEGER,
"code" TEXT NOT NULL,
"system" TEXT,
"value" TEXT
)`);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_Token_resourceId_idx ON "UserSecurityRequest_Token" ("resourceId")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_Token_code_idx ON "UserSecurityRequest_Token" ("code")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_Token_system_idx ON "UserSecurityRequest_Token" ("system")'
);
await client.query(
'CREATE INDEX CONCURRENTLY IF NOT EXISTS UserSecurityRequest_Token_value_idx ON "UserSecurityRequest_Token" ("value")'
);
await client.query(`CREATE TABLE IF NOT EXISTS "UserSecurityRequest_References" (
"resourceId" UUID NOT NULL,
"targetId" UUID NOT NULL,
"code" TEXT NOT NULL
)`);
await client.query(
'ALTER TABLE IF EXISTS "UserSecurityRequest_References" ADD PRIMARY KEY ("resourceId", "targetId", "code")'
);
}