SchemaIntegrityVerifier reports false drift on partial + functional indexes (indpred unread, ParseIndexExpressions mis-parses)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 72/100
Línea de trabajo
Start in PostgresSchemaInspector, reading the index read-back query and ParseIndexExpressions, then follow how IndexDefinition is checked by SchemaIntegrityVerifier.SameSql. Reproduce the schema with the partial functional index and verify that the inspector round-trips its filter and expressions without reporting drift.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
A unique index that is both functional and partial always reports drift in the post-apply SchemaIntegrityVerifier, even immediately after migrate creates it. Two independent bugs in Nimblesite.DataProvider.Migration.Postgres.PostgresSchemaInspector cause this.
Reproduced with DataProviderMigrate 0.9.12-beta against postgres:16.
Repro schema.yaml index
- name: uq_invitations_pending_email
expressions:
- tenant_id
- lower(email)
isUnique: true
filter: "accepted_at IS NULL AND revoked_at IS NULL"
Observed
migrate creates the index, then the integrity check fails:
public.invitations: index uq_invitations_pending_email expressions drifted
public.invitations: index uq_invitations_pending_email filter drifted
Postgres stores the index as:
CREATE UNIQUE INDEX uq_invitations_pending_email ON public.invitations
USING btree (tenant_id, lower(email))
WHERE ((accepted_at IS NULL) AND (revoked_at IS NULL))
Bug 1 — Filter is never read back
PostgresSchemaInspector builds IndexDefinition from the read-back query but never reads pg_index.indpred (pg_get_expr(indpred, indrelid)), so actual.Filter is always null. SchemaIntegrityVerifier.SameSql(null, "accepted_at IS NULL AND revoked_at IS NULL") is therefore always false → "filter drifted" for ANY partial index.
Bug 2 — ParseIndexExpressions mis-parses functional / partial indexes
ParseIndexExpressions(indexDef) locates the column list with indexDef.LastIndexOf('(') and LastIndexOf(')'). For ... (tenant_id, lower(email)) WHERE (...) the last (/) belong to the WHERE clause (or to lower(), so the substring extracted is not the index column list. Result: parsed Expressions are garbage → "expressions drifted". This also misfires on a functional index with no WHERE ((tenant_id, lower(email)) → parses email only).
Suggested fix
- Read
pg_get_expr(i.indpred, i.indrelid, true)and populateIndexDefinition.Filter; normalize parenthesisation inSameSql(Postgres re-parenthesises predicates). - Replace the
LastIndexOfbracket scan with a depth-aware scan anchored onUSING <method> (… matching)so the WHERE clause and nested function parens are not mistaken for the column-list bounds.
Impact / workaround
NAP's [INVITE-EMAIL] wanted a partial+functional unique index ((tenant_id, lower(email)) WHERE accepted_at IS NULL AND revoked_at IS NULL). Because the verifier fails it, NAP currently enforces the invariant in the application layer instead and omits the DB index. We'd like to restore the DB constraint once the verifier round-trips filtered/expression indexes.
- Lenguaje dominante
- C#
- Estrellas
- 68
- Forks
- 4
- Merge medio
- 50 min
- PR fusionados (30 d)
- 2
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Nimblesite/DataProvider
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 92/100
Nimblesite/DataProvider#137 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Nimblesite/DataProvider#72 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Nimblesite/DataProvider#121 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
Nimblesite/DataProvider#108 ·
Los mantenedores suelen responder en 1 día
-
A check constraint the schema cannot name can never be retired, and keeps enforcing the old ruleAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Nimblesite/DataProvider#107 ·
Los mantenedores suelen responder en 1 día
Todos los issues de Nimblesite/DataProvider
Issues similares
-
kronos:develop:queued priority:P0
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
nopSolutions/nopCommerce#8512 ·
Los mantenedores suelen responder en 4 días
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
modelcontextprotocol/csharp-sdk#2061 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día