fix drizzle-kit push
crash on pulling db schema with compound indexes that have expression members
#3888
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.
fix #3745
See my comment #3745 (comment)
drizzle-kit push
crashes with zod errorExpected string, received null
on tables likeThe crash happens when there's a compound index on
(col, expression(col))
where one of the index components isexpression(col)
, not just a column.It happens when
drizzle-kit push
ingests the db's current schema. This is extra confusing becausedrizzle-kit push
succeeds when adding the index to a db that doesn't have it yet. It's only in subsequent syncs thatdrizzle-kit
crashes trying to read back the index it created.The
null
causes zod to error out when trying to parse the schema pulled from postgres. The schema it's handed has the inappropriate null constructed infromDatabase
, where:The
dbIndexes
it pulls from postgres has acolumn_name=NULL
for the row withindexname='tnsltn', index_order=2
, where it ought to havecolumn_name='md5((source_text)::text)'
.I confirmed this in my project, which has a table with similar index to that of the original bug reporter. I worked with Claude to generate this new SQL query. I confirmed that this changed SQL query produced by Claude works for my project.
However, I'm personally not great at SQL, so do very much take this with a grain of salt. I can't meaningfully read the original query, nor the one Claude wrote.
Hopefully someone with better SQL can read and give feedback!