-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add artist_id to sessions #27
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
supabase/migrations/20260530025046_add_artist_id_to_sessions.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| -- Add artist_id to sessions, mirroring rooms.artist_id | ||
| -- (see 20250310153603_add_artist_id_to_rooms.sql). | ||
| -- | ||
| -- Each chat is provisioned inside one session; the artist the chat | ||
| -- belongs to lives on the session row so the chat listing endpoint | ||
| -- can filter via `sessions.artist_id`. Backfill from rooms is done | ||
| -- inline below — mirrors the legacy migration's pattern of shipping | ||
| -- the schema change and the data migration atomically. | ||
|
|
||
| ALTER TABLE "public"."sessions" | ||
| ADD COLUMN "artist_id" UUID DEFAULT NULL; | ||
|
|
||
| ALTER TABLE "public"."sessions" | ||
| ADD CONSTRAINT "sessions_artist_id_fkey" | ||
| FOREIGN KEY ("artist_id") REFERENCES "public"."accounts"("id") ON DELETE CASCADE NOT VALID; | ||
|
sweetmantech marked this conversation as resolved.
|
||
|
|
||
| ALTER TABLE "public"."sessions" VALIDATE CONSTRAINT "sessions_artist_id_fkey"; | ||
|
|
||
| -- Backfill from legacy rooms via the uuidv5 derivation used by the | ||
| -- Phase 2 backfill script (api/scripts/backfill/migrateRoom.ts). The | ||
| -- fixed namespace is the same one the script hardcodes, so this | ||
| -- SQL reproduces the exact session id each migrated room was given. | ||
| -- Verified pre-merge: 17,985 of 23,252 migrated sessions have a | ||
| -- matching legacy room with a non-null artist_id. | ||
| UPDATE "public"."sessions" s | ||
| SET "artist_id" = r."artist_id" | ||
| FROM "public"."rooms" r | ||
| WHERE s."id" = uuid_generate_v5( | ||
| 'f47ac10b-58cc-4372-a567-0e02b2c3d479'::uuid, | ||
| r."id"::text | ||
| )::text | ||
| AND r."artist_id" IS NOT NULL; | ||
|
|
||
| -- Direct lookup of "all sessions for an artist". | ||
| -- A composite `(account_id, artist_id)` index was considered for the | ||
| -- sidebar's account+artist filter, but a pre-merge EXPLAIN against a | ||
| -- dry-run on prod showed PG already prefers the existing | ||
| -- `sessions_account_id_idx` (bitmap) + in-memory artist filter for this | ||
| -- query shape — adding the composite paid storage + write cost for a | ||
| -- plan the planner won't pick. Revisit if future query patterns change. | ||
| CREATE INDEX IF NOT EXISTS "sessions_artist_id_idx" | ||
| ON "public"."sessions" ("artist_id"); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.