feat: create predictions table for engagement scoring#17
feat: create predictions table for engagement scoring#17sidneyswift wants to merge 1 commit intomainfrom
Conversation
Stores TRIBE v2 prediction results: engagement score, timeline, peak moments, weak spots, and regional brain activation data. Indexed by account_id and created_at for efficient queries. Made-with: Cursor
|
Updates to Preview Branch (feature/create-predictions-table) ↗︎
Tasks are run on every commit but only new migration files are pushed.
View logs for this Workflow Run ↗︎. |
📝 WalkthroughWalkthroughA new SQL migration creates the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@supabase/migrations/20260410000000_create_predictions.sql`:
- Line 23: The migration enables RLS on public.predictions but does not create
any policies, which will lock out authenticated/anonymous users; update the
migration to either (A) create appropriate row-level policies for
public.predictions (e.g., separate CREATE POLICY statements for
SELECT/INSERT/UPDATE/DELETE granting access to authenticated/anon roles or using
USING/WITH CHECK expressions tied to your auth columns) before running ALTER
TABLE public.predictions ENABLE ROW LEVEL SECURITY, or (B) defer the ALTER TABLE
... ENABLE ROW LEVEL SECURITY to a subsequent migration after you add the
necessary CREATE POLICY statements; reference the table name public.predictions
and the ALTER TABLE ... ENABLE ROW LEVEL SECURITY line when making the change.
- Around line 7-13: Add CHECK constraints to enforce valid domains: require
engagement_score to be within a sane range (e.g., >= 0 AND <= 1 or the
project-specific max — update to the correct max if different) and require
total_duration_seconds >= 0, elapsed_seconds >= 0 and elapsed_seconds <=
total_duration_seconds; add these CHECK constraints referencing the columns
engagement_score, total_duration_seconds and elapsed_seconds in the table
definition so negative or inconsistent durations/scores cannot be inserted.
- Line 4: The migration enables row level security on public.predictions but
defines no policies, which will block all access; update this migration to add
appropriate RLS policies for public.predictions (for example policies that allow
owners or specific roles to SELECT/INSERT/UPDATE/DELETE) or remove/deferr the
"alter table public.predictions enable row level security" statement until a
prior migration creates those policies; reference the table name
public.predictions and the existing "alter table public.predictions enable row
level security;" statement when adding the corresponding CREATE POLICY entries
or moving the enable step.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 4a601e50-48d5-48ca-95be-6f21e162ce0e
📒 Files selected for processing (1)
supabase/migrations/20260410000000_create_predictions.sql
| -- 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, |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Searching for accounts table creation =="
rg -n --type-add 'sql:*.sql' --type sql -C2 'create\s+table\s+(if\s+not\s+exists\s+)?public\.accounts\b|create\s+table\s+(if\s+not\s+exists\s+)?accounts\b' supabase/migrations || true
echo
echo "== Searching for predictions policies =="
rg -n --type-add 'sql:*.sql' --type sql -C2 'create\s+policy.*predictions|on\s+public\.predictions' supabase/migrations || trueRepository: recoupable/database
Length of output: 884
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== List all SQL migrations in supabase/migrations =="
ls -la supabase/migrations/*.sql 2>/dev/null | head -20 || echo "No migrations found"
echo
echo "== Count and show all migration filenames =="
find supabase/migrations -name "*.sql" -type f | sort
echo
echo "== Check if accounts table exists anywhere in migrations =="
rg -i "create.*table.*accounts" supabase/migrations --no-heading || echo "No matches found"
echo
echo "== Check the full content of the predictions migration file =="
cat supabase/migrations/20260410000000_create_predictions.sqlRepository: recoupable/database
Length of output: 13587
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== Search for any RLS policies on predictions table =="
rg -i "create.*policy.*predictions|policy.*on.*public\.predictions" supabase/migrations --type sql -A5 || echo "No policy definitions found"
echo
echo "== Check specific accounts table creation migration =="
cat supabase/migrations/20241209025457_add_foreign_key.sqlRepository: recoupable/database
Length of output: 889
Add RLS policies for public.predictions table 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
Verify each finding against the current code and only fix it if needed.
In `@supabase/migrations/20260410000000_create_predictions.sql` at line 4, The
migration enables row level security on public.predictions but defines no
policies, which will block all access; update this migration to add appropriate
RLS policies for public.predictions (for example policies that allow owners or
specific roles to SELECT/INSERT/UPDATE/DELETE) or remove/deferr the "alter table
public.predictions enable row level security" statement until a prior migration
creates those policies; reference the table name public.predictions and the
existing "alter table public.predictions enable row level security;" statement
when adding the corresponding CREATE POLICY entries or moving the enable step.
| 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, |
There was a problem hiding this comment.
Add domain checks for score/duration fields.
Lines 7-13 allow negative/invalid numeric values (engagement_score, total_duration_seconds, elapsed_seconds), which can corrupt analytics.
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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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, | |
| 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() |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@supabase/migrations/20260410000000_create_predictions.sql` around lines 7 -
13, Add CHECK constraints to enforce valid domains: require engagement_score to
be within a sane range (e.g., >= 0 AND <= 1 or the project-specific max — update
to the correct max if different) and require total_duration_seconds >= 0,
elapsed_seconds >= 0 and elapsed_seconds <= total_duration_seconds; add these
CHECK constraints referencing the columns engagement_score,
total_duration_seconds and elapsed_seconds in the table definition so negative
or inconsistent durations/scores cannot be inserted.
| 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.
RLS is enabled without any policy in this migration.
On Line 23, ENABLE ROW LEVEL SECURITY with no policy in the same migration can make the table unusable for authenticated/anon immediately after deploy.
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
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| alter table public.predictions enable row level security; | |
| 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()); |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@supabase/migrations/20260410000000_create_predictions.sql` at line 23, The
migration enables RLS on public.predictions but does not create any policies,
which will lock out authenticated/anonymous users; update the migration to
either (A) create appropriate row-level policies for public.predictions (e.g.,
separate CREATE POLICY statements for SELECT/INSERT/UPDATE/DELETE granting
access to authenticated/anon roles or using USING/WITH CHECK expressions tied to
your auth columns) before running ALTER TABLE public.predictions ENABLE ROW
LEVEL SECURITY, or (B) defer the ALTER TABLE ... ENABLE ROW LEVEL SECURITY to a
subsequent migration after you add the necessary CREATE POLICY statements;
reference the table name public.predictions and the ALTER TABLE ... ENABLE ROW
LEVEL SECURITY line when making the change.
There was a problem hiding this comment.
1 issue found across 1 file
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="supabase/migrations/20260410000000_create_predictions.sql">
<violation number="1" location="supabase/migrations/20260410000000_create_predictions.sql:13">
P2: No domain constraints on `engagement_score`, `total_duration_seconds`, or `elapsed_seconds`. Negative scores or durations would silently pass. Add CHECK constraints (e.g., `engagement_score between 0 and 1`, durations `>= 0`, `elapsed_seconds <= total_duration_seconds`).</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
| weak_spots jsonb not null, | ||
| regional_activation jsonb not null, | ||
| total_duration_seconds numeric not null, | ||
| elapsed_seconds numeric not null, |
There was a problem hiding this comment.
P2: No domain constraints on engagement_score, total_duration_seconds, or elapsed_seconds. Negative scores or durations would silently pass. Add CHECK constraints (e.g., engagement_score between 0 and 1, durations >= 0, elapsed_seconds <= total_duration_seconds).
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At supabase/migrations/20260410000000_create_predictions.sql, line 13:
<comment>No domain constraints on `engagement_score`, `total_duration_seconds`, or `elapsed_seconds`. Negative scores or durations would silently pass. Add CHECK constraints (e.g., `engagement_score between 0 and 1`, durations `>= 0`, `elapsed_seconds <= total_duration_seconds`).</comment>
<file context>
@@ -0,0 +1,23 @@
+ weak_spots jsonb not null,
+ regional_activation jsonb not null,
+ total_duration_seconds numeric not null,
+ elapsed_seconds numeric not null,
+ created_at timestamptz not null default now()
+);
</file context>
Summary
predictionstable for storing TRIBE v2 neural engagement predictionsTest plan
Made with Cursor
Summary by cubic
Add
public.predictionstable to store TRIBE v2 neural engagement predictions. Enables fast querying and account-scoped access.New Features
public.predictionstable with:id,account_id(FK, cascade),file_url,modality('video'|'audio'|'text'),engagement_score,engagement_timeline(jsonb),peak_moments(jsonb),weak_spots(jsonb),regional_activation(jsonb),total_duration_seconds,elapsed_seconds,created_at.account_idandcreated_at desc.Migration
Written for commit a26b652. Summary will update on new commits.
Summary by CodeRabbit