-
Notifications
You must be signed in to change notification settings - Fork 20
fix(server): repair connections.entity_ids schema drift (query_sql) #1157
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
+22
−0
Merged
Changes from all commits
Commits
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
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,22 @@ | ||
| -- migrate:up | ||
|
|
||
| -- Schema drift repair: `connections.entity_ids` exists in the squashed baseline | ||
| -- (00000000000000_baseline.sql) with a GIN index, but installs provisioned from | ||
| -- an *older* pre-squash baseline applied the column to events/watchers/feeds and | ||
| -- never to connections. Those databases (e.g. the prod `owletto` DB) are missing | ||
| -- both the column and its index, so any query that projects connections.entity_ids | ||
| -- — including the admin `query_sql` tool whose SAFE_COLUMN_DEFS allowlist lists it | ||
| -- — fails with `column "entity_ids" does not exist`. | ||
| -- | ||
| -- This delta is idempotent: a no-op on fresh installs (baseline already created | ||
| -- the column + index) and a repair on drifted databases. Matches the baseline | ||
| -- definition exactly so the allowlist stays consistent with the real schema. | ||
| ALTER TABLE public.connections ADD COLUMN IF NOT EXISTS entity_ids bigint[]; | ||
|
|
||
| CREATE INDEX IF NOT EXISTS idx_connections_entity_ids ON public.connections USING gin (entity_ids); | ||
|
|
||
| -- migrate:down | ||
|
|
||
| DROP INDEX IF EXISTS public.idx_connections_entity_ids; | ||
|
|
||
| ALTER TABLE public.connections DROP COLUMN IF EXISTS entity_ids; | ||
Oops, something went wrong.
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.
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: lobu-ai/lobu
Length of output: 91
🌐 Web query:
PostgreSQL CREATE INDEX CONCURRENTLY IF NOT EXISTS minimum version💡 Result:
Minimum PostgreSQL version: PostgreSQL 9.5. Reasoning (from sources): - PostgreSQL 9.5 release notes state: “Add IF NOT EXISTS clause to … CREATE INDEX …” [1]. - The CREATE INDEX grammar documents both optional CONCURRENTLY and IF NOT EXISTS clauses: “CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] …” [2][3]. - A CREATE INDEX IF NOT EXISTS community reference also notes “Postgres 9.5 or newer” and that it “Also works for CREATE INDEX CONCURRENTLY IF NOT EXISTS.” [4]. So the combined form “CREATE INDEX CONCURRENTLY IF NOT EXISTS …” is available starting in PostgreSQL 9.5. [1][2][4]
Citations:
Add
CONCURRENTLYto avoid production locks during the GIN index build.The migration’s
CREATE INDEX IF NOT EXISTS ... USING gin (entity_ids);will take a table lock while the index is built on a non-emptypublic.connectionstable.CREATE INDEX CONCURRENTLY IF NOT EXISTSis supported by PostgreSQL 9.5+.🔧 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents