halkyon/apps/learn/halkyon_learn_server/migrations/20261021110159867-second-factor-paths/definition.sql
Tizian 「ティツィアーン」 4d1cd2045c
fix(auth): codes after the recovery phrase count apart from the password's
The full reading's M3: whoever knows the password made the account's codes
wait, and that wait refused the phrase's owner their reset too, so they were
held out of both without end. Codes now count per account and per way they
came (SecondFactorPath: after the password, after the phrase), each with
its own waits; a code accepted either way clears both.

Migration (module, Learn's and Todo's servers; Learn's device schema
rebuilds the server-only table):
  DROP INDEX "second_factor_failures_person_idx";
  ALTER TABLE "second_factor_failures" ADD COLUMN "path" text NOT NULL
    DEFAULT 'password'::text;
  CREATE UNIQUE INDEX "second_factor_failures_person_idx" ON
    "second_factor_failures" USING btree ("authUserId", "path");
Existing rows are the password's, unique per account, so unique per
account and way too.

Also the hosts' generated future calls, for the pruning's doc comment the
lapsed resets' commit changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-23 14:12:52 +02:00

2345 lines
69 KiB
PL/PgSQL

BEGIN;
--
-- Function: gen_random_uuid_v7()
-- Source: https://gist.github.com/kjmph/5bd772b2c2df145aa645b837da7eca74
-- License: MIT (copyright notice included on the generator source code).
--
create or replace function gen_random_uuid_v7()
returns uuid
as $$
begin
-- use random v4 uuid as starting point (which has the same variant we need)
-- then overlay timestamp
-- then set version 7 by flipping the 2 and 1 bit in the version 4 string
return encode(
set_bit(
set_bit(
overlay(uuid_send(gen_random_uuid())
placing substring(int8send(floor(extract(epoch from clock_timestamp()) * 1000)::bigint) from 3)
from 1 for 6
),
52, 1
),
53, 1
),
'hex')::uuid;
end
$$
language plpgsql
volatile;
--
-- Class Asset as table asset
--
CREATE TABLE "asset" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"sha256" text NOT NULL,
"mimeType" text NOT NULL,
"byteSize" bigint NOT NULL,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "asset_space_idx" ON "asset" USING btree ("spaceId");
CREATE INDEX "asset_hash_idx" ON "asset" USING btree ("spaceId", "sha256");
--
-- Class AssistantClient as table assistant_client
--
CREATE TABLE "assistant_client" (
"id" bigserial PRIMARY KEY,
"clientId" text NOT NULL,
"name" text NOT NULL,
"redirectUris" json NOT NULL,
"secretHash" text,
"createdAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "assistant_client_id_idx" ON "assistant_client" USING btree ("clientId");
--
-- Class AssistantConnectCode as table assistant_connect_code
--
CREATE TABLE "assistant_connect_code" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"codeHash" text NOT NULL,
"expiresAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "assistant_connect_code_hash_idx" ON "assistant_connect_code" USING btree ("codeHash");
CREATE INDEX "assistant_connect_code_person_idx" ON "assistant_connect_code" USING btree ("authUserId");
--
-- Class AssistantConnection as table assistant_connection
--
CREATE TABLE "assistant_connection" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"clientId" bigint NOT NULL,
"createdAt" timestamp without time zone NOT NULL,
"lastUsedAt" timestamp without time zone
);
-- Indexes
CREATE INDEX "assistant_connection_person_idx" ON "assistant_connection" USING btree ("authUserId");
CREATE INDEX "assistant_connection_client_idx" ON "assistant_connection" USING btree ("clientId");
--
-- Class AssistantGrant as table assistant_grant
--
CREATE TABLE "assistant_grant" (
"id" bigserial PRIMARY KEY,
"connectionId" bigint NOT NULL,
"codeHash" text NOT NULL,
"redirectUri" text NOT NULL,
"codeChallenge" text NOT NULL,
"resource" text NOT NULL,
"scope" text NOT NULL,
"expiresAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "assistant_grant_hash_idx" ON "assistant_grant" USING btree ("codeHash");
CREATE INDEX "assistant_grant_connection_idx" ON "assistant_grant" USING btree ("connectionId");
--
-- Class AssistantToken as table assistant_token
--
CREATE TABLE "assistant_token" (
"id" bigserial PRIMARY KEY,
"connectionId" bigint NOT NULL,
"accessHash" text NOT NULL,
"accessExpiresAt" timestamp without time zone NOT NULL,
"refreshHash" text NOT NULL,
"refreshExpiresAt" timestamp without time zone NOT NULL,
"resource" text NOT NULL,
"scope" text NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "assistant_token_access_idx" ON "assistant_token" USING btree ("accessHash");
CREATE UNIQUE INDEX "assistant_token_refresh_idx" ON "assistant_token" USING btree ("refreshHash");
CREATE INDEX "assistant_token_connection_idx" ON "assistant_token" USING btree ("connectionId");
--
-- Class Card as table card
--
CREATE TABLE "card" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"studysetId" uuid NOT NULL,
"position" text NOT NULL,
"buriedAt" timestamp without time zone
);
-- Indexes
CREATE INDEX "card_space_idx" ON "card" USING btree ("spaceId");
CREATE INDEX "card_studyset_idx" ON "card" USING btree ("studysetId", "position");
--
-- Class CardRevision as table card_revision
--
CREATE TABLE "card_revision" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"cardId" uuid NOT NULL,
"parents" json NOT NULL,
"authorId" uuid NOT NULL,
"reportId" uuid,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "card_revision_space_idx" ON "card_revision" USING btree ("spaceId");
CREATE INDEX "card_revision_card_idx" ON "card_revision" USING btree ("cardId");
--
-- Class CardTag as table card_tag
--
CREATE TABLE "card_tag" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"cardId" uuid NOT NULL,
"tagId" uuid NOT NULL
);
-- Indexes
CREATE INDEX "card_tag_space_idx" ON "card_tag" USING btree ("spaceId");
CREATE INDEX "card_tag_card_idx" ON "card_tag" USING btree ("cardId");
CREATE INDEX "card_tag_tag_idx" ON "card_tag" USING btree ("tagId");
--
-- Class DictionaryEntry as table dictionary_entry
--
CREATE TABLE "dictionary_entry" (
"id" bigserial PRIMARY KEY,
"source" text NOT NULL,
"sourceId" text NOT NULL,
"language" text NOT NULL,
"glossLanguage" text NOT NULL,
"headword" text NOT NULL,
"reading" text,
"rank" bigint NOT NULL,
"labels" text NOT NULL,
"searchKeys" text NOT NULL,
"looseKeys" text NOT NULL,
"entry" text NOT NULL,
"version" text NOT NULL DEFAULT ''::text
);
-- Indexes
CREATE UNIQUE INDEX "dictionary_entry_source_idx" ON "dictionary_entry" USING btree ("source", "glossLanguage", "sourceId");
CREATE INDEX "dictionary_entry_rank_idx" ON "dictionary_entry" USING btree ("source", "glossLanguage", "rank");
--
-- Class DictionaryKey as table dictionary_key
--
CREATE TABLE "dictionary_key" (
"id" bigserial PRIMARY KEY,
"source" text NOT NULL,
"glossLanguage" text NOT NULL,
"key" text NOT NULL,
"sourceId" text NOT NULL,
"rank" bigint NOT NULL
);
-- Indexes
CREATE INDEX "dictionary_key_idx" ON "dictionary_key" USING btree ("source", "glossLanguage", "key");
--
-- Class DictionarySearchKey as table dictionary_search_key
--
CREATE TABLE "dictionary_search_key" (
"id" bigserial PRIMARY KEY,
"source" text NOT NULL,
"glossLanguage" text NOT NULL,
"key" text NOT NULL,
"loose" boolean NOT NULL,
"start1" text NOT NULL,
"start2" text NOT NULL,
"start3" text NOT NULL,
"sourceId" text NOT NULL,
"rank" bigint NOT NULL
);
-- Indexes
CREATE INDEX "dictionary_search_key_start_idx" ON "dictionary_search_key" USING btree ("source", "glossLanguage", "start1", "start2", "start3");
--
-- Class DictionarySource as table dictionary_source
--
CREATE TABLE "dictionary_source" (
"id" bigserial PRIMARY KEY,
"source" text NOT NULL,
"sourceVersion" text NOT NULL,
"kind" text NOT NULL DEFAULT 'words'::text,
"language" text NOT NULL,
"glossLanguage" text NOT NULL,
"license" text NOT NULL,
"credits" json NOT NULL,
"entryCount" bigint NOT NULL,
"fileName" text NOT NULL,
"fileHash" text NOT NULL,
"loadedAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "dictionary_source_idx" ON "dictionary_source" USING btree ("source", "glossLanguage");
--
-- Class DiscussionPost as table discussion_post
--
CREATE TABLE "discussion_post" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"publishedStudysetId" bigint NOT NULL,
"kind" text NOT NULL,
"questionId" uuid,
"parentId" uuid,
"authUserId" uuid,
"targetKind" text,
"targetItem" text,
"targetVersion" bigint,
"topics" text,
"title" text,
"body" text NOT NULL,
"createdAt" timestamp without time zone NOT NULL,
"editedAt" timestamp without time zone,
"activeAt" timestamp without time zone NOT NULL,
"deletedAt" timestamp without time zone,
"hiddenAt" timestamp without time zone,
"acceptedAnswerId" uuid,
"acceptedAt" timestamp without time zone
);
-- Indexes
CREATE INDEX "discussion_post_studyset_idx" ON "discussion_post" USING btree ("publishedStudysetId", "kind");
CREATE INDEX "discussion_post_question_idx" ON "discussion_post" USING btree ("questionId");
CREATE INDEX "discussion_post_writer_idx" ON "discussion_post" USING btree ("authUserId");
--
-- Class DiscussionSeen as table discussion_seen
--
CREATE TABLE "discussion_seen" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"questionId" uuid NOT NULL,
"seenAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "discussion_seen_pair_idx" ON "discussion_seen" USING btree ("authUserId", "questionId");
--
-- Class FeedbackBlock as table feedback_block
--
CREATE TABLE "feedback_block" (
"id" bigserial PRIMARY KEY,
"authorId" uuid NOT NULL,
"blockedId" uuid NOT NULL,
"createdAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "feedback_block_pair_idx" ON "feedback_block" USING btree ("authorId", "blockedId");
--
-- Class FeedbackDecision as table feedback_decision
--
CREATE TABLE "feedback_decision" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"threadId" uuid NOT NULL,
"decision" text NOT NULL
);
-- Indexes
CREATE INDEX "feedback_decision_space_idx" ON "feedback_decision" USING btree ("spaceId");
CREATE INDEX "feedback_decision_thread_idx" ON "feedback_decision" USING btree ("threadId");
--
-- Class FeedbackMessage as table feedback_message
--
CREATE TABLE "feedback_message" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"threadId" uuid NOT NULL,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "feedback_message_space_idx" ON "feedback_message" USING btree ("spaceId");
CREATE INDEX "feedback_message_thread_idx" ON "feedback_message" USING btree ("threadId");
--
-- Class FeedbackSeen as table feedback_seen
--
CREATE TABLE "feedback_seen" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"threadId" uuid NOT NULL,
"seenAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "feedback_seen_pair_idx" ON "feedback_seen" USING btree ("authUserId", "threadId");
--
-- Class FeedbackThread as table feedback_thread
--
CREATE TABLE "feedback_thread" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"publicationId" uuid NOT NULL,
"kind" text NOT NULL,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "feedback_thread_space_idx" ON "feedback_thread" USING btree ("spaceId");
CREATE INDEX "feedback_thread_publication_idx" ON "feedback_thread" USING btree ("publicationId");
--
-- Class FileAllowance as table file_allowance
--
CREATE TABLE "file_allowance" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"maxBytes" bigint NOT NULL,
"note" text
);
-- Indexes
CREATE UNIQUE INDEX "file_allowance_person_idx" ON "file_allowance" USING btree ("authUserId");
--
-- Class LearningPath as table learning_path
--
CREATE TABLE "learning_path" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"studysetId" uuid NOT NULL,
"position" text NOT NULL,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "learning_path_space_idx" ON "learning_path" USING btree ("spaceId");
CREATE INDEX "learning_path_studyset_idx" ON "learning_path" USING btree ("studysetId", "position");
--
-- Class LearningPathAnswer as table learning_path_answer
--
CREATE TABLE "learning_path_answer" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"stepId" uuid NOT NULL,
"answeredAt" timestamp without time zone NOT NULL,
"outcome" text NOT NULL,
"answer" text
);
-- Indexes
CREATE INDEX "learning_path_answer_space_idx" ON "learning_path_answer" USING btree ("spaceId");
CREATE INDEX "learning_path_answer_step_idx" ON "learning_path_answer" USING btree ("stepId", "answeredAt");
--
-- Class LearningPathStep as table learning_path_step
--
CREATE TABLE "learning_path_step" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"pathId" uuid NOT NULL,
"position" text NOT NULL,
"kind" text NOT NULL
);
-- Indexes
CREATE INDEX "learning_path_step_space_idx" ON "learning_path_step" USING btree ("spaceId");
CREATE INDEX "learning_path_step_path_idx" ON "learning_path_step" USING btree ("pathId", "position");
--
-- Class LearningPathStepRevision as table learning_path_step_revision
--
CREATE TABLE "learning_path_step_revision" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"stepId" uuid NOT NULL,
"parents" json NOT NULL,
"authorId" uuid NOT NULL,
"reportId" uuid,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "learning_path_step_revision_space_idx" ON "learning_path_step_revision" USING btree ("spaceId");
CREATE INDEX "learning_path_step_revision_step_idx" ON "learning_path_step_revision" USING btree ("stepId");
--
-- Class LearningPathTag as table learning_path_tag
--
CREATE TABLE "learning_path_tag" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"pathId" uuid NOT NULL,
"tagId" uuid NOT NULL
);
-- Indexes
CREATE INDEX "learning_path_tag_space_idx" ON "learning_path_tag" USING btree ("spaceId");
CREATE INDEX "learning_path_tag_path_idx" ON "learning_path_tag" USING btree ("pathId");
CREATE INDEX "learning_path_tag_tag_idx" ON "learning_path_tag" USING btree ("tagId");
--
-- Class Note as table note
--
CREATE TABLE "note" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"studysetId" uuid NOT NULL,
"position" text NOT NULL
);
-- Indexes
CREATE INDEX "note_space_idx" ON "note" USING btree ("spaceId");
CREATE INDEX "note_studyset_idx" ON "note" USING btree ("studysetId", "position");
--
-- Class NoteRevision as table note_revision
--
CREATE TABLE "note_revision" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"noteId" uuid NOT NULL,
"parents" json NOT NULL,
"authorId" uuid NOT NULL,
"reportId" uuid,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "note_revision_space_idx" ON "note_revision" USING btree ("spaceId");
CREATE INDEX "note_revision_note_idx" ON "note_revision" USING btree ("noteId");
--
-- Class NoteTag as table note_tag
--
CREATE TABLE "note_tag" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"noteId" uuid NOT NULL,
"tagId" uuid NOT NULL
);
-- Indexes
CREATE INDEX "note_tag_space_idx" ON "note_tag" USING btree ("spaceId");
CREATE INDEX "note_tag_note_idx" ON "note_tag" USING btree ("noteId");
CREATE INDEX "note_tag_tag_idx" ON "note_tag" USING btree ("tagId");
--
-- Class PdfReading as table pdf_reading
--
CREATE TABLE "pdf_reading" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"pdfSourceId" uuid NOT NULL,
"readAt" timestamp without time zone NOT NULL,
"kind" text NOT NULL,
"page" bigint NOT NULL
);
-- Indexes
CREATE INDEX "pdf_reading_space_idx" ON "pdf_reading" USING btree ("spaceId");
CREATE INDEX "pdf_reading_source_idx" ON "pdf_reading" USING btree ("pdfSourceId", "readAt");
--
-- Class PdfSource as table pdf_source
--
CREATE TABLE "pdf_source" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"studysetId" uuid NOT NULL,
"position" text NOT NULL DEFAULT 'a0'::text,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "pdf_source_space_idx" ON "pdf_source" USING btree ("spaceId");
CREATE INDEX "pdf_source_studyset_idx" ON "pdf_source" USING btree ("studysetId", "position");
--
-- Class PersonSettings as table person_settings
--
CREATE TABLE "person_settings" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "person_settings_space_idx" ON "person_settings" USING btree ("spaceId");
--
-- Class PublishedStudyset as table published_studyset
--
CREATE TABLE "published_studyset" (
"id" bigserial PRIMARY KEY,
"publicId" uuid NOT NULL,
"studysetId" uuid NOT NULL,
"authUserId" uuid NOT NULL,
"slug" text NOT NULL,
"createdAt" timestamp without time zone NOT NULL,
"withdrawnAt" timestamp without time zone,
"learners" bigint NOT NULL DEFAULT 0
);
-- Indexes
CREATE UNIQUE INDEX "published_studyset_public_idx" ON "published_studyset" USING btree ("publicId");
CREATE UNIQUE INDEX "published_studyset_studyset_idx" ON "published_studyset" USING btree ("authUserId", "studysetId");
CREATE UNIQUE INDEX "published_studyset_slug_idx" ON "published_studyset" USING btree ("authUserId", "slug");
--
-- Class ReviewLog as table review_log
--
CREATE TABLE "review_log" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"cardId" uuid NOT NULL,
"rating" bigint NOT NULL,
"reviewedAt" timestamp without time zone NOT NULL,
"durationMs" bigint NOT NULL,
"mode" text NOT NULL DEFAULT 'review'::text
);
-- Indexes
CREATE INDEX "review_log_space_idx" ON "review_log" USING btree ("spaceId");
CREATE INDEX "review_log_card_idx" ON "review_log" USING btree ("cardId", "reviewedAt");
--
-- Class Studyset as table studyset
--
CREATE TABLE "studyset" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"parentId" uuid,
"position" text NOT NULL DEFAULT 'a0'::text,
"archivedAt" timestamp without time zone,
"deletedAt" timestamp without time zone,
"starredAt" timestamp without time zone,
"updatedAt" timestamp without time zone,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "studyset_space_idx" ON "studyset" USING btree ("spaceId");
CREATE INDEX "studyset_parent_idx" ON "studyset" USING btree ("parentId", "position");
--
-- Class StudysetRelease as table studyset_release
--
CREATE TABLE "studyset_release" (
"id" bigserial PRIMARY KEY,
"publishedStudysetId" bigint NOT NULL,
"version" bigint NOT NULL,
"commit" text NOT NULL,
"tree" text NOT NULL,
"notes" text NOT NULL,
"license" text NOT NULL,
"studysetCount" bigint NOT NULL,
"cardCount" bigint NOT NULL,
"noteCount" bigint NOT NULL,
"pathCount" bigint NOT NULL,
"pdfCount" bigint NOT NULL,
"releasedAt" timestamp without time zone NOT NULL,
"title" text NOT NULL DEFAULT ''::text,
"secondaryTitle" text,
"description" text,
"frontLanguage" text,
"backLanguage" text,
"licenseHolder" text,
"licenseYear" bigint,
"basedOn" text,
"colorName" text
);
-- Indexes
CREATE UNIQUE INDEX "studyset_release_version_idx" ON "studyset_release" USING btree ("publishedStudysetId", "version");
--
-- Class Tag as table tag
--
CREATE TABLE "tag" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"spaceId" bigint,
"keyId" text,
"payload" bytea NOT NULL,
"nonce" bytea
);
-- Indexes
CREATE INDEX "tag_space_idx" ON "tag" USING btree ("spaceId");
--
-- Class AccountDeletionNotice as table account_deletion_notice
--
CREATE TABLE "account_deletion_notice" (
"id" bigserial PRIMARY KEY,
"account" uuid NOT NULL,
"member" text NOT NULL,
"createdAt" timestamp without time zone NOT NULL,
"attempts" bigint NOT NULL,
"lastAttemptAt" timestamp without time zone
);
-- Indexes
CREATE UNIQUE INDEX "account_deletion_notice_idx" ON "account_deletion_notice" USING btree ("account", "member");
--
-- Class AccountPassword as table account_password
--
CREATE TABLE "account_password" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"salt" bytea NOT NULL,
"kdfAlgorithm" text NOT NULL,
"kdfOpsLimit" bigint NOT NULL,
"kdfMemLimit" bigint NOT NULL,
"verifier" bytea NOT NULL,
"encryptionPublicKey" bytea NOT NULL,
"signingPublicKey" bytea NOT NULL,
"passwordKeysNonce" bytea NOT NULL,
"passwordKeysCipherText" bytea NOT NULL,
"recoveryKeysNonce" bytea NOT NULL,
"recoveryKeysCipherText" bytea NOT NULL,
"recoveryProofKey" bytea,
"sessionEndedForProofsAt" timestamp without time zone,
"createdAt" timestamp without time zone NOT NULL,
"updatedAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "account_password_person_idx" ON "account_password" USING btree ("authUserId");
--
-- Class AccountReset as table account_reset
--
CREATE TABLE "account_reset" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"kind" text NOT NULL,
"takesEffectAt" timestamp without time zone NOT NULL,
"createdAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "account_reset_person_kind_idx" ON "account_reset" USING btree ("authUserId", "kind");
--
-- Class EmailCodeRequest as table email_code_request
--
CREATE TABLE "email_code_request" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"addressHash" text NOT NULL,
"challengeId" uuid NOT NULL,
"switchChallengeId" uuid,
"purpose" text,
"createdAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE INDEX "email_code_request_address_idx" ON "email_code_request" USING btree ("addressHash");
--
-- Class EmailIdentity as table email_identity
--
CREATE TABLE "email_identity" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"addressHash" text NOT NULL,
"createdAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "email_identity_person_idx" ON "email_identity" USING btree ("authUserId");
CREATE UNIQUE INDEX "email_identity_address_idx" ON "email_identity" USING btree ("addressHash");
--
-- Class PublicProfile as table public_profile
--
CREATE TABLE "public_profile" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"handle" text NOT NULL,
"handleKey" text NOT NULL,
"displayName" text NOT NULL,
"bio" text NOT NULL,
"links" json NOT NULL,
"verifiedLinks" json,
"avatarHash" text,
"firstPublishedAt" timestamp without time zone,
"updatedAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "public_profile_person_idx" ON "public_profile" USING btree ("authUserId");
CREATE UNIQUE INDEX "public_profile_handle_idx" ON "public_profile" USING btree ("handleKey");
--
-- Class RecoveryCode as table recovery_code
--
CREATE TABLE "recovery_code" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"hash" text NOT NULL
);
-- Indexes
CREATE INDEX "recovery_code_person_idx" ON "recovery_code" USING btree ("authUserId");
--
-- Class SecondFactorFailures as table second_factor_failures
--
CREATE TABLE "second_factor_failures" (
"id" bigserial PRIMARY KEY,
"authUserId" uuid NOT NULL,
"path" text NOT NULL DEFAULT 'password'::text,
"failures" bigint NOT NULL,
"waits" bigint NOT NULL,
"waitUntil" timestamp without time zone,
"updatedAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "second_factor_failures_person_idx" ON "second_factor_failures" USING btree ("authUserId", "path");
--
-- Class SessionCodeFailures as table session_code_failures
--
CREATE TABLE "session_code_failures" (
"id" bigserial PRIMARY KEY,
"sessionId" uuid NOT NULL,
"authUserId" uuid NOT NULL,
"failures" bigint NOT NULL,
"updatedAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "session_code_failures_session_idx" ON "session_code_failures" USING btree ("sessionId");
--
-- Class SessionsEndedNotice as table sessions_ended_notice
--
CREATE TABLE "sessions_ended_notice" (
"id" bigserial PRIMARY KEY,
"account" uuid NOT NULL,
"member" text NOT NULL,
"endedBefore" timestamp without time zone NOT NULL,
"keepSession" uuid,
"attempts" bigint NOT NULL,
"lastAttemptAt" timestamp without time zone
);
-- Indexes
CREATE UNIQUE INDEX "sessions_ended_notice_idx" ON "sessions_ended_notice" USING btree ("account", "member");
--
-- Class SignInChallenge as table sign_in_challenge
--
CREATE TABLE "sign_in_challenge" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid,
"purpose" text NOT NULL,
"addressHash" text NOT NULL,
"secret" text NOT NULL,
"serverValue" text,
"createdAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE INDEX "sign_in_challenge_created_idx" ON "sign_in_challenge" USING btree ("createdAt");
--
-- Class TotpAuthenticator as table totp_authenticator
--
CREATE TABLE "totp_authenticator" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"name" text NOT NULL,
"secret" bytea NOT NULL,
"confirmedAt" timestamp without time zone,
"lastStep" bigint,
"createdAt" timestamp without time zone NOT NULL
);
-- Indexes
CREATE INDEX "totp_authenticator_person_idx" ON "totp_authenticator" USING btree ("authUserId");
--
-- Class CloudStorageEntry as table serverpod_cloud_storage
--
CREATE TABLE "serverpod_cloud_storage" (
"id" bigserial PRIMARY KEY,
"storageId" text NOT NULL,
"path" text NOT NULL,
"addedTime" timestamp without time zone NOT NULL,
"expiration" timestamp without time zone,
"byteData" bytea NOT NULL,
"verified" boolean NOT NULL,
"contentType" text,
"cacheControl" text,
"contentDisposition" text,
"contentEncoding" text,
"customMetadata" text
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_cloud_storage_path_idx" ON "serverpod_cloud_storage" USING btree ("storageId", "path");
CREATE INDEX "serverpod_cloud_storage_expiration" ON "serverpod_cloud_storage" USING btree ("expiration");
--
-- Class CloudStorageDirectDownloadEntry as table serverpod_cloud_storage_direct_download
--
CREATE TABLE "serverpod_cloud_storage_direct_download" (
"id" bigserial PRIMARY KEY,
"storageId" text NOT NULL,
"path" text NOT NULL,
"expiration" timestamp without time zone NOT NULL,
"authKey" text NOT NULL,
"downloadFileName" text,
"contentType" text
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_cloud_storage_direct_download_auth_key" ON "serverpod_cloud_storage_direct_download" USING btree ("authKey");
CREATE INDEX "serverpod_cloud_storage_direct_download_expiration" ON "serverpod_cloud_storage_direct_download" USING btree ("expiration");
--
-- Class CloudStorageDirectUploadEntry as table serverpod_cloud_storage_direct_upload
--
CREATE TABLE "serverpod_cloud_storage_direct_upload" (
"id" bigserial PRIMARY KEY,
"storageId" text NOT NULL,
"path" text NOT NULL,
"expiration" timestamp without time zone NOT NULL,
"authKey" text NOT NULL,
"maxFileSize" bigint NOT NULL DEFAULT 10485760,
"contentLength" bigint,
"preventOverwrite" boolean NOT NULL DEFAULT false,
"contentType" text,
"cacheControl" text,
"contentDisposition" text,
"contentEncoding" text,
"customMetadata" text
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_cloud_storage_direct_upload_storage_path" ON "serverpod_cloud_storage_direct_upload" USING btree ("storageId", "path");
--
-- Class FutureCallEntry as table serverpod_future_call
--
CREATE TABLE "serverpod_future_call" (
"id" bigserial PRIMARY KEY,
"name" text NOT NULL,
"time" timestamp without time zone NOT NULL,
"serializedObject" text,
"serverId" text NOT NULL,
"identifier" text,
"scheduling" json
);
-- Indexes
CREATE INDEX "serverpod_future_call_time_idx" ON "serverpod_future_call" USING btree ("time");
CREATE INDEX "serverpod_future_call_serverId_idx" ON "serverpod_future_call" USING btree ("serverId");
CREATE INDEX "serverpod_future_call_identifier_idx" ON "serverpod_future_call" USING btree ("identifier");
--
-- Class FutureCallClaimEntry as table serverpod_future_call_claim
--
CREATE TABLE "serverpod_future_call_claim" (
"id" bigserial PRIMARY KEY,
"futureCallId" bigint,
"lastHeartbeatTime" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "future_call_unique_idx" ON "serverpod_future_call_claim" USING btree ("futureCallId");
--
-- Class ServerHealthConnectionInfo as table serverpod_health_connection_info
--
CREATE TABLE "serverpod_health_connection_info" (
"id" bigserial PRIMARY KEY,
"serverId" text NOT NULL,
"timestamp" timestamp without time zone NOT NULL,
"active" bigint NOT NULL,
"closing" bigint NOT NULL,
"idle" bigint NOT NULL,
"granularity" bigint NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_health_connection_info_timestamp_idx" ON "serverpod_health_connection_info" USING btree ("timestamp", "serverId", "granularity");
--
-- Class ServerHealthMetric as table serverpod_health_metric
--
CREATE TABLE "serverpod_health_metric" (
"id" bigserial PRIMARY KEY,
"name" text NOT NULL,
"serverId" text NOT NULL,
"timestamp" timestamp without time zone NOT NULL,
"isHealthy" boolean NOT NULL,
"value" double precision NOT NULL,
"granularity" bigint NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_health_metric_timestamp_idx" ON "serverpod_health_metric" USING btree ("timestamp", "serverId", "name", "granularity");
--
-- Class LogEntry as table serverpod_log
--
CREATE TABLE "serverpod_log" (
"id" bigserial PRIMARY KEY,
"sessionLogId" bigint NOT NULL,
"messageId" bigint,
"reference" text,
"serverId" text NOT NULL,
"time" timestamp without time zone NOT NULL,
"logLevel" bigint NOT NULL,
"message" text NOT NULL,
"error" text,
"stackTrace" text,
"order" bigint NOT NULL
);
-- Indexes
CREATE INDEX "serverpod_log_sessionLogId_idx" ON "serverpod_log" USING btree ("sessionLogId", "order");
--
-- Class MessageLogEntry as table serverpod_message_log
--
CREATE TABLE "serverpod_message_log" (
"id" bigserial PRIMARY KEY,
"sessionLogId" bigint NOT NULL,
"serverId" text NOT NULL,
"messageId" bigint NOT NULL,
"endpoint" text NOT NULL,
"messageName" text NOT NULL,
"duration" double precision NOT NULL,
"error" text,
"stackTrace" text,
"slow" boolean NOT NULL,
"order" bigint NOT NULL
);
-- Indexes
CREATE INDEX "serverpod_message_log_sessionLogId_idx" ON "serverpod_message_log" USING btree ("sessionLogId", "order");
--
-- Class MethodInfo as table serverpod_method
--
CREATE TABLE "serverpod_method" (
"id" bigserial PRIMARY KEY,
"endpoint" text NOT NULL,
"method" text NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_method_endpoint_method_idx" ON "serverpod_method" USING btree ("endpoint", "method");
--
-- Class DatabaseMigrationVersion as table serverpod_migrations
--
CREATE TABLE "serverpod_migrations" (
"id" bigserial PRIMARY KEY,
"module" text NOT NULL,
"version" text NOT NULL,
"timestamp" timestamp without time zone
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_migrations_ids" ON "serverpod_migrations" USING btree ("module");
--
-- Class QueryLogEntry as table serverpod_query_log
--
CREATE TABLE "serverpod_query_log" (
"id" bigserial PRIMARY KEY,
"serverId" text NOT NULL,
"sessionLogId" bigint NOT NULL,
"messageId" bigint,
"query" text NOT NULL,
"duration" double precision NOT NULL,
"numRows" bigint,
"error" text,
"stackTrace" text,
"slow" boolean NOT NULL,
"order" bigint NOT NULL
);
-- Indexes
CREATE INDEX "serverpod_query_log_sessionLogId_idx" ON "serverpod_query_log" USING btree ("sessionLogId", "order");
--
-- Class ReadWriteTestEntry as table serverpod_readwrite_test
--
CREATE TABLE "serverpod_readwrite_test" (
"id" bigserial PRIMARY KEY,
"number" bigint NOT NULL
);
--
-- Class RuntimeSettings as table serverpod_runtime_settings
--
CREATE TABLE "serverpod_runtime_settings" (
"id" bigserial PRIMARY KEY,
"logSettings" json NOT NULL,
"logSettingsOverrides" json NOT NULL,
"logServiceCalls" boolean NOT NULL,
"logMalformedCalls" boolean NOT NULL
);
--
-- Class SessionLogEntry as table serverpod_session_log
--
CREATE TABLE "serverpod_session_log" (
"id" bigserial PRIMARY KEY,
"serverId" text NOT NULL,
"time" timestamp without time zone NOT NULL,
"module" text,
"endpoint" text,
"method" text,
"duration" double precision,
"numQueries" bigint,
"slow" boolean,
"error" text,
"stackTrace" text,
"authenticatedUserId" bigint,
"userId" text,
"isOpen" boolean,
"touched" timestamp without time zone NOT NULL
);
-- Indexes
CREATE INDEX "serverpod_session_log_serverid_idx" ON "serverpod_session_log" USING btree ("serverId");
CREATE INDEX "serverpod_session_log_time_idx" ON "serverpod_session_log" USING btree ("time");
CREATE INDEX "serverpod_session_log_touched_idx" ON "serverpod_session_log" USING btree ("touched");
CREATE INDEX "serverpod_session_log_isopen_idx" ON "serverpod_session_log" USING btree ("isOpen");
--
-- Class AnonymousAccount as table serverpod_auth_idp_anonymous_account
--
CREATE TABLE "serverpod_auth_idp_anonymous_account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"createdAt" timestamp without time zone NOT NULL
);
--
-- Class AppleAccount as table serverpod_auth_idp_apple_account
--
CREATE TABLE "serverpod_auth_idp_apple_account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"userIdentifier" text NOT NULL,
"refreshToken" text NOT NULL,
"refreshTokenRequestedWithBundleIdentifier" boolean NOT NULL,
"lastRefreshedAt" timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"authUserId" uuid NOT NULL,
"createdAt" timestamp without time zone NOT NULL,
"email" text,
"isEmailVerified" boolean,
"isPrivateEmail" boolean,
"firstName" text,
"lastName" text
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_apple_account_identifier" ON "serverpod_auth_idp_apple_account" USING btree ("userIdentifier");
--
-- Class EmailAccount as table serverpod_auth_idp_email_account
--
CREATE TABLE "serverpod_auth_idp_email_account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"createdAt" timestamp without time zone NOT NULL,
"email" text NOT NULL,
"passwordHash" text NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_idp_email_account_email" ON "serverpod_auth_idp_email_account" USING btree ("email");
--
-- Class EmailAccountPasswordResetRequest as table serverpod_auth_idp_email_account_password_reset_request
--
CREATE TABLE "serverpod_auth_idp_email_account_password_reset_request" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"emailAccountId" uuid NOT NULL,
"createdAt" timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"challengeId" uuid NOT NULL,
"setPasswordChallengeId" uuid
);
--
-- Class EmailAccountRequest as table serverpod_auth_idp_email_account_request
--
CREATE TABLE "serverpod_auth_idp_email_account_request" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"createdAt" timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"email" text NOT NULL,
"challengeId" uuid NOT NULL,
"createAccountChallengeId" uuid
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_idp_email_account_request_email" ON "serverpod_auth_idp_email_account_request" USING btree ("email");
--
-- Class FacebookAccount as table serverpod_auth_idp_facebook_account
--
CREATE TABLE "serverpod_auth_idp_facebook_account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"createdAt" timestamp without time zone NOT NULL,
"userIdentifier" text NOT NULL,
"email" text,
"fullName" text,
"firstName" text,
"lastName" text
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_facebook_account_user_identifier" ON "serverpod_auth_idp_facebook_account" USING btree ("userIdentifier");
--
-- Class FirebaseAccount as table serverpod_auth_idp_firebase_account
--
CREATE TABLE "serverpod_auth_idp_firebase_account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"created" timestamp without time zone NOT NULL,
"email" text,
"phone" text,
"userIdentifier" text NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_firebase_account_user_identifier" ON "serverpod_auth_idp_firebase_account" USING btree ("userIdentifier");
--
-- Class GitHubAccount as table serverpod_auth_idp_github_account
--
CREATE TABLE "serverpod_auth_idp_github_account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"userIdentifier" text NOT NULL,
"email" text,
"created" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_github_account_user_identifier" ON "serverpod_auth_idp_github_account" USING btree ("userIdentifier");
--
-- Class GoogleAccount as table serverpod_auth_idp_google_account
--
CREATE TABLE "serverpod_auth_idp_google_account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"created" timestamp without time zone NOT NULL,
"email" text NOT NULL,
"userIdentifier" text NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_google_account_user_identifier" ON "serverpod_auth_idp_google_account" USING btree ("userIdentifier");
--
-- Class MicrosoftAccount as table serverpod_auth_idp_microsoft_account
--
CREATE TABLE "serverpod_auth_idp_microsoft_account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"userIdentifier" text NOT NULL,
"email" text,
"created" timestamp without time zone NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_microsoft_account_user_identifier" ON "serverpod_auth_idp_microsoft_account" USING btree ("userIdentifier");
--
-- Class PasskeyAccount as table serverpod_auth_idp_passkey_account
--
CREATE TABLE "serverpod_auth_idp_passkey_account" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"createdAt" timestamp without time zone NOT NULL,
"keyId" bytea NOT NULL,
"keyIdBase64" text NOT NULL,
"clientDataJSON" bytea NOT NULL,
"attestationObject" bytea NOT NULL,
"originalChallenge" bytea NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_idp_passkey_account_key_id_base64" ON "serverpod_auth_idp_passkey_account" USING btree ("keyIdBase64");
--
-- Class PasskeyChallenge as table serverpod_auth_idp_passkey_challenge
--
CREATE TABLE "serverpod_auth_idp_passkey_challenge" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"createdAt" timestamp without time zone NOT NULL,
"challenge" bytea NOT NULL
);
--
-- Class RateLimitedRequestAttempt as table serverpod_auth_idp_rate_limited_request_attempt
--
CREATE TABLE "serverpod_auth_idp_rate_limited_request_attempt" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"domain" text NOT NULL,
"source" text NOT NULL,
"key" text NOT NULL,
"ipAddress" text,
"attemptedAt" timestamp without time zone NOT NULL,
"extraData" json
);
-- Indexes
CREATE INDEX "serverpod_auth_idp_rate_limited_request_attempt_composite" ON "serverpod_auth_idp_rate_limited_request_attempt" USING btree ("domain", "source", "key", "attemptedAt");
--
-- Class SecretChallenge as table serverpod_auth_idp_secret_challenge
--
CREATE TABLE "serverpod_auth_idp_secret_challenge" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"challengeCodeHash" text NOT NULL
);
--
-- Class CrdtDataAttemptedValue as table crdt_data_attempted_value
--
CREATE TABLE "crdt_data_attempted_value" (
"id" bigserial PRIMARY KEY,
"fieldId" bigint NOT NULL,
"value" jsonb NOT NULL,
"projectionReason" bigint NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "crdt_data_attempted_value__fieldId__unique_idx" ON "crdt_data_attempted_value" USING btree ("fieldId");
--
-- Class CrdtDataField as table crdt_data_fields
--
CREATE TABLE "crdt_data_fields" (
"id" bigserial PRIMARY KEY,
"hlcDatetime" timestamp without time zone NOT NULL,
"hlcCounter" bigint NOT NULL,
"rowId" bigint NOT NULL,
"columnId" bigint NOT NULL,
"nodeId" bigint NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "crdt_data_fields_row_column_idx" ON "crdt_data_fields" USING btree ("rowId", "columnId");
--
-- Class CrdtDataRow as table crdt_data_rows
--
CREATE TABLE "crdt_data_rows" (
"id" bigserial PRIMARY KEY,
"hlcDatetime" timestamp without time zone NOT NULL,
"hlcCounter" bigint NOT NULL,
"spaceId" bigint NOT NULL,
"tblId" bigint NOT NULL,
"uuidRowId" uuid NOT NULL,
"nodeId" bigint NOT NULL,
"visibility" bigint NOT NULL DEFAULT 0
);
-- Indexes
CREATE UNIQUE INDEX "crdt_data_rows_space_tbl_row_idx" ON "crdt_data_rows" USING btree ("spaceId", "tblId", "uuidRowId");
--
-- Class CrdtDataDeleted as table crdt_data_tombstone
--
CREATE TABLE "crdt_data_tombstone" (
"id" bigserial PRIMARY KEY,
"hlcDatetime" timestamp without time zone NOT NULL,
"hlcCounter" bigint NOT NULL,
"rowId" bigint NOT NULL,
"nodeId" bigint NOT NULL,
"clFlag" bigint NOT NULL,
"reason" bigint NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "crdt_data_tombstone_row_idx" ON "crdt_data_tombstone" USING btree ("rowId");
--
-- Class CrdtNode as table crdt_nodes
--
CREATE TABLE "crdt_nodes" (
"id" bigserial PRIMARY KEY,
"uuidNodeId" uuid NOT NULL DEFAULT gen_random_uuid_v7(),
"lastHlc" jsonb
);
-- Indexes
CREATE UNIQUE INDEX "crdt_nodes__uuidNodeId__unique_idx" ON "crdt_nodes" USING btree ("uuidNodeId");
--
-- Class CrdtSchemaColumn as table crdt_schema_columns
--
CREATE TABLE "crdt_schema_columns" (
"id" bigserial PRIMARY KEY,
"tblId" bigint NOT NULL,
"name" text NOT NULL,
"columnType" text NOT NULL,
"dartType" text NOT NULL,
"isNullable" boolean NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "crdt_schema_columns_table_column_idx" ON "crdt_schema_columns" USING btree ("tblId", "name");
--
-- Class CrdtSchemaTable as table crdt_schema_tables
--
CREATE TABLE "crdt_schema_tables" (
"id" bigserial PRIMARY KEY,
"name" text NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "crdt_schema_tables__name__unique_idx" ON "crdt_schema_tables" USING btree ("name");
--
-- Class OfflineSyncIntegrityViolation as table offline_sync_integrity_violations
--
CREATE TABLE "offline_sync_integrity_violations" (
"id" bigserial PRIMARY KEY,
"type" text NOT NULL,
"domainTableName" text NOT NULL,
"uuidRowId" uuid NOT NULL,
"ownerSpaceUuid" uuid,
"incomingSpaceUuid" uuid NOT NULL,
"operation" text NOT NULL,
"uuidNodeId" uuid,
"crdtDataRowId" bigint,
"hlcDatetime" timestamp without time zone,
"hlcCounter" bigint,
"firstSeenAt" timestamp without time zone NOT NULL,
"lastSeenAt" timestamp without time zone NOT NULL,
"occurrences" bigint NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "offline_sync_integrity_violations_key_idx" ON "offline_sync_integrity_violations" USING btree ("type", "operation", "domainTableName", "uuidRowId", "ownerSpaceUuid", "incomingSpaceUuid");
--
-- Class OfflineSyncSpaceMember as table offline_sync_space_members
--
CREATE TABLE "offline_sync_space_members" (
"id" bigserial PRIMARY KEY,
"spaceId" bigint NOT NULL,
"userUuid" uuid NOT NULL,
"role" text NOT NULL
);
-- Indexes
CREATE UNIQUE INDEX "offline_sync_space_member_unique_idx" ON "offline_sync_space_members" USING btree ("userUuid", "spaceId");
--
-- Class OfflineSyncSpaceNode as table offline_sync_space_nodes
--
CREATE TABLE "offline_sync_space_nodes" (
"id" bigserial PRIMARY KEY,
"spaceId" bigint NOT NULL,
"nodeId" bigint NOT NULL,
"lastReceivedHlc" jsonb
);
-- Indexes
CREATE UNIQUE INDEX "offline_sync_space_node_unique_idx" ON "offline_sync_space_nodes" USING btree ("spaceId", "nodeId");
--
-- Class OfflineSyncSpace as table offline_sync_spaces
--
CREATE TABLE "offline_sync_spaces" (
"id" bigserial PRIMARY KEY,
"uuidSpaceId" uuid NOT NULL DEFAULT gen_random_uuid_v7(),
"currentNodeId" bigint
);
-- Indexes
CREATE UNIQUE INDEX "offline_sync_spaces__uuidSpaceId__unique_idx" ON "offline_sync_spaces" USING btree ("uuidSpaceId");
--
-- Class RefreshToken as table serverpod_auth_core_jwt_refresh_token
--
CREATE TABLE "serverpod_auth_core_jwt_refresh_token" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"scopeNames" json NOT NULL,
"extraClaims" text,
"method" text NOT NULL,
"fixedSecret" bytea NOT NULL,
"rotatingSecretHash" text NOT NULL,
"lastUpdatedAt" timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"createdAt" timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Indexes
CREATE INDEX "serverpod_auth_core_jwt_refresh_token_last_updated_at" ON "serverpod_auth_core_jwt_refresh_token" USING btree ("lastUpdatedAt");
--
-- Class UserProfile as table serverpod_auth_core_profile
--
CREATE TABLE "serverpod_auth_core_profile" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"userName" text,
"fullName" text,
"email" text,
"createdAt" timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"imageId" uuid
);
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_profile_user_profile_email_auth_user_id" ON "serverpod_auth_core_profile" USING btree ("authUserId");
--
-- Class UserProfileImage as table serverpod_auth_core_profile_image
--
CREATE TABLE "serverpod_auth_core_profile_image" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"userProfileId" uuid NOT NULL,
"createdAt" timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"storageId" text NOT NULL,
"path" text NOT NULL,
"url" text NOT NULL
);
--
-- Class ServerSideSession as table serverpod_auth_core_session
--
CREATE TABLE "serverpod_auth_core_session" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"authUserId" uuid NOT NULL,
"scopeNames" json NOT NULL,
"createdAt" timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"lastUsedAt" timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
"expiresAt" timestamp without time zone,
"expireAfterUnusedFor" bigint,
"sessionKeyHash" bytea NOT NULL,
"sessionKeySalt" bytea NOT NULL,
"method" text NOT NULL
);
--
-- Class AuthUser as table serverpod_auth_core_user
--
CREATE TABLE "serverpod_auth_core_user" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid_v7(),
"createdAt" timestamp without time zone NOT NULL,
"scopeNames" json NOT NULL,
"blocked" boolean NOT NULL
);
--
-- Foreign relations for "asset" table
--
ALTER TABLE ONLY "asset"
ADD CONSTRAINT "asset_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "assistant_connection" table
--
ALTER TABLE ONLY "assistant_connection"
ADD CONSTRAINT "assistant_connection_fk_0"
FOREIGN KEY("clientId")
REFERENCES "assistant_client"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "assistant_grant" table
--
ALTER TABLE ONLY "assistant_grant"
ADD CONSTRAINT "assistant_grant_fk_0"
FOREIGN KEY("connectionId")
REFERENCES "assistant_connection"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "assistant_token" table
--
ALTER TABLE ONLY "assistant_token"
ADD CONSTRAINT "assistant_token_fk_0"
FOREIGN KEY("connectionId")
REFERENCES "assistant_connection"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "card" table
--
ALTER TABLE ONLY "card"
ADD CONSTRAINT "card_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "card"
ADD CONSTRAINT "card_fk_1"
FOREIGN KEY("studysetId")
REFERENCES "studyset"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "card_revision" table
--
ALTER TABLE ONLY "card_revision"
ADD CONSTRAINT "card_revision_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "card_revision"
ADD CONSTRAINT "card_revision_fk_1"
FOREIGN KEY("cardId")
REFERENCES "card"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "card_tag" table
--
ALTER TABLE ONLY "card_tag"
ADD CONSTRAINT "card_tag_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "card_tag"
ADD CONSTRAINT "card_tag_fk_1"
FOREIGN KEY("cardId")
REFERENCES "card"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE ONLY "card_tag"
ADD CONSTRAINT "card_tag_fk_2"
FOREIGN KEY("tagId")
REFERENCES "tag"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "discussion_post" table
--
ALTER TABLE ONLY "discussion_post"
ADD CONSTRAINT "discussion_post_fk_0"
FOREIGN KEY("publishedStudysetId")
REFERENCES "published_studyset"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "discussion_post"
ADD CONSTRAINT "discussion_post_fk_1"
FOREIGN KEY("questionId")
REFERENCES "discussion_post"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "discussion_post"
ADD CONSTRAINT "discussion_post_fk_2"
FOREIGN KEY("parentId")
REFERENCES "discussion_post"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "discussion_seen" table
--
ALTER TABLE ONLY "discussion_seen"
ADD CONSTRAINT "discussion_seen_fk_0"
FOREIGN KEY("questionId")
REFERENCES "discussion_post"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "feedback_decision" table
--
ALTER TABLE ONLY "feedback_decision"
ADD CONSTRAINT "feedback_decision_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "feedback_message" table
--
ALTER TABLE ONLY "feedback_message"
ADD CONSTRAINT "feedback_message_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "feedback_thread" table
--
ALTER TABLE ONLY "feedback_thread"
ADD CONSTRAINT "feedback_thread_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "learning_path" table
--
ALTER TABLE ONLY "learning_path"
ADD CONSTRAINT "learning_path_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "learning_path"
ADD CONSTRAINT "learning_path_fk_1"
FOREIGN KEY("studysetId")
REFERENCES "studyset"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "learning_path_answer" table
--
ALTER TABLE ONLY "learning_path_answer"
ADD CONSTRAINT "learning_path_answer_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "learning_path_answer"
ADD CONSTRAINT "learning_path_answer_fk_1"
FOREIGN KEY("stepId")
REFERENCES "learning_path_step"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "learning_path_step" table
--
ALTER TABLE ONLY "learning_path_step"
ADD CONSTRAINT "learning_path_step_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "learning_path_step"
ADD CONSTRAINT "learning_path_step_fk_1"
FOREIGN KEY("pathId")
REFERENCES "learning_path"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "learning_path_step_revision" table
--
ALTER TABLE ONLY "learning_path_step_revision"
ADD CONSTRAINT "learning_path_step_revision_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "learning_path_step_revision"
ADD CONSTRAINT "learning_path_step_revision_fk_1"
FOREIGN KEY("stepId")
REFERENCES "learning_path_step"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "learning_path_tag" table
--
ALTER TABLE ONLY "learning_path_tag"
ADD CONSTRAINT "learning_path_tag_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "learning_path_tag"
ADD CONSTRAINT "learning_path_tag_fk_1"
FOREIGN KEY("pathId")
REFERENCES "learning_path"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE ONLY "learning_path_tag"
ADD CONSTRAINT "learning_path_tag_fk_2"
FOREIGN KEY("tagId")
REFERENCES "tag"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "note" table
--
ALTER TABLE ONLY "note"
ADD CONSTRAINT "note_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "note"
ADD CONSTRAINT "note_fk_1"
FOREIGN KEY("studysetId")
REFERENCES "studyset"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "note_revision" table
--
ALTER TABLE ONLY "note_revision"
ADD CONSTRAINT "note_revision_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "note_revision"
ADD CONSTRAINT "note_revision_fk_1"
FOREIGN KEY("noteId")
REFERENCES "note"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "note_tag" table
--
ALTER TABLE ONLY "note_tag"
ADD CONSTRAINT "note_tag_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "note_tag"
ADD CONSTRAINT "note_tag_fk_1"
FOREIGN KEY("noteId")
REFERENCES "note"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE ONLY "note_tag"
ADD CONSTRAINT "note_tag_fk_2"
FOREIGN KEY("tagId")
REFERENCES "tag"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "pdf_reading" table
--
ALTER TABLE ONLY "pdf_reading"
ADD CONSTRAINT "pdf_reading_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "pdf_reading"
ADD CONSTRAINT "pdf_reading_fk_1"
FOREIGN KEY("pdfSourceId")
REFERENCES "pdf_source"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "pdf_source" table
--
ALTER TABLE ONLY "pdf_source"
ADD CONSTRAINT "pdf_source_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "pdf_source"
ADD CONSTRAINT "pdf_source_fk_1"
FOREIGN KEY("studysetId")
REFERENCES "studyset"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "person_settings" table
--
ALTER TABLE ONLY "person_settings"
ADD CONSTRAINT "person_settings_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "review_log" table
--
ALTER TABLE ONLY "review_log"
ADD CONSTRAINT "review_log_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "review_log"
ADD CONSTRAINT "review_log_fk_1"
FOREIGN KEY("cardId")
REFERENCES "card"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "studyset" table
--
ALTER TABLE ONLY "studyset"
ADD CONSTRAINT "studyset_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "studyset"
ADD CONSTRAINT "studyset_fk_1"
FOREIGN KEY("parentId")
REFERENCES "studyset"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "studyset_release" table
--
ALTER TABLE ONLY "studyset_release"
ADD CONSTRAINT "studyset_release_fk_0"
FOREIGN KEY("publishedStudysetId")
REFERENCES "published_studyset"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "tag" table
--
ALTER TABLE ONLY "tag"
ADD CONSTRAINT "tag_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "email_code_request" table
--
ALTER TABLE ONLY "email_code_request"
ADD CONSTRAINT "email_code_request_fk_0"
FOREIGN KEY("challengeId")
REFERENCES "serverpod_auth_idp_secret_challenge"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "email_code_request"
ADD CONSTRAINT "email_code_request_fk_1"
FOREIGN KEY("switchChallengeId")
REFERENCES "serverpod_auth_idp_secret_challenge"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_future_call_claim" table
--
ALTER TABLE ONLY "serverpod_future_call_claim"
ADD CONSTRAINT "serverpod_future_call_claim_fk_0"
FOREIGN KEY("futureCallId")
REFERENCES "serverpod_future_call"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_log" table
--
ALTER TABLE ONLY "serverpod_log"
ADD CONSTRAINT "serverpod_log_fk_0"
FOREIGN KEY("sessionLogId")
REFERENCES "serverpod_session_log"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_message_log" table
--
ALTER TABLE ONLY "serverpod_message_log"
ADD CONSTRAINT "serverpod_message_log_fk_0"
FOREIGN KEY("sessionLogId")
REFERENCES "serverpod_session_log"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_query_log" table
--
ALTER TABLE ONLY "serverpod_query_log"
ADD CONSTRAINT "serverpod_query_log_fk_0"
FOREIGN KEY("sessionLogId")
REFERENCES "serverpod_session_log"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_anonymous_account" table
--
ALTER TABLE ONLY "serverpod_auth_idp_anonymous_account"
ADD CONSTRAINT "serverpod_auth_idp_anonymous_account_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_apple_account" table
--
ALTER TABLE ONLY "serverpod_auth_idp_apple_account"
ADD CONSTRAINT "serverpod_auth_idp_apple_account_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_email_account" table
--
ALTER TABLE ONLY "serverpod_auth_idp_email_account"
ADD CONSTRAINT "serverpod_auth_idp_email_account_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_email_account_password_reset_request" table
--
ALTER TABLE ONLY "serverpod_auth_idp_email_account_password_reset_request"
ADD CONSTRAINT "serverpod_auth_idp_email_account_password_reset_request_fk_0"
FOREIGN KEY("emailAccountId")
REFERENCES "serverpod_auth_idp_email_account"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "serverpod_auth_idp_email_account_password_reset_request"
ADD CONSTRAINT "serverpod_auth_idp_email_account_password_reset_request_fk_1"
FOREIGN KEY("challengeId")
REFERENCES "serverpod_auth_idp_secret_challenge"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "serverpod_auth_idp_email_account_password_reset_request"
ADD CONSTRAINT "serverpod_auth_idp_email_account_password_reset_request_fk_2"
FOREIGN KEY("setPasswordChallengeId")
REFERENCES "serverpod_auth_idp_secret_challenge"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_email_account_request" table
--
ALTER TABLE ONLY "serverpod_auth_idp_email_account_request"
ADD CONSTRAINT "serverpod_auth_idp_email_account_request_fk_0"
FOREIGN KEY("challengeId")
REFERENCES "serverpod_auth_idp_secret_challenge"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "serverpod_auth_idp_email_account_request"
ADD CONSTRAINT "serverpod_auth_idp_email_account_request_fk_1"
FOREIGN KEY("createAccountChallengeId")
REFERENCES "serverpod_auth_idp_secret_challenge"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_facebook_account" table
--
ALTER TABLE ONLY "serverpod_auth_idp_facebook_account"
ADD CONSTRAINT "serverpod_auth_idp_facebook_account_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_firebase_account" table
--
ALTER TABLE ONLY "serverpod_auth_idp_firebase_account"
ADD CONSTRAINT "serverpod_auth_idp_firebase_account_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_github_account" table
--
ALTER TABLE ONLY "serverpod_auth_idp_github_account"
ADD CONSTRAINT "serverpod_auth_idp_github_account_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_google_account" table
--
ALTER TABLE ONLY "serverpod_auth_idp_google_account"
ADD CONSTRAINT "serverpod_auth_idp_google_account_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_microsoft_account" table
--
ALTER TABLE ONLY "serverpod_auth_idp_microsoft_account"
ADD CONSTRAINT "serverpod_auth_idp_microsoft_account_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_idp_passkey_account" table
--
ALTER TABLE ONLY "serverpod_auth_idp_passkey_account"
ADD CONSTRAINT "serverpod_auth_idp_passkey_account_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "crdt_data_attempted_value" table
--
ALTER TABLE ONLY "crdt_data_attempted_value"
ADD CONSTRAINT "crdt_data_attempted_value_fk_0"
FOREIGN KEY("fieldId")
REFERENCES "crdt_data_fields"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "crdt_data_fields" table
--
ALTER TABLE ONLY "crdt_data_fields"
ADD CONSTRAINT "crdt_data_fields_fk_0"
FOREIGN KEY("rowId")
REFERENCES "crdt_data_rows"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "crdt_data_fields"
ADD CONSTRAINT "crdt_data_fields_fk_1"
FOREIGN KEY("columnId")
REFERENCES "crdt_schema_columns"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "crdt_data_fields"
ADD CONSTRAINT "crdt_data_fields_fk_2"
FOREIGN KEY("nodeId")
REFERENCES "crdt_nodes"("id")
ON DELETE NO ACTION
ON UPDATE NO ACTION;
--
-- Foreign relations for "crdt_data_rows" table
--
ALTER TABLE ONLY "crdt_data_rows"
ADD CONSTRAINT "crdt_data_rows_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "crdt_data_rows"
ADD CONSTRAINT "crdt_data_rows_fk_1"
FOREIGN KEY("tblId")
REFERENCES "crdt_schema_tables"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "crdt_data_rows"
ADD CONSTRAINT "crdt_data_rows_fk_2"
FOREIGN KEY("nodeId")
REFERENCES "crdt_nodes"("id")
ON DELETE NO ACTION
ON UPDATE NO ACTION;
--
-- Foreign relations for "crdt_data_tombstone" table
--
ALTER TABLE ONLY "crdt_data_tombstone"
ADD CONSTRAINT "crdt_data_tombstone_fk_0"
FOREIGN KEY("rowId")
REFERENCES "crdt_data_rows"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "crdt_data_tombstone"
ADD CONSTRAINT "crdt_data_tombstone_fk_1"
FOREIGN KEY("nodeId")
REFERENCES "crdt_nodes"("id")
ON DELETE NO ACTION
ON UPDATE NO ACTION;
--
-- Foreign relations for "crdt_schema_columns" table
--
ALTER TABLE ONLY "crdt_schema_columns"
ADD CONSTRAINT "crdt_schema_columns_fk_0"
FOREIGN KEY("tblId")
REFERENCES "crdt_schema_tables"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "offline_sync_space_members" table
--
ALTER TABLE ONLY "offline_sync_space_members"
ADD CONSTRAINT "offline_sync_space_members_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "offline_sync_space_nodes" table
--
ALTER TABLE ONLY "offline_sync_space_nodes"
ADD CONSTRAINT "offline_sync_space_nodes_fk_0"
FOREIGN KEY("spaceId")
REFERENCES "offline_sync_spaces"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "offline_sync_space_nodes"
ADD CONSTRAINT "offline_sync_space_nodes_fk_1"
FOREIGN KEY("nodeId")
REFERENCES "crdt_nodes"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "offline_sync_spaces" table
--
ALTER TABLE ONLY "offline_sync_spaces"
ADD CONSTRAINT "offline_sync_spaces_fk_0"
FOREIGN KEY("currentNodeId")
REFERENCES "crdt_nodes"("id")
ON DELETE NO ACTION
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_core_jwt_refresh_token" table
--
ALTER TABLE ONLY "serverpod_auth_core_jwt_refresh_token"
ADD CONSTRAINT "serverpod_auth_core_jwt_refresh_token_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_core_profile" table
--
ALTER TABLE ONLY "serverpod_auth_core_profile"
ADD CONSTRAINT "serverpod_auth_core_profile_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
ALTER TABLE ONLY "serverpod_auth_core_profile"
ADD CONSTRAINT "serverpod_auth_core_profile_fk_1"
FOREIGN KEY("imageId")
REFERENCES "serverpod_auth_core_profile_image"("id")
ON DELETE NO ACTION
ON UPDATE NO ACTION
DEFERRABLE INITIALLY DEFERRED;
--
-- Foreign relations for "serverpod_auth_core_profile_image" table
--
ALTER TABLE ONLY "serverpod_auth_core_profile_image"
ADD CONSTRAINT "serverpod_auth_core_profile_image_fk_0"
FOREIGN KEY("userProfileId")
REFERENCES "serverpod_auth_core_profile"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- Foreign relations for "serverpod_auth_core_session" table
--
ALTER TABLE ONLY "serverpod_auth_core_session"
ADD CONSTRAINT "serverpod_auth_core_session_fk_0"
FOREIGN KEY("authUserId")
REFERENCES "serverpod_auth_core_user"("id")
ON DELETE CASCADE
ON UPDATE NO ACTION;
--
-- MIGRATION VERSION FOR halkyon_learn
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('halkyon_learn', '20261021110159867-second-factor-paths', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20261021110159867-second-factor-paths', "timestamp" = now();
--
-- MIGRATION VERSION FOR halkyon_base
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('halkyon_base', '20261021110159448-second-factor-paths', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20261021110159448-second-factor-paths', "timestamp" = now();
--
-- MIGRATION VERSION FOR serverpod
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod', '20260824182259319', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260824182259319', "timestamp" = now();
--
-- MIGRATION VERSION FOR serverpod_auth_idp
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_auth_idp', '20260924105404509', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260924105404509', "timestamp" = now();
--
-- MIGRATION VERSION FOR serverpod_offline_sync
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_offline_sync', '20260914143806119', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260914143806119', "timestamp" = now();
--
-- MIGRATION VERSION FOR serverpod_auth_core
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_auth_core', '20260924105232991', now())
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260924105232991', "timestamp" = now();
COMMIT;