-- Generated by @compas/code-gen

-- WARNING:
-- This file is a suggestion, and can be used to create your migration files.
-- Please note that many indexes can have a negative impact on performance. Combining indexes may also be a good option in some circumstances.
-- The order of this output is alphabetically sorted, dependencies between tables are not taken into account.



CREATE TABLE "file"
(
  "id" uuid PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),
  "contentLength" int NOT NULL,
  "bucketName" varchar NOT NULL,
  "contentType" varchar NOT NULL,
  "name" varchar NOT NULL,
  "meta" jsonb NOT NULL,
  "createdAt" timestamptz NOT NULL DEFAULT now(),
  "updatedAt" timestamptz NOT NULL DEFAULT now()
);

CREATE INDEX "fileDatesIdx" ON "file" ("createdAt", "updatedAt");
CREATE INDEX "fileBucketNameIdx" ON "file" ("bucketName");


CREATE TABLE "job"
(
  "id" BIGSERIAL PRIMARY KEY NOT NULL,
  "isComplete" boolean NOT NULL,
  "handlerTimeout" int NULL,
  "priority" int NOT NULL,
  "retryCount" int NOT NULL,
  "name" varchar NOT NULL,
  "scheduledAt" timestamptz NOT NULL,
  "data" jsonb NOT NULL,
  "createdAt" timestamptz NOT NULL DEFAULT now(),
  "updatedAt" timestamptz NOT NULL DEFAULT now()
);

CREATE INDEX "jobDatesIdx" ON "job" ("createdAt", "updatedAt");
CREATE INDEX "jobIsCompleteIdx" ON "job" ("isComplete");
CREATE INDEX "jobNameIdx" ON "job" ("name");
CREATE INDEX "jobScheduledAtIdx" ON "job" ("scheduledAt");


CREATE TABLE "sessionStore"
(
  "id" uuid PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),
  "checksum" varchar NOT NULL,
  "revokedAt" timestamptz NULL,
  "data" jsonb NOT NULL,
  "createdAt" timestamptz NOT NULL DEFAULT now(),
  "updatedAt" timestamptz NOT NULL DEFAULT now()
);

CREATE INDEX "sessionStoreDatesIdx" ON "sessionStore" ("createdAt", "updatedAt");


CREATE TABLE "sessionStoreToken"
(
  "id" uuid PRIMARY KEY NOT NULL DEFAULT uuid_generate_v4(),
  "session" uuid NOT NULL,
  "expiresAt" timestamptz NOT NULL,
  "refreshToken" uuid NULL,
  "revokedAt" timestamptz NULL,
  "createdAt" timestamptz NOT NULL,
  constraint "sessionStoreTokenRefreshTokenFk" foreign key ("refreshToken") references "sessionStoreToken" ("id") ON DELETE SET NULL,
  constraint "sessionStoreTokenSessionFk" foreign key ("session") references "sessionStore" ("id") ON DELETE CASCADE
);

CREATE INDEX "sessionStoreTokenSessionIdx" ON "sessionStoreToken" ("session");
CREATE INDEX "sessionStoreTokenExpiresAtIdx" ON "sessionStoreToken" ("expiresAt");
CREATE INDEX "sessionStoreTokenRefreshTokenIdx" ON "sessionStoreToken" ("refreshToken");
CREATE INDEX "sessionStoreTokenRevokedAtIdx" ON "sessionStoreToken" ("revokedAt");



