serverpod-offline-sync/test/serverpod_offline_sync_test_server/migrations/20261008234516445/definition.sql
Marcelo Mendonça Soares ee000e348c
fix: Author the column default an upsert writes for a null foreign key (#164)
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-10-08 22:48:47 -03:00

1219 lines
54 KiB
PL/PgSQL

BEGIN;
--
-- Class Address as table address
--
CREATE TABLE "address" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"street" TEXT NOT NULL,
"inhabitantId" BLOB,
CONSTRAINT "address_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "address_fk_1" FOREIGN KEY ("inhabitantId") REFERENCES "person" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "address__inhabitantId__unique_idx" ON "address" ("inhabitantId");
--
-- Class City as table city
--
CREATE TABLE "city" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
CONSTRAINT "city_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
--
-- Class Company as table company
--
CREATE TABLE "company" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"townId" BLOB NOT NULL DEFAULT (X'550e8400e29b41d4a716446655440000'),
CONSTRAINT "company_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "company_fk_1" FOREIGN KEY ("townId") REFERENCES "town" ("id") ON DELETE SET DEFAULT ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class FkChainCascadeMiddle as table fk_chain_cascade_middle
--
CREATE TABLE "fk_chain_cascade_middle" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"rootId" BLOB,
CONSTRAINT "fk_chain_cascade_middle_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "fk_chain_cascade_middle_fk_1" FOREIGN KEY ("rootId") REFERENCES "fk_chain_root" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class FkChainMiddleCascadeChild as table fk_chain_middle_cascade_child
--
CREATE TABLE "fk_chain_middle_cascade_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"restrictBlockerId" BLOB,
CONSTRAINT "fk_chain_middle_cascade_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "fk_chain_middle_cascade_child_fk_1" FOREIGN KEY ("restrictBlockerId") REFERENCES "fk_chain_restrict_blocker" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class FkChainMiddleSetNullChild as table fk_chain_middle_set_null_child
--
CREATE TABLE "fk_chain_middle_set_null_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"restrictBlockerId" BLOB,
CONSTRAINT "fk_chain_middle_set_null_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "fk_chain_middle_set_null_child_fk_1" FOREIGN KEY ("restrictBlockerId") REFERENCES "fk_chain_restrict_blocker" ("id") ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class FkChainRestrictBlocker as table fk_chain_restrict_blocker
--
CREATE TABLE "fk_chain_restrict_blocker" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"cascadeMiddleId" BLOB,
CONSTRAINT "fk_chain_restrict_blocker_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "fk_chain_restrict_blocker_fk_1" FOREIGN KEY ("cascadeMiddleId") REFERENCES "fk_chain_cascade_middle" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class FkChainRoot as table fk_chain_root
--
CREATE TABLE "fk_chain_root" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
CONSTRAINT "fk_chain_root_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
--
-- Class FkChainSetNullCascadeChild as table fk_chain_set_null_cascade_child
--
CREATE TABLE "fk_chain_set_null_cascade_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"setNullMiddleId" BLOB,
CONSTRAINT "fk_chain_set_null_cascade_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "fk_chain_set_null_cascade_child_fk_1" FOREIGN KEY ("setNullMiddleId") REFERENCES "fk_chain_set_null_middle" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class FkChainSetNullMiddle as table fk_chain_set_null_middle
--
CREATE TABLE "fk_chain_set_null_middle" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"cascadeMiddleId" BLOB,
CONSTRAINT "fk_chain_set_null_middle_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "fk_chain_set_null_middle_fk_1" FOREIGN KEY ("cascadeMiddleId") REFERENCES "fk_chain_cascade_middle" ("id") ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class FkChainSetNullRestrictChild as table fk_chain_set_null_restrict_child
--
CREATE TABLE "fk_chain_set_null_restrict_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"setNullMiddleId" BLOB,
CONSTRAINT "fk_chain_set_null_restrict_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "fk_chain_set_null_restrict_child_fk_1" FOREIGN KEY ("setNullMiddleId") REFERENCES "fk_chain_set_null_middle" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class FkChainSetNullSetNullChild as table fk_chain_set_null_set_null_child
--
CREATE TABLE "fk_chain_set_null_set_null_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"setNullMiddleId" BLOB,
CONSTRAINT "fk_chain_set_null_set_null_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "fk_chain_set_null_set_null_child_fk_1" FOREIGN KEY ("setNullMiddleId") REFERENCES "fk_chain_set_null_middle" ("id") ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class Organization as table organization
--
CREATE TABLE "organization" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"cityId" BLOB,
CONSTRAINT "organization_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "organization_fk_1" FOREIGN KEY ("cityId") REFERENCES "city" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class Person as table person
--
CREATE TABLE "person" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"surname" TEXT,
"organizationId" BLOB,
"oldCompanyId" BLOB,
"cityId" BLOB,
CONSTRAINT "person_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "person_fk_1" FOREIGN KEY ("organizationId") REFERENCES "organization" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT "person_fk_2" FOREIGN KEY ("oldCompanyId") REFERENCES "company" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT "person_fk_3" FOREIGN KEY ("cityId") REFERENCES "city" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class RequiredCascadeChild as table required_cascade_child
--
CREATE TABLE "required_cascade_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"parentId" BLOB NOT NULL,
CONSTRAINT "required_cascade_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "required_cascade_child_fk_1" FOREIGN KEY ("parentId") REFERENCES "person" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class RequiredNoActionChild as table required_no_action_child
--
CREATE TABLE "required_no_action_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"parentId" BLOB NOT NULL,
CONSTRAINT "required_no_action_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "required_no_action_child_fk_1" FOREIGN KEY ("parentId") REFERENCES "person" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class RestrictChild as table restrict_child
--
CREATE TABLE "restrict_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"parentId" BLOB,
CONSTRAINT "restrict_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "restrict_child_fk_1" FOREIGN KEY ("parentId") REFERENCES "person" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class SharedChild as table shared_child
--
CREATE TABLE "shared_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"flavor" TEXT NOT NULL DEFAULT ('plain'),
"parentId" BLOB,
CONSTRAINT "shared_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "shared_child_fk_1" FOREIGN KEY ("parentId") REFERENCES "shared_parent" ("id") ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class SharedParent as table shared_parent
--
CREATE TABLE "shared_parent" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
CONSTRAINT "shared_parent_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
--
-- Class Town as table town
--
CREATE TABLE "town" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"cityId" BLOB,
"mayorId" BLOB,
CONSTRAINT "town_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "town_fk_1" FOREIGN KEY ("cityId") REFERENCES "city" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT "town_fk_2" FOREIGN KEY ("mayorId") REFERENCES "person" ("id") ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
--
-- Class Types as table types
--
CREATE TABLE "types" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"aBool" INTEGER NOT NULL,
"aDateTime" INTEGER NOT NULL,
"aText" TEXT NOT NULL,
"anInt" INTEGER NOT NULL,
"anInt64" TEXT NOT NULL,
"aReal" REAL NOT NULL,
"aBlob" BLOB NOT NULL,
"anEnum" INTEGER,
"optionalText" TEXT,
"optionalUuid" BLOB,
"parentId" BLOB,
"jsonDocument" TEXT,
"jsonbDocument" BLOB,
"jsonbNumbers" BLOB,
CONSTRAINT "types_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "types_fk_1" FOREIGN KEY ("parentId") REFERENCES "types" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE INDEX "types_a_text_idx" ON "types" ("aText");
--
-- Class Unique as table unique
--
CREATE TABLE "unique" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
CONSTRAINT "unique_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique__spaceId__name__unique_idx" ON "unique" ("spaceId", "name");
--
-- Class UniqueCascadeChild as table unique_cascade_child
--
CREATE TABLE "unique_cascade_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"parentId" BLOB,
CONSTRAINT "unique_cascade_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "unique_cascade_child_fk_1" FOREIGN KEY ("parentId") REFERENCES "person" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_cascade_child__spaceId__name__unique_idx" ON "unique_cascade_child" ("spaceId", "name");
--
-- Class UniqueCascadeReference as table unique_cascade_reference
--
CREATE TABLE "unique_cascade_reference" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"parentId" BLOB,
CONSTRAINT "unique_cascade_reference_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "unique_cascade_reference_fk_1" FOREIGN KEY ("parentId") REFERENCES "person" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_cascade_reference__parentId__unique_idx" ON "unique_cascade_reference" ("parentId");
--
-- Class UniqueComposite as table unique_composite
--
CREATE TABLE "unique_composite" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"scope" TEXT NOT NULL,
"value" TEXT NOT NULL,
CONSTRAINT "unique_composite_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_composite__spaceId__scope__value__unique_idx" ON "unique_composite" ("spaceId", "scope", "value");
--
-- Class UniqueDiscriminator as table unique_discriminator
--
CREATE TABLE "unique_discriminator" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"categoryId" INTEGER NOT NULL,
"name" TEXT NOT NULL,
CONSTRAINT "unique_discriminator_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_discriminator__spaceId__categoryId__name__unique_idx" ON "unique_discriminator" ("spaceId", "categoryId", "name");
--
-- Class UniqueFkPair as table unique_fk_pair
--
CREATE TABLE "unique_fk_pair" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"leftId" BLOB,
"rightId" BLOB,
CONSTRAINT "unique_fk_pair_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "unique_fk_pair_fk_1" FOREIGN KEY ("leftId") REFERENCES "person" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED,
CONSTRAINT "unique_fk_pair_fk_2" FOREIGN KEY ("rightId") REFERENCES "person" ("id") ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_fk_pair_parents" ON "unique_fk_pair" ("leftId", "rightId");
--
-- Class UniqueMixedFk as table unique_mixed_fk
--
CREATE TABLE "unique_mixed_fk" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"parentId" BLOB,
CONSTRAINT "unique_mixed_fk_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "unique_mixed_fk_fk_1" FOREIGN KEY ("parentId") REFERENCES "person" ("id") ON DELETE CASCADE ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_mixed_fk_name_parent" ON "unique_mixed_fk" ("spaceId", "name", "parentId");
--
-- Class UniqueNoRelease as table unique_no_release
--
CREATE TABLE "unique_no_release" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"categoryId" INTEGER NOT NULL,
CONSTRAINT "unique_no_release_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_no_release__spaceId__categoryId__unique_idx" ON "unique_no_release" ("spaceId", "categoryId");
--
-- Class UniqueNullable as table unique_nullable
--
CREATE TABLE "unique_nullable" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"value" INTEGER,
CONSTRAINT "unique_nullable_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_nullable__spaceId__value__unique_idx" ON "unique_nullable" ("spaceId", "value");
--
-- Class UniqueOverlapping as table unique_overlapping
--
CREATE TABLE "unique_overlapping" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"first" TEXT NOT NULL,
"second" TEXT NOT NULL,
"third" TEXT NOT NULL,
CONSTRAINT "unique_overlapping_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_overlapping_first_second" ON "unique_overlapping" ("spaceId", "first", "second");
CREATE UNIQUE INDEX "unique_overlapping_second_third" ON "unique_overlapping" ("spaceId", "second", "third");
--
-- Class UniqueSetDefaultChild as table unique_set_default_child
--
CREATE TABLE "unique_set_default_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"parentId" BLOB DEFAULT (X'550e8400e29b41d4a716446655440000'),
CONSTRAINT "unique_set_default_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "unique_set_default_child_fk_1" FOREIGN KEY ("parentId") REFERENCES "town" ("id") ON DELETE SET DEFAULT ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_set_default_child__parentId__unique_idx" ON "unique_set_default_child" ("parentId");
CREATE UNIQUE INDEX "unique_set_default_child_name" ON "unique_set_default_child" ("spaceId", "name");
--
-- Class UniqueSetNullChild as table unique_set_null_child
--
CREATE TABLE "unique_set_null_child" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"name" TEXT NOT NULL,
"parentId" BLOB,
CONSTRAINT "unique_set_null_child_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "unique_set_null_child_fk_1" FOREIGN KEY ("parentId") REFERENCES "person" ("id") ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_set_null_child__parentId__unique_idx" ON "unique_set_null_child" ("parentId");
--
-- Class UniqueUuid as table unique_uuid
--
CREATE TABLE "unique_uuid" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"spaceId" INTEGER,
"value" BLOB NOT NULL,
CONSTRAINT "unique_uuid_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "unique_uuid__spaceId__value__unique_idx" ON "unique_uuid" ("spaceId", "value");
--
-- Class CloudStorageEntry as table serverpod_cloud_storage
--
CREATE TABLE "serverpod_cloud_storage" (
"id" INTEGER PRIMARY KEY,
"storageId" TEXT NOT NULL,
"path" TEXT NOT NULL,
"addedTime" INTEGER NOT NULL,
"expiration" INTEGER,
"byteData" BLOB NOT NULL,
"verified" INTEGER NOT NULL,
"contentType" TEXT,
"cacheControl" TEXT,
"contentDisposition" TEXT,
"contentEncoding" TEXT,
"customMetadata" TEXT
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "serverpod_cloud_storage_path_idx" ON "serverpod_cloud_storage" ("storageId", "path");
CREATE INDEX "serverpod_cloud_storage_expiration" ON "serverpod_cloud_storage" ("expiration");
--
-- Class CloudStorageDirectDownloadEntry as table serverpod_cloud_storage_direct_download
--
CREATE TABLE "serverpod_cloud_storage_direct_download" (
"id" INTEGER PRIMARY KEY,
"storageId" TEXT NOT NULL,
"path" TEXT NOT NULL,
"expiration" INTEGER NOT NULL,
"authKey" TEXT NOT NULL,
"downloadFileName" TEXT,
"contentType" TEXT
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "serverpod_cloud_storage_direct_download_auth_key" ON "serverpod_cloud_storage_direct_download" ("authKey");
CREATE INDEX "serverpod_cloud_storage_direct_download_expiration" ON "serverpod_cloud_storage_direct_download" ("expiration");
--
-- Class CloudStorageDirectUploadEntry as table serverpod_cloud_storage_direct_upload
--
CREATE TABLE "serverpod_cloud_storage_direct_upload" (
"id" INTEGER PRIMARY KEY,
"storageId" TEXT NOT NULL,
"path" TEXT NOT NULL,
"expiration" INTEGER NOT NULL,
"authKey" TEXT NOT NULL,
"maxFileSize" INTEGER NOT NULL DEFAULT (10485760),
"contentLength" INTEGER,
"preventOverwrite" INTEGER NOT NULL DEFAULT (0),
"contentType" TEXT,
"cacheControl" TEXT,
"contentDisposition" TEXT,
"contentEncoding" TEXT,
"customMetadata" TEXT
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "serverpod_cloud_storage_direct_upload_storage_path" ON "serverpod_cloud_storage_direct_upload" ("storageId", "path");
--
-- Class FutureCallEntry as table serverpod_future_call
--
CREATE TABLE "serverpod_future_call" (
"id" INTEGER PRIMARY KEY,
"name" TEXT NOT NULL,
"time" INTEGER NOT NULL,
"serializedObject" TEXT,
"serverId" TEXT NOT NULL,
"identifier" TEXT,
"scheduling" TEXT
) STRICT;
-- Indexes
CREATE INDEX "serverpod_future_call_time_idx" ON "serverpod_future_call" ("time");
CREATE INDEX "serverpod_future_call_serverId_idx" ON "serverpod_future_call" ("serverId");
CREATE INDEX "serverpod_future_call_identifier_idx" ON "serverpod_future_call" ("identifier");
--
-- Class FutureCallClaimEntry as table serverpod_future_call_claim
--
CREATE TABLE "serverpod_future_call_claim" (
"id" INTEGER PRIMARY KEY,
"futureCallId" INTEGER,
"lastHeartbeatTime" INTEGER NOT NULL,
CONSTRAINT "serverpod_future_call_claim_fk_0" FOREIGN KEY ("futureCallId") REFERENCES "serverpod_future_call" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "future_call_unique_idx" ON "serverpod_future_call_claim" ("futureCallId");
--
-- Class ServerHealthConnectionInfo as table serverpod_health_connection_info
--
CREATE TABLE "serverpod_health_connection_info" (
"id" INTEGER PRIMARY KEY,
"serverId" TEXT NOT NULL,
"timestamp" INTEGER NOT NULL,
"active" INTEGER NOT NULL,
"closing" INTEGER NOT NULL,
"idle" INTEGER NOT NULL,
"granularity" INTEGER NOT NULL
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "serverpod_health_connection_info_timestamp_idx" ON "serverpod_health_connection_info" ("timestamp", "serverId", "granularity");
--
-- Class ServerHealthMetric as table serverpod_health_metric
--
CREATE TABLE "serverpod_health_metric" (
"id" INTEGER PRIMARY KEY,
"name" TEXT NOT NULL,
"serverId" TEXT NOT NULL,
"timestamp" INTEGER NOT NULL,
"isHealthy" INTEGER NOT NULL,
"value" REAL NOT NULL,
"granularity" INTEGER NOT NULL
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "serverpod_health_metric_timestamp_idx" ON "serverpod_health_metric" ("timestamp", "serverId", "name", "granularity");
--
-- Class LogEntry as table serverpod_log
--
CREATE TABLE "serverpod_log" (
"id" INTEGER PRIMARY KEY,
"sessionLogId" INTEGER NOT NULL,
"messageId" INTEGER,
"reference" TEXT,
"serverId" TEXT NOT NULL,
"time" INTEGER NOT NULL,
"logLevel" INTEGER NOT NULL,
"message" TEXT NOT NULL,
"error" TEXT,
"stackTrace" TEXT,
"order" INTEGER NOT NULL,
CONSTRAINT "serverpod_log_fk_0" FOREIGN KEY ("sessionLogId") REFERENCES "serverpod_session_log" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE INDEX "serverpod_log_sessionLogId_idx" ON "serverpod_log" ("sessionLogId", "order");
--
-- Class MessageLogEntry as table serverpod_message_log
--
CREATE TABLE "serverpod_message_log" (
"id" INTEGER PRIMARY KEY,
"sessionLogId" INTEGER NOT NULL,
"serverId" TEXT NOT NULL,
"messageId" INTEGER NOT NULL,
"endpoint" TEXT NOT NULL,
"messageName" TEXT NOT NULL,
"duration" REAL NOT NULL,
"error" TEXT,
"stackTrace" TEXT,
"slow" INTEGER NOT NULL,
"order" INTEGER NOT NULL,
CONSTRAINT "serverpod_message_log_fk_0" FOREIGN KEY ("sessionLogId") REFERENCES "serverpod_session_log" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE INDEX "serverpod_message_log_sessionLogId_idx" ON "serverpod_message_log" ("sessionLogId", "order");
--
-- Class MethodInfo as table serverpod_method
--
CREATE TABLE "serverpod_method" (
"id" INTEGER PRIMARY KEY,
"endpoint" TEXT NOT NULL,
"method" TEXT NOT NULL
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "serverpod_method_endpoint_method_idx" ON "serverpod_method" ("endpoint", "method");
--
-- Class DatabaseMigrationVersion as table serverpod_migrations
--
CREATE TABLE "serverpod_migrations" (
"id" INTEGER PRIMARY KEY,
"module" TEXT NOT NULL,
"version" TEXT NOT NULL,
"timestamp" INTEGER
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "serverpod_migrations_ids" ON "serverpod_migrations" ("module");
--
-- Class QueryLogEntry as table serverpod_query_log
--
CREATE TABLE "serverpod_query_log" (
"id" INTEGER PRIMARY KEY,
"serverId" TEXT NOT NULL,
"sessionLogId" INTEGER NOT NULL,
"messageId" INTEGER,
"query" TEXT NOT NULL,
"duration" REAL NOT NULL,
"numRows" INTEGER,
"error" TEXT,
"stackTrace" TEXT,
"slow" INTEGER NOT NULL,
"order" INTEGER NOT NULL,
CONSTRAINT "serverpod_query_log_fk_0" FOREIGN KEY ("sessionLogId") REFERENCES "serverpod_session_log" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE INDEX "serverpod_query_log_sessionLogId_idx" ON "serverpod_query_log" ("sessionLogId", "order");
--
-- Class ReadWriteTestEntry as table serverpod_readwrite_test
--
CREATE TABLE "serverpod_readwrite_test" (
"id" INTEGER PRIMARY KEY,
"number" INTEGER NOT NULL
) STRICT;
--
-- Class RuntimeSettings as table serverpod_runtime_settings
--
CREATE TABLE "serverpod_runtime_settings" (
"id" INTEGER PRIMARY KEY,
"logSettings" TEXT NOT NULL,
"logSettingsOverrides" TEXT NOT NULL,
"logServiceCalls" INTEGER NOT NULL,
"logMalformedCalls" INTEGER NOT NULL
) STRICT;
--
-- Class SessionLogEntry as table serverpod_session_log
--
CREATE TABLE "serverpod_session_log" (
"id" INTEGER PRIMARY KEY,
"serverId" TEXT NOT NULL,
"time" INTEGER NOT NULL,
"module" TEXT,
"endpoint" TEXT,
"method" TEXT,
"duration" REAL,
"numQueries" INTEGER,
"slow" INTEGER,
"error" TEXT,
"stackTrace" TEXT,
"authenticatedUserId" INTEGER,
"userId" TEXT,
"isOpen" INTEGER,
"touched" INTEGER NOT NULL
) STRICT;
-- Indexes
CREATE INDEX "serverpod_session_log_serverid_idx" ON "serverpod_session_log" ("serverId");
CREATE INDEX "serverpod_session_log_time_idx" ON "serverpod_session_log" ("time");
CREATE INDEX "serverpod_session_log_touched_idx" ON "serverpod_session_log" ("touched");
CREATE INDEX "serverpod_session_log_isopen_idx" ON "serverpod_session_log" ("isOpen");
--
-- Class RefreshToken as table serverpod_auth_core_jwt_refresh_token
--
CREATE TABLE "serverpod_auth_core_jwt_refresh_token" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"authUserId" BLOB NOT NULL,
"scopeNames" TEXT NOT NULL,
"extraClaims" TEXT,
"method" TEXT NOT NULL,
"fixedSecret" BLOB NOT NULL,
"rotatingSecretHash" TEXT NOT NULL,
"lastUpdatedAt" INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsecond') * 1000 AS INTEGER)),
"createdAt" INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsecond') * 1000 AS INTEGER)),
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
) STRICT;
-- Indexes
CREATE INDEX "serverpod_auth_core_jwt_refresh_token_last_updated_at" ON "serverpod_auth_core_jwt_refresh_token" ("lastUpdatedAt");
--
-- Class UserProfile as table serverpod_auth_core_profile
--
CREATE TABLE "serverpod_auth_core_profile" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"authUserId" BLOB NOT NULL,
"userName" TEXT,
"fullName" TEXT,
"email" TEXT,
"createdAt" INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsecond') * 1000 AS INTEGER)),
"imageId" BLOB,
CONSTRAINT "serverpod_auth_core_profile_fk_0" FOREIGN KEY ("authUserId") REFERENCES "serverpod_auth_core_user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
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
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "serverpod_auth_profile_user_profile_email_auth_user_id" ON "serverpod_auth_core_profile" ("authUserId");
--
-- Class UserProfileImage as table serverpod_auth_core_profile_image
--
CREATE TABLE "serverpod_auth_core_profile_image" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"userProfileId" BLOB NOT NULL,
"createdAt" INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsecond') * 1000 AS INTEGER)),
"storageId" TEXT NOT NULL,
"path" TEXT NOT NULL,
"url" TEXT NOT NULL,
CONSTRAINT "serverpod_auth_core_profile_image_fk_0" FOREIGN KEY ("userProfileId") REFERENCES "serverpod_auth_core_profile" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
--
-- Class ServerSideSession as table serverpod_auth_core_session
--
CREATE TABLE "serverpod_auth_core_session" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"authUserId" BLOB NOT NULL,
"scopeNames" TEXT NOT NULL,
"createdAt" INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsecond') * 1000 AS INTEGER)),
"lastUsedAt" INTEGER NOT NULL DEFAULT (CAST(unixepoch('subsecond') * 1000 AS INTEGER)),
"expiresAt" INTEGER,
"expireAfterUnusedFor" INTEGER,
"sessionKeyHash" BLOB NOT NULL,
"sessionKeySalt" BLOB NOT NULL,
"method" TEXT NOT NULL,
CONSTRAINT "serverpod_auth_core_session_fk_0" FOREIGN KEY ("authUserId") REFERENCES "serverpod_auth_core_user" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
--
-- Class AuthUser as table serverpod_auth_core_user
--
CREATE TABLE "serverpod_auth_core_user" (
"id" BLOB PRIMARY KEY DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"createdAt" INTEGER NOT NULL,
"scopeNames" TEXT NOT NULL,
"blocked" INTEGER NOT NULL
) STRICT;
--
-- Class CrdtDataAttemptedValue as table crdt_data_attempted_value
--
CREATE TABLE "crdt_data_attempted_value" (
"id" INTEGER PRIMARY KEY,
"fieldId" INTEGER NOT NULL,
"value" BLOB NOT NULL,
"projectionReason" INTEGER NOT NULL,
CONSTRAINT "crdt_data_attempted_value_fk_0" FOREIGN KEY ("fieldId") REFERENCES "crdt_data_fields" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "crdt_data_attempted_value__fieldId__unique_idx" ON "crdt_data_attempted_value" ("fieldId");
--
-- Class CrdtDataField as table crdt_data_fields
--
CREATE TABLE "crdt_data_fields" (
"id" INTEGER PRIMARY KEY,
"hlcDatetime" INTEGER NOT NULL,
"hlcCounter" INTEGER NOT NULL,
"rowId" INTEGER NOT NULL,
"columnId" INTEGER NOT NULL,
"nodeId" INTEGER NOT NULL,
CONSTRAINT "crdt_data_fields_fk_0" FOREIGN KEY ("rowId") REFERENCES "crdt_data_rows" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "crdt_data_fields_fk_1" FOREIGN KEY ("columnId") REFERENCES "crdt_schema_columns" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "crdt_data_fields_fk_2" FOREIGN KEY ("nodeId") REFERENCES "crdt_nodes" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "crdt_data_fields_row_column_idx" ON "crdt_data_fields" ("rowId", "columnId");
--
-- Class CrdtDataRow as table crdt_data_rows
--
CREATE TABLE "crdt_data_rows" (
"id" INTEGER PRIMARY KEY,
"hlcDatetime" INTEGER NOT NULL,
"hlcCounter" INTEGER NOT NULL,
"spaceId" INTEGER NOT NULL,
"tblId" INTEGER NOT NULL,
"uuidRowId" BLOB NOT NULL,
"nodeId" INTEGER NOT NULL,
"visibility" INTEGER NOT NULL DEFAULT (0),
CONSTRAINT "crdt_data_rows_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "crdt_data_rows_fk_1" FOREIGN KEY ("tblId") REFERENCES "crdt_schema_tables" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "crdt_data_rows_fk_2" FOREIGN KEY ("nodeId") REFERENCES "crdt_nodes" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "crdt_data_rows_space_tbl_row_idx" ON "crdt_data_rows" ("spaceId", "tblId", "uuidRowId");
--
-- Class CrdtDataDeleted as table crdt_data_tombstone
--
CREATE TABLE "crdt_data_tombstone" (
"id" INTEGER PRIMARY KEY,
"hlcDatetime" INTEGER NOT NULL,
"hlcCounter" INTEGER NOT NULL,
"rowId" INTEGER NOT NULL,
"nodeId" INTEGER NOT NULL,
"clFlag" INTEGER NOT NULL,
"reason" INTEGER NOT NULL,
CONSTRAINT "crdt_data_tombstone_fk_0" FOREIGN KEY ("rowId") REFERENCES "crdt_data_rows" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "crdt_data_tombstone_fk_1" FOREIGN KEY ("nodeId") REFERENCES "crdt_nodes" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "crdt_data_tombstone_row_idx" ON "crdt_data_tombstone" ("rowId");
--
-- Class CrdtNode as table crdt_nodes
--
CREATE TABLE "crdt_nodes" (
"id" INTEGER PRIMARY KEY,
"uuidNodeId" BLOB NOT NULL DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"lastHlc" BLOB
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "crdt_nodes__uuidNodeId__unique_idx" ON "crdt_nodes" ("uuidNodeId");
--
-- Class CrdtSchemaColumn as table crdt_schema_columns
--
CREATE TABLE "crdt_schema_columns" (
"id" INTEGER PRIMARY KEY,
"tblId" INTEGER NOT NULL,
"name" TEXT NOT NULL,
"columnType" TEXT NOT NULL,
"dartType" TEXT NOT NULL,
"isNullable" INTEGER NOT NULL,
CONSTRAINT "crdt_schema_columns_fk_0" FOREIGN KEY ("tblId") REFERENCES "crdt_schema_tables" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "crdt_schema_columns_table_column_idx" ON "crdt_schema_columns" ("tblId", "name");
--
-- Class CrdtSchemaTable as table crdt_schema_tables
--
CREATE TABLE "crdt_schema_tables" (
"id" INTEGER PRIMARY KEY,
"name" TEXT NOT NULL
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "crdt_schema_tables__name__unique_idx" ON "crdt_schema_tables" ("name");
--
-- Class OfflineSyncIntegrityViolation as table offline_sync_integrity_violations
--
CREATE TABLE "offline_sync_integrity_violations" (
"id" INTEGER PRIMARY KEY,
"type" TEXT NOT NULL,
"domainTableName" TEXT NOT NULL,
"uuidRowId" BLOB NOT NULL,
"ownerSpaceUuid" BLOB,
"incomingSpaceUuid" BLOB NOT NULL,
"operation" TEXT NOT NULL,
"uuidNodeId" BLOB,
"crdtDataRowId" INTEGER,
"hlcDatetime" INTEGER,
"hlcCounter" INTEGER,
"firstSeenAt" INTEGER NOT NULL,
"lastSeenAt" INTEGER NOT NULL,
"occurrences" INTEGER NOT NULL
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "offline_sync_integrity_violations_key_idx" ON "offline_sync_integrity_violations" ("type", "operation", "domainTableName", "uuidRowId", "ownerSpaceUuid", "incomingSpaceUuid");
--
-- Class OfflineSyncSpaceMember as table offline_sync_space_members
--
CREATE TABLE "offline_sync_space_members" (
"id" INTEGER PRIMARY KEY,
"spaceId" INTEGER NOT NULL,
"userUuid" BLOB NOT NULL,
"role" TEXT NOT NULL,
CONSTRAINT "offline_sync_space_members_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "offline_sync_space_member_unique_idx" ON "offline_sync_space_members" ("userUuid", "spaceId");
--
-- Class OfflineSyncSpaceNode as table offline_sync_space_nodes
--
CREATE TABLE "offline_sync_space_nodes" (
"id" INTEGER PRIMARY KEY,
"spaceId" INTEGER NOT NULL,
"nodeId" INTEGER NOT NULL,
"lastReceivedHlc" BLOB,
CONSTRAINT "offline_sync_space_nodes_fk_0" FOREIGN KEY ("spaceId") REFERENCES "offline_sync_spaces" ("id") ON DELETE CASCADE ON UPDATE NO ACTION,
CONSTRAINT "offline_sync_space_nodes_fk_1" FOREIGN KEY ("nodeId") REFERENCES "crdt_nodes" ("id") ON DELETE CASCADE ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "offline_sync_space_node_unique_idx" ON "offline_sync_space_nodes" ("spaceId", "nodeId");
--
-- Class OfflineSyncSpace as table offline_sync_spaces
--
CREATE TABLE "offline_sync_spaces" (
"id" INTEGER PRIMARY KEY,
"uuidSpaceId" BLOB NOT NULL DEFAULT (unhex(printf('%012x', CAST(unixepoch('now', 'subsecond') * 1000 AS INTEGER)) || '7' || substr(hex(randomblob(2)), 2, 3) || substr('89AB', 1 + (abs(random()) % 4), 1) || substr(hex(randomblob(8)), 2, 15))),
"currentNodeId" INTEGER,
CONSTRAINT "offline_sync_spaces_fk_0" FOREIGN KEY ("currentNodeId") REFERENCES "crdt_nodes" ("id") ON DELETE NO ACTION ON UPDATE NO ACTION
) STRICT;
-- Indexes
CREATE UNIQUE INDEX "offline_sync_spaces__uuidSpaceId__unique_idx" ON "offline_sync_spaces" ("uuidSpaceId");
--
-- STORE COLUMN TYPES FOR MIGRATIONS
--
DROP TABLE IF EXISTS "serverpod_sqlite_schema";
CREATE TABLE "serverpod_sqlite_schema" (
"table_name" TEXT NOT NULL,
"column_name" TEXT NOT NULL,
"column_type" TEXT NOT NULL,
"column_vector_dimension" INTEGER,
PRIMARY KEY ("table_name", "column_name")
);
INSERT INTO "serverpod_sqlite_schema" VALUES
('address', 'id', 'uuid', NULL),
('address', 'inhabitantId', 'uuid', NULL),
('city', 'id', 'uuid', NULL),
('company', 'id', 'uuid', NULL),
('company', 'townId', 'uuid', NULL),
('fk_chain_cascade_middle', 'id', 'uuid', NULL),
('fk_chain_cascade_middle', 'rootId', 'uuid', NULL),
('fk_chain_middle_cascade_child', 'id', 'uuid', NULL),
('fk_chain_middle_cascade_child', 'restrictBlockerId', 'uuid', NULL),
('fk_chain_middle_set_null_child', 'id', 'uuid', NULL),
('fk_chain_middle_set_null_child', 'restrictBlockerId', 'uuid', NULL),
('fk_chain_restrict_blocker', 'id', 'uuid', NULL),
('fk_chain_restrict_blocker', 'cascadeMiddleId', 'uuid', NULL),
('fk_chain_root', 'id', 'uuid', NULL),
('fk_chain_set_null_cascade_child', 'id', 'uuid', NULL),
('fk_chain_set_null_cascade_child', 'setNullMiddleId', 'uuid', NULL),
('fk_chain_set_null_middle', 'id', 'uuid', NULL),
('fk_chain_set_null_middle', 'cascadeMiddleId', 'uuid', NULL),
('fk_chain_set_null_restrict_child', 'id', 'uuid', NULL),
('fk_chain_set_null_restrict_child', 'setNullMiddleId', 'uuid', NULL),
('fk_chain_set_null_set_null_child', 'id', 'uuid', NULL),
('fk_chain_set_null_set_null_child', 'setNullMiddleId', 'uuid', NULL),
('organization', 'id', 'uuid', NULL),
('organization', 'cityId', 'uuid', NULL),
('person', 'id', 'uuid', NULL),
('person', 'organizationId', 'uuid', NULL),
('person', 'oldCompanyId', 'uuid', NULL),
('person', 'cityId', 'uuid', NULL),
('required_cascade_child', 'id', 'uuid', NULL),
('required_cascade_child', 'parentId', 'uuid', NULL),
('required_no_action_child', 'id', 'uuid', NULL),
('required_no_action_child', 'parentId', 'uuid', NULL),
('restrict_child', 'id', 'uuid', NULL),
('restrict_child', 'parentId', 'uuid', NULL),
('shared_child', 'id', 'uuid', NULL),
('shared_child', 'parentId', 'uuid', NULL),
('shared_parent', 'id', 'uuid', NULL),
('town', 'id', 'uuid', NULL),
('town', 'cityId', 'uuid', NULL),
('town', 'mayorId', 'uuid', NULL),
('types', 'id', 'uuid', NULL),
('types', 'aBool', 'boolean', NULL),
('types', 'aDateTime', 'timestampWithoutTimeZone', NULL),
('types', 'optionalUuid', 'uuid', NULL),
('types', 'parentId', 'uuid', NULL),
('types', 'jsonDocument', 'json', NULL),
('types', 'jsonbDocument', 'jsonb', NULL),
('types', 'jsonbNumbers', 'jsonb', NULL),
('unique', 'id', 'uuid', NULL),
('unique_cascade_child', 'id', 'uuid', NULL),
('unique_cascade_child', 'parentId', 'uuid', NULL),
('unique_cascade_reference', 'id', 'uuid', NULL),
('unique_cascade_reference', 'parentId', 'uuid', NULL),
('unique_composite', 'id', 'uuid', NULL),
('unique_discriminator', 'id', 'uuid', NULL),
('unique_fk_pair', 'id', 'uuid', NULL),
('unique_fk_pair', 'leftId', 'uuid', NULL),
('unique_fk_pair', 'rightId', 'uuid', NULL),
('unique_mixed_fk', 'id', 'uuid', NULL),
('unique_mixed_fk', 'parentId', 'uuid', NULL),
('unique_no_release', 'id', 'uuid', NULL),
('unique_nullable', 'id', 'uuid', NULL),
('unique_overlapping', 'id', 'uuid', NULL),
('unique_set_default_child', 'id', 'uuid', NULL),
('unique_set_default_child', 'parentId', 'uuid', NULL),
('unique_set_null_child', 'id', 'uuid', NULL),
('unique_set_null_child', 'parentId', 'uuid', NULL),
('unique_uuid', 'id', 'uuid', NULL),
('unique_uuid', 'value', 'uuid', NULL),
('serverpod_cloud_storage', 'addedTime', 'timestampWithoutTimeZone', NULL),
('serverpod_cloud_storage', 'expiration', 'timestampWithoutTimeZone', NULL),
('serverpod_cloud_storage', 'verified', 'boolean', NULL),
('serverpod_cloud_storage_direct_download', 'expiration', 'timestampWithoutTimeZone', NULL),
('serverpod_cloud_storage_direct_upload', 'expiration', 'timestampWithoutTimeZone', NULL),
('serverpod_cloud_storage_direct_upload', 'preventOverwrite', 'boolean', NULL),
('serverpod_future_call', 'time', 'timestampWithoutTimeZone', NULL),
('serverpod_future_call', 'scheduling', 'json', NULL),
('serverpod_future_call_claim', 'lastHeartbeatTime', 'timestampWithoutTimeZone', NULL),
('serverpod_health_connection_info', 'timestamp', 'timestampWithoutTimeZone', NULL),
('serverpod_health_metric', 'timestamp', 'timestampWithoutTimeZone', NULL),
('serverpod_health_metric', 'isHealthy', 'boolean', NULL),
('serverpod_log', 'time', 'timestampWithoutTimeZone', NULL),
('serverpod_message_log', 'slow', 'boolean', NULL),
('serverpod_migrations', 'timestamp', 'timestampWithoutTimeZone', NULL),
('serverpod_query_log', 'slow', 'boolean', NULL),
('serverpod_runtime_settings', 'logSettings', 'json', NULL),
('serverpod_runtime_settings', 'logSettingsOverrides', 'json', NULL),
('serverpod_runtime_settings', 'logServiceCalls', 'boolean', NULL),
('serverpod_runtime_settings', 'logMalformedCalls', 'boolean', NULL),
('serverpod_session_log', 'time', 'timestampWithoutTimeZone', NULL),
('serverpod_session_log', 'slow', 'boolean', NULL),
('serverpod_session_log', 'isOpen', 'boolean', NULL),
('serverpod_session_log', 'touched', 'timestampWithoutTimeZone', NULL),
('serverpod_auth_core_jwt_refresh_token', 'id', 'uuid', NULL),
('serverpod_auth_core_jwt_refresh_token', 'authUserId', 'uuid', NULL),
('serverpod_auth_core_jwt_refresh_token', 'scopeNames', 'json', NULL),
('serverpod_auth_core_jwt_refresh_token', 'lastUpdatedAt', 'timestampWithoutTimeZone', NULL),
('serverpod_auth_core_jwt_refresh_token', 'createdAt', 'timestampWithoutTimeZone', NULL),
('serverpod_auth_core_profile', 'id', 'uuid', NULL),
('serverpod_auth_core_profile', 'authUserId', 'uuid', NULL),
('serverpod_auth_core_profile', 'createdAt', 'timestampWithoutTimeZone', NULL),
('serverpod_auth_core_profile', 'imageId', 'uuid', NULL),
('serverpod_auth_core_profile_image', 'id', 'uuid', NULL),
('serverpod_auth_core_profile_image', 'userProfileId', 'uuid', NULL),
('serverpod_auth_core_profile_image', 'createdAt', 'timestampWithoutTimeZone', NULL),
('serverpod_auth_core_session', 'id', 'uuid', NULL),
('serverpod_auth_core_session', 'authUserId', 'uuid', NULL),
('serverpod_auth_core_session', 'scopeNames', 'json', NULL),
('serverpod_auth_core_session', 'createdAt', 'timestampWithoutTimeZone', NULL),
('serverpod_auth_core_session', 'lastUsedAt', 'timestampWithoutTimeZone', NULL),
('serverpod_auth_core_session', 'expiresAt', 'timestampWithoutTimeZone', NULL),
('serverpod_auth_core_user', 'id', 'uuid', NULL),
('serverpod_auth_core_user', 'createdAt', 'timestampWithoutTimeZone', NULL),
('serverpod_auth_core_user', 'scopeNames', 'json', NULL),
('serverpod_auth_core_user', 'blocked', 'boolean', NULL),
('crdt_data_attempted_value', 'value', 'jsonb', NULL),
('crdt_data_fields', 'hlcDatetime', 'timestampWithoutTimeZone', NULL),
('crdt_data_rows', 'hlcDatetime', 'timestampWithoutTimeZone', NULL),
('crdt_data_rows', 'uuidRowId', 'uuid', NULL),
('crdt_data_tombstone', 'hlcDatetime', 'timestampWithoutTimeZone', NULL),
('crdt_nodes', 'uuidNodeId', 'uuid', NULL),
('crdt_nodes', 'lastHlc', 'jsonb', NULL),
('crdt_schema_columns', 'isNullable', 'boolean', NULL),
('offline_sync_integrity_violations', 'uuidRowId', 'uuid', NULL),
('offline_sync_integrity_violations', 'ownerSpaceUuid', 'uuid', NULL),
('offline_sync_integrity_violations', 'incomingSpaceUuid', 'uuid', NULL),
('offline_sync_integrity_violations', 'uuidNodeId', 'uuid', NULL),
('offline_sync_integrity_violations', 'hlcDatetime', 'timestampWithoutTimeZone', NULL),
('offline_sync_integrity_violations', 'firstSeenAt', 'timestampWithoutTimeZone', NULL),
('offline_sync_integrity_violations', 'lastSeenAt', 'timestampWithoutTimeZone', NULL),
('offline_sync_space_members', 'userUuid', 'uuid', NULL),
('offline_sync_space_nodes', 'lastReceivedHlc', 'jsonb', NULL),
('offline_sync_spaces', 'uuidSpaceId', 'uuid', NULL);
--
-- MIGRATION VERSION FOR serverpod_offline_sync_test
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_offline_sync_test', '20261008234516445', (unixepoch('now', 'subsecond') * 1000))
ON CONFLICT ("module")
DO UPDATE SET "version" = '20261008234516445', "timestamp" = (unixepoch('now', 'subsecond') * 1000);
--
-- MIGRATION VERSION FOR serverpod
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod', '20260824182259319', (unixepoch('now', 'subsecond') * 1000))
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260824182259319', "timestamp" = (unixepoch('now', 'subsecond') * 1000);
--
-- MIGRATION VERSION FOR serverpod_auth_core
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_auth_core', '20260924105232991', (unixepoch('now', 'subsecond') * 1000))
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260924105232991', "timestamp" = (unixepoch('now', 'subsecond') * 1000);
--
-- MIGRATION VERSION FOR serverpod_offline_sync
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_offline_sync', '20260914143806119', (unixepoch('now', 'subsecond') * 1000))
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260914143806119', "timestamp" = (unixepoch('now', 'subsecond') * 1000);
COMMIT;