-- 020_webdav_shares.sql — user-connected WebDAV file shares. -- -- Additive and idempotent; schema.sql carries the identical tables, so this -- is a structural no-op on a fresh database (db-converge proves both paths -- land the same). -- -- A connected WebDAV share (any service; Settings → WebDAV) materializes as -- a Collection whose members are bookmarks — one per file, URL = the DAV -- location. WebDavItem is the path↔bookmark reconciliation map: UNIQUE per -- (connectionId, path); bookmarkId ON DELETE SET NULL means a user-deleted -- bookmark leaves a tombstone so syncs never resurrect what the owner -- removed, and file removal on the server detaches membership only (the -- bookmark itself stays, pages-and-trash semantics). -- -- Credentials follow the house discipline: username in the clear (it is not -- a secret and the DAV URL needs no userinfo), password/app-token encrypted -- at rest via internal/crypto, masked in every response, write-only (a PATCH -- echoing the mask keeps the stored value). Dials go through -- internal/netguard — user-supplied hosts get no trusted-range exemption — -- with Basic auth carried in a header only, never the URL. Mutations carry -- the row version (409 on stale), like MCP connections and channels. -- lastSyncedAt/lastError/collectionId are engine-owned bookkeeping and never -- bump version (AgentTask.lastCheckedAt precedent). CREATE TABLE IF NOT EXISTS "WebDavConnection" ( id text PRIMARY KEY, "ownerId" text NOT NULL REFERENCES "User"(id) ON DELETE CASCADE, name text NOT NULL, url text NOT NULL, username text NOT NULL, secret text NOT NULL, "collectionId" text REFERENCES "Collection"(id) ON DELETE SET NULL, enabled boolean NOT NULL DEFAULT true, "lastSyncedAt" timestamptz, "lastError" text, version integer NOT NULL DEFAULT 1, "createdAt" timestamptz NOT NULL DEFAULT now(), "updatedAt" timestamptz NOT NULL DEFAULT now() ); CREATE INDEX IF NOT EXISTS "WebDavConnection_ownerId_idx" ON "WebDavConnection"("ownerId"); CREATE TABLE IF NOT EXISTS "WebDavItem" ( id text PRIMARY KEY, "connectionId" text NOT NULL REFERENCES "WebDavConnection"(id) ON DELETE CASCADE, path text NOT NULL, "bookmarkId" text REFERENCES "Bookmark"(id) ON DELETE SET NULL, etag text NOT NULL DEFAULT '', "sizeBytes" bigint NOT NULL DEFAULT 0, "modifiedAt" timestamptz, "createdAt" timestamptz NOT NULL DEFAULT now(), "updatedAt" timestamptz NOT NULL DEFAULT now(), UNIQUE ("connectionId", path) ); CREATE INDEX IF NOT EXISTS "WebDavItem_connectionId_idx" ON "WebDavItem"("connectionId");