-
Notifications
You must be signed in to change notification settings - Fork 3
feat: create predictions table for engagement scoring #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,23 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||
| -- Neural engagement predictions from TRIBE v2 model | ||||||||||||||||||||||||||||||||||||||||||||||||
| create table if not exists public.predictions ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| id uuid primary key default gen_random_uuid(), | ||||||||||||||||||||||||||||||||||||||||||||||||
| account_id uuid not null references public.accounts(id) on delete cascade, | ||||||||||||||||||||||||||||||||||||||||||||||||
| file_url text not null, | ||||||||||||||||||||||||||||||||||||||||||||||||
| modality text not null check (modality in ('video', 'audio', 'text')), | ||||||||||||||||||||||||||||||||||||||||||||||||
| engagement_score numeric not null, | ||||||||||||||||||||||||||||||||||||||||||||||||
| engagement_timeline jsonb not null, | ||||||||||||||||||||||||||||||||||||||||||||||||
| peak_moments jsonb not null, | ||||||||||||||||||||||||||||||||||||||||||||||||
| weak_spots jsonb not null, | ||||||||||||||||||||||||||||||||||||||||||||||||
| regional_activation jsonb not null, | ||||||||||||||||||||||||||||||||||||||||||||||||
| total_duration_seconds numeric not null, | ||||||||||||||||||||||||||||||||||||||||||||||||
| elapsed_seconds numeric not null, | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add domain checks for score/duration fields. Lines 7-13 allow negative/invalid numeric values ( Proposed SQL patch engagement_score numeric not null,
engagement_timeline jsonb not null,
peak_moments jsonb not null,
weak_spots jsonb not null,
regional_activation jsonb not null,
total_duration_seconds numeric not null,
elapsed_seconds numeric not null,
+ constraint predictions_engagement_score_range_chk
+ check (engagement_score >= 0 and engagement_score <= 1),
+ constraint predictions_duration_nonnegative_chk
+ check (
+ total_duration_seconds >= 0
+ and elapsed_seconds >= 0
+ and elapsed_seconds <= total_duration_seconds
+ ),
created_at timestamptz not null default now()📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: No domain constraints on Prompt for AI agents |
||||||||||||||||||||||||||||||||||||||||||||||||
| created_at timestamptz not null default now() | ||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| create index if not exists idx_predictions_account_id | ||||||||||||||||||||||||||||||||||||||||||||||||
| on public.predictions(account_id); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| create index if not exists idx_predictions_created_at | ||||||||||||||||||||||||||||||||||||||||||||||||
| on public.predictions(created_at desc); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| alter table public.predictions enable row level security; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RLS is enabled without any policy in this migration. On Line 23, Proposed SQL patch alter table public.predictions enable row level security;
+
+-- Example baseline policies (adjust to your auth/account model)
+create policy if not exists "predictions_select_own"
+ on public.predictions
+ for select
+ using (account_id = auth.uid());
+
+create policy if not exists "predictions_insert_own"
+ on public.predictions
+ for insert
+ with check (account_id = auth.uid());📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: recoupable/database
Length of output: 884
🏁 Script executed:
Repository: recoupable/database
Length of output: 13587
🏁 Script executed:
Repository: recoupable/database
Length of output: 889
Add RLS policies for
public.predictionstable before deployment.Line 23 enables row level security (
alter table public.predictions enable row level security;) but no policies are defined. This will block all access to the table. Either define policies in this migration or ensure they're created in a guaranteed earlier deploy step.🤖 Prompt for AI Agents