[drizzle-kit] fix: pg push drops and recreates index when .with() params are numeric - #6124
Open
SnowingFox wants to merge 1 commit into
Open
Conversation
…ams are numeric Fixes drizzle-team#6079
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.
Fixes #6079.
Problem
Declaring Postgres index storage parameters (
.with()) with numeric values makesdrizzle-kit pushDROP and re-CREATE the index on every push, even when nothing changed:Postgres stores reloptions as text in
pg_class.reloptions, so the introspected snapshot always holds string values ({ "m": "24" }), while the schema-side serializer passed the raw numeric values ({ m: 24 }). The squashed index strings never compared equal, so the differ classified the index as altered and emittedDROP INDEX+CREATE INDEXon every run. For HNSW/pgvector indexes a rebuild takes many minutes and interrupts leave the DB without the index (seq-scan fallback).Fix
Normalize the schema-side
.with()values to strings indrizzle-kit/src/serializer/pgSerializer.tswhen building the index snapshot, so the schema side matches what Postgres introspection returns. Numeric params now compare equal to the introspected text reloptions and the diff stays quiet:This also makes the emitted
create_index/create_index_pgstatement data consistent with the snapshot schema (indexV4/V5/V6already declarewith: record(string(), string())). The generated SQL is unchanged (WITH (m=24,ef_construction=128)). String params written by users keep working as before.Test plan
Adds a regression test (
drizzle-kit/tests/push/pg-index-with-reloptions.test.ts) that pushes the same schema containing an index with numeric.with()params and asserts that noDROP INDEX/CREATE INDEXstatements are produced. On the old code the test fails with two spurious statements; with the fix it passes. Existing index tests that asserted numericwithvalues in the statement data were updated to the now-correct string representation.