fix(indexer): remove ensureSchema() and add startup schema-version guard - #1186
Open
Chucks1093 wants to merge 2 commits into
Open
fix(indexer): remove ensureSchema() and add startup schema-version guard#1186Chucks1093 wants to merge 2 commits into
Chucks1093 wants to merge 2 commits into
Conversation
|
@Chucks1093 is attempting to deploy a commit to the Jaja's projects Team on Vercel. A member of the Team first needs to authorize it. |
devJaja
self-requested a review
August 27, 2026 06:08
Contributor
|
Nice work @Chucks1093 Kindly fix all the ci checks failure |
Contributor
|
Resolve conflicts |
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.
Closes #1176
What changed
1.
ensureSchema()removed fromsrc/index.tsThe function ran 15+
CREATE TABLE IF NOT EXISTS/CREATE INDEX IF NOT EXISTSstatements on every process startup, bypassing the versioned migration suite inservices/indexer/migrations/. Problems:CREATE TABLE IF NOT EXISTSis a no-op on existing tables, so additive column changes from migrations were never applied to existing deploymentsAccessShareLockonpg_classon every startup2.
src/schema-version.ts— startup guardNew
assertSchemaVersion(pool)function replacesensureSchema()inmain(). It queriespg_tablesandinformation_schema.columnsto verify that all sentinel tables and columns are present, and callsprocess.exit(1)with a descriptive error message if any are missing:Sentinel tables checked:
raw_events,indexer_cursor,indexer_state,device_tokens,sent_notifications,blocks,dm_keys,notification_preferences(011 — forward-progress sentinel).Sentinel column checked:
posts.content_tsv(added by009_posts_fts).3.
docker-compose.yml—migrateinit serviceAdded a
migrateone-shot service that applies all.sqlfiles in filename order before the indexer starts:The postgres service's
initdb.dmount is removed — migrations are now always applied explicitly by themigrateservice, not implicitly on first boot.4.
migrate.sh— bare-metal migration runnerNew
services/indexer/migrate.shfor CI / bare-metal deployments (no Docker required):5.
tests/migrations/test-migrations.sh— Step 10New step verifies the
assertSchemaVersion()sentinel invariants after the full migration run, and confirms the sentinel table (notification_preferences) is absent on a partially-migrated DB (negative test).6.
migrations/README.mdupdatedRemoved the
ensureSchema()paragraph and replaced it with instructions for running migrations viadocker compose upormigrate.sh.Tests
src/__tests__/schema-version.test.ts— 5 Jest cases:process.exit(1)when a required table is missingprocess.exit(1)whenposts.content_tsvis missing