fix: Rebuild foreign key and unique projection from authored facts (#115)

This commit is contained in:
Marcelo Mendonça Soares 2026-09-04 15:37:09 -03:00 • committed by GitHub
commit 519a8efca0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,99 @@
BEGIN;
--
-- ACTION DROP TABLE
--
DROP TABLE "crdt_schema_columns";
--
-- ACTION CREATE TABLE
--
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");
--
-- 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
('crdt_data_fields', 'hlcDatetime', 'timestampWithoutTimeZone', NULL),
('crdt_data_foreign_key', 'attemptedValue', 'uuid', NULL),
('crdt_data_foreign_key', 'visibleValue', 'uuid', 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),
('crdt_scope_members', 'userUuid', 'uuid', NULL),
('crdt_scope_nodes', 'lastReceivedHlc', 'jsonb', NULL),
('crdt_scopes', 'uuidScopeId', 'uuid', NULL),
('crdt_sync_integrity_violations', 'uuidRowId', 'uuid', NULL),
('crdt_sync_integrity_violations', 'ownerScopeUuid', 'uuid', NULL),
('crdt_sync_integrity_violations', 'incomingScopeUuid', 'uuid', NULL),
('crdt_sync_integrity_violations', 'uuidNodeId', 'uuid', NULL),
('crdt_sync_integrity_violations', 'hlcDatetime', 'timestampWithoutTimeZone', NULL),
('crdt_sync_integrity_violations', 'firstSeenAt', 'timestampWithoutTimeZone', NULL),
('crdt_sync_integrity_violations', 'lastSeenAt', 'timestampWithoutTimeZone', 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);
--
-- MIGRATION VERSION FOR serverpod_offline_sync
--
INSERT INTO "serverpod_migrations" ("module", "version", "timestamp")
VALUES ('serverpod_offline_sync', '20260902184216091', (unixepoch('now', 'subsecond') * 1000))
ON CONFLICT ("module")
DO UPDATE SET "version" = '20260902184216091', "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);
COMMIT;