feat(confidence-engine): define investigation persistence schema

This commit is contained in:
2026-09-08 16:56:07 +01:00
parent 30bf44f2e5
commit b949eea831
3 changed files with 60 additions and 0 deletions
+5
View File
@@ -12,6 +12,11 @@ Initial-decomposition hardening is frozen for the current MVP stage.
- Confidence Engine uses self-hosted Supabase Auth with magic-link email, `/auth/callback` code exchange, cookie-backed sessions, and protected product routes/API requests; unauthenticated API requests receive 401. - Confidence Engine uses self-hosted Supabase Auth with magic-link email, `/auth/callback` code exchange, cookie-backed sessions, and protected product routes/API requests; unauthenticated API requests receive 401.
- Investigation persistence remains wholly localStorage-backed and independent of authentication. No `confidence_engine` database schema, tables, snapshot ownership fields, Supabase server configuration, or PostgREST configuration were changed; server persistence remains future work. - Investigation persistence remains wholly localStorage-backed and independent of authentication. No `confidence_engine` database schema, tables, snapshot ownership fields, Supabase server configuration, or PostgREST configuration were changed; server persistence remains future work.
## Database foundation (v0.62b)
- Version-controlled migration defines `confidence_engine.investigations`: the existing CE UUID is the row ID, platform ownership is `user_id`, and the opaque CE snapshot is JSONB. RLS permits authenticated users only where `user_id = auth.uid()`; timestamps include automatic `updated_at` maintenance.
- The migration has not been applied to the self-hosted Supabase environment. Application persistence remains localStorage-backed; the external infrastructure step is to apply the migration and add `confidence_engine` to PostgREST's exposed schemas before server persistence is wired.
**Current product checkpoint:** Read `docs/confidence-engine-product-checkpoint-2026-09-08.md` before planning new product, live-evidence, or commercial work. The core investigation loop is now sufficiently established to prioritise realistic end-to-end use, report experience, prospective-user value, repeat use, and willingness to pay—not endless isolated reasoning-mechanics experiments. Preserve user ownership and address trust-critical defects when found. **Current product checkpoint:** Read `docs/confidence-engine-product-checkpoint-2026-09-08.md` before planning new product, live-evidence, or commercial work. The core investigation loop is now sufficiently established to prioritise realistic end-to-end use, report experience, prospective-user value, repeat use, and willingness to pay—not endless isolated reasoning-mechanics experiments. Preserve user ownership and address trust-critical defects when found.
Do not resume: Do not resume:
+2
View File
@@ -36,6 +36,8 @@ The product direction is a **facilitated investigation** presented across three
**Authentication boundary:** Supabase Auth magic links gate product and CE API routes. Sessions are cookie-backed and `/auth/callback` exchanges the auth code before returning to `/`. This does not alter localStorage investigation persistence or introduce user ownership into CE snapshots; dedicated `confidence_engine` PostgreSQL persistence remains future work. **Authentication boundary:** Supabase Auth magic links gate product and CE API routes. Sessions are cookie-backed and `/auth/callback` exchanges the auth code before returning to `/`. This does not alter localStorage investigation persistence or introduce user ownership into CE snapshots; dedicated `confidence_engine` PostgreSQL persistence remains future work.
**Database contract (v0.62b):** A pending version-controlled migration defines `confidence_engine.investigations` outside `public`. Its platform metadata is `id`, `user_id`, and timestamps; the CE payload remains an opaque JSONB `snapshot`. Authenticated RLS ownership is `user_id = auth.uid()`. The migration is not yet applied, `confidence_engine` is not yet exposed through PostgREST, and localStorage remains the production persistence authority.
The user controls which question to investigate, how deeply to investigate it, when to say Done for now, whether Current Understanding is sufficient, whether to reopen work, and when to review the Report. The engine facilitates — it does not steer or prioritise. The user controls which question to investigate, how deeply to investigate it, when to say Done for now, whether Current Understanding is sufficient, whether to reopen work, and when to review the Report. The engine facilitates — it does not steer or prioritise.
## September 8, 2026 Product Checkpoint ## September 8, 2026 Product Checkpoint
@@ -0,0 +1,53 @@
create schema if not exists confidence_engine;
create table confidence_engine.investigations (
id uuid primary key,
user_id uuid not null references auth.users(id) on delete cascade,
snapshot jsonb not null,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create index investigations_user_id_idx
on confidence_engine.investigations (user_id);
create function confidence_engine.set_updated_at()
returns trigger
language plpgsql
set search_path = ''
as $$
begin
new.updated_at = now();
return new;
end;
$$;
create trigger investigations_set_updated_at
before update on confidence_engine.investigations
for each row execute function confidence_engine.set_updated_at();
alter table confidence_engine.investigations enable row level security;
grant usage on schema confidence_engine to authenticated;
grant select, insert, update, delete on confidence_engine.investigations to authenticated;
create policy "Users can select their own investigations"
on confidence_engine.investigations
for select to authenticated
using (user_id = auth.uid());
create policy "Users can insert their own investigations"
on confidence_engine.investigations
for insert to authenticated
with check (user_id = auth.uid());
create policy "Users can update their own investigations"
on confidence_engine.investigations
for update to authenticated
using (user_id = auth.uid())
with check (user_id = auth.uid());
create policy "Users can delete their own investigations"
on confidence_engine.investigations
for delete to authenticated
using (user_id = auth.uid());