Files
claudedo-online/server/utils/schema.ts
2026-06-11 08:24:28 +00:00

28 lines
1.2 KiB
TypeScript

// Canonical schema for the Online Inbox. Single source of truth, applied idempotently by
// the Nitro startup plugin (server/plugins/migrate.ts) and the CLI (server/db/migrate.ts).
export const INIT_SQL = `
create table if not exists lists (
id text primary key, -- GUID supplied by the desktop, reused verbatim
name text not null,
updated_at timestamptz not null default now()
);
create table if not exists tasks (
id text primary key, -- GUID; shared id space (web + desktop)
list_id text not null references lists(id) on delete cascade,
title text not null,
description text,
source text not null, -- 'web' | 'desktop'
consumed boolean not null default false, -- web->desktop handoff flag
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index if not exists idx_tasks_list_id on tasks(list_id);
create index if not exists idx_tasks_unconsumed on tasks(consumed) where consumed = false;
-- Multi-user plumbing: rows are owned by a Zitadel sub. NULL = legacy/unowned (pre-multi-user).
alter table lists add column if not exists owner_id text;
alter table tasks add column if not exists owner_id text;
`;