Make SQL migrations the single source of the Postgres search schema - #3
Merged
Merged
Conversation
PostgresBackend.Migrate hand-wrote the tsvector column, trigger, and GIN index that migration 000001 already creates, with a drift (namespace DEFAULT '' vs 'default'), and it created the pg_trgm extension + trigram indexes that no production path ever called — so fuzzy search ran without its indexes in production. - Move pg_trgm + the trigram indexes into a new migration (000006). A DO block attempts CREATE EXTENSION and degrades gracefully (indexes only created when the extension is present) so a missing privilege does not fail startup. Bump RequiredSchemaVersion to 6. - Reduce PostgresBackend.Migrate to running the versioned migrations, so there is one schema definition and it cannot drift. - Point the Postgres search tests at the real migrations (reset schema + RunMigrations) instead of AutoMigrate + backend DDL, and adjust the down-migration step counts and required-version log assertions for v6. Verified against a live Postgres: migrations create pg_trgm, both trigram indexes, and namespace DEFAULT 'default'. Co-Authored-By: Claude Fable 5 <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.
문제
PostgresBackend.Migrate가 마이그레이션000001이 이미 만드는 tsvector 컬럼·트리거·GIN 인덱스를 Go 인라인 SQL로 중복 생성했고,namespace DEFAULT ''(SQL은'default') 드리프트가 있었음. 게다가 pg_trgm 확장·trgm 인덱스는Migrate에만 있었는데 프로덕션은Migrate를 호출하지 않음 → 퍼지 검색이 프로덕션서 인덱스 없이(seq scan) 돌았음.변경
000006으로 이동.CREATE EXTENSION을DO블록으로 감싸 권한 없을 때 graceful degrade(확장 있을 때만 인덱스 생성) — startup 하드실패 방지.RequiredSchemaVersion5→6.PostgresBackend.Migrate를 마이그레이션 실행으로 축소 → 스키마 정의 단일화, 드리프트 불가능.검증
live Postgres(격리 DB)에서 확인:
search_documents.namespace DEFAULT 'default'(드리프트 해소)🤖 Generated with Claude Code