Spaces:
Running on Zero
Running on Zero
Add analytics schema reference
Browse files
analytics_supabase_schema.sql
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
create extension if not exists pgcrypto;
|
| 2 |
+
|
| 3 |
+
create table if not exists public.analytics_generation_events (
|
| 4 |
+
id uuid primary key default gen_random_uuid(),
|
| 5 |
+
generation_id text not null,
|
| 6 |
+
timestamp timestamptz not null default now(),
|
| 7 |
+
product text not null,
|
| 8 |
+
source text not null check (source in ('ui', 'mcp')),
|
| 9 |
+
pipeline text not null check (pipeline in ('standard', 'artistic')),
|
| 10 |
+
tool_name text not null,
|
| 11 |
+
analytics_opt_in boolean not null default false,
|
| 12 |
+
status text not null check (status in ('success', 'error')),
|
| 13 |
+
error_bucket text not null,
|
| 14 |
+
anonymous_id text not null,
|
| 15 |
+
prompt_full text,
|
| 16 |
+
qr_payload_full text,
|
| 17 |
+
settings_full jsonb,
|
| 18 |
+
created_at timestamptz not null default now()
|
| 19 |
+
);
|
| 20 |
+
|
| 21 |
+
create index if not exists analytics_generation_events_generation_id_idx
|
| 22 |
+
on public.analytics_generation_events (generation_id);
|
| 23 |
+
|
| 24 |
+
create index if not exists analytics_generation_events_source_pipeline_idx
|
| 25 |
+
on public.analytics_generation_events (source, pipeline, timestamp desc);
|
| 26 |
+
|
| 27 |
+
create table if not exists public.analytics_download_events (
|
| 28 |
+
id uuid primary key default gen_random_uuid(),
|
| 29 |
+
generation_id text,
|
| 30 |
+
timestamp timestamptz not null default now(),
|
| 31 |
+
product text not null,
|
| 32 |
+
source text not null check (source in ('ui', 'mcp')),
|
| 33 |
+
pipeline text not null,
|
| 34 |
+
tool_name text not null,
|
| 35 |
+
analytics_opt_in boolean not null default false,
|
| 36 |
+
format text not null check (format in ('png', 'svg')),
|
| 37 |
+
anonymous_id text not null,
|
| 38 |
+
qr_payload_full text,
|
| 39 |
+
seed bigint,
|
| 40 |
+
created_at timestamptz not null default now()
|
| 41 |
+
);
|
| 42 |
+
|
| 43 |
+
create index if not exists analytics_download_events_generation_id_idx
|
| 44 |
+
on public.analytics_download_events (generation_id);
|
| 45 |
+
|
| 46 |
+
create index if not exists analytics_download_events_source_pipeline_idx
|
| 47 |
+
on public.analytics_download_events (source, pipeline, timestamp desc);
|
| 48 |
+
|
| 49 |
+
create or replace view public.analytics_generation_outcomes as
|
| 50 |
+
select
|
| 51 |
+
g.generation_id,
|
| 52 |
+
g.timestamp as generation_timestamp,
|
| 53 |
+
g.source,
|
| 54 |
+
g.pipeline,
|
| 55 |
+
g.analytics_opt_in,
|
| 56 |
+
g.status,
|
| 57 |
+
g.error_bucket,
|
| 58 |
+
exists (
|
| 59 |
+
select 1
|
| 60 |
+
from public.analytics_download_events d
|
| 61 |
+
where d.generation_id = g.generation_id
|
| 62 |
+
) as has_download
|
| 63 |
+
from public.analytics_generation_events g;
|