Conversation
Master shipped 083_rewrite_imap_thread_external_ids and 084_allow_realtime_sync_type while feat/rls was in flight, colliding with the RLS migrations' numbers. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
generate_permission_filter, build_common_filters, and json_value_to_term_string in shared/db/repositories/document.rs were only ever called by each other after the move to RLS-based filtering. Cargo flagged them as dead code. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Some indexer-side code legitimately needs to read or update documents across all users — IMAP cross-source dedup looks for any donor with embeddings, and embedding_status updates have to land regardless of who owns the document. Both paths previously used the unscoped pool; under RLS that returns zero rows. Adds system_db_connection() which sets app.is_admin = 'true' so the indexer-bypass policies match. Routes find_embedded_duplicate through it and restores update_embedding_status (still called from batch_processor at three sites). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two runtime bugs in the RLS hook setup:
1. rlsClient.connect() doesn't exist on postgres-js (Sql<{}>). Every
authenticated request would have crashed before reaching a route.
Switched to reserve() / release().
2. SET app.current_user_id = $1 cannot be parameterised in plain SQL —
SET parses its value at parse time, not bind time. Switched to
set_config(...) which accepts bind parameters.
Also adds db: typeof db to App.Locals so callers can reference
locals.db without a type error (was 52 svelte-check errors).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Cleanup of various call-sites that the main RLS commit missed:
- repositories/sources.ts: dropped non-existent drizzle-orm type
imports (PgDatabase / AnyPgColumn / PgTable), retyped this.db as
typeof db, fixed findActiveByTypeAndCreator which silently used the
unscoped admin db instead of this.db.
- api/v1/api-keys: callers were passing locals.user.id where locals.db
was expected (4 sites — list/create/revoke/delete).
- auth/google/{link,unlink}: userSession.userId → userSession.user.id.
- admin/settings/integrations/{drive,gmail}/[sourceId]: instantiate
SourcesRepository(locals.db) instead of importing the singleton.
- db/{chats,response-feedback}: result.rowCount → result.count
(postgres-js returns count, not rowCount).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The multi-line `CMD bash -c '...'` form was being parsed line-by-line by the Dockerfile parser, breaking the build. Moved the script into services/migrations/entrypoint.sh and switched CMD to exec form. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Migrate from explicit user-based filtering in application code to
Postgres RLS policies. All user-scoped tables are now protected by
policies that reference
app.current_user_idsession variable.Implementation: