Skip to content

Conversation

@KOBA789
Copy link

@KOBA789 KOBA789 commented Aug 20, 2025

Summary

Fixes an issue where drizzle-kit push would generate unnecessary DROP INDEX statements for primary key indexes when working with Amazon Aurora DSQL, causing failures with the error "cannot drop index because constraint requires it".

Fixes: #4779

Problem

Aurora DSQL's pg_stat_user_indexes view does not correctly identify primary key indexes as constraint-generated. This causes the schema introspection logic in drizzle-kit to incorrectly classify primary key indexes as regular indexes that should be dropped during schema synchronization.

When running drizzle-kit push on a subsequent run, it would attempt to drop primary key indexes.

Solution

Replaced the pg_stat_user_indexes query with direct system catalog queries using: pg_class, pg_namespace and pg_index.

This approach correctly identifies constraint-generated indexes in both Aurora DSQL and standard PostgreSQL environments.

…OP INDEX

Aurora DSQL's pg_stat_user_indexes view does not correctly identify primary
key indexes as constraint-generated, causing drizzle-kit push to generate
unnecessary DROP INDEX statements that fail with "cannot drop index because
constraint requires it".

This change replaces the pg_stat_user_indexes query with direct system
catalog queries (pg_class, pg_namespace, pg_index, pg_constraint) to properly
detect constraint-generated indexes in both Aurora DSQL and standard PostgreSQL.

Fixes drizzle-team#4779
@owenmorgan
Copy link

can this be merged please? quite a big issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: drizzle-kit / Amazon Aurora DSQL : drizzle-kit push tries to drop the primary key index on reapply without changes

2 participants