0.9.11-beta SchemaIntegrityVerifier rejects valid schemas: Text default casts + multi-role / AllTablesInSchema grants
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 50/100
調査の方向性
Start with Migration/Nimblesite.DataProvider.Migration.Core/SchemaIntegrityVerifier.cs and PostgresSupportSchemaInspector.cs, then run the provided postgres:16 reproduction. Trace default comparison, multi-role grant matching, and AllTablesInSchema inspection. Done means migrate exits successfully while accepting the text default and both grant forms.
索引モデルが issue の本文から書いたものです。
説明
Summary
The new SchemaIntegrityVerifier in 0.9.11-beta fails the migrate exit code on every valid schema we have. The migration itself succeeds — the live database is correctly converged — but the post-migrate integrity check rejects valid YAML it can't reconcile against what its inspector reads back from Postgres.
Two regressions vs 0.9.10-beta, both reproducible against an empty postgres:16 container with the schema below.
Repro
docker run -d --rm --name pg -e POSTGRES_PASSWORD=postgres -p 5499:5432 postgres:16
dotnet tool update -g DataProviderMigrate --version 0.9.11-beta
DataProviderMigrate migrate \
--schema schema.yaml \
--output "Host=localhost;Database=postgres;Username=postgres;Password=postgres;Port=5499" \
--provider postgres --allow-destructive
Minimal schema.yaml triggering all three failure modes (full repro in the NAP repo at migrations/schema.yaml):
name: repro
roles:
- { name: app_user, grantTo: [postgres] }
- { name: app_admin, grantTo: [postgres] }
grants:
- schema: public
target: Schema
privileges: [USAGE]
roles: [app_user, app_admin]
- schema: public
target: AllTablesInSchema
privileges: [SELECT, INSERT, UPDATE, DELETE]
roles: [app_user, app_admin]
tables:
- name: t
schema: public
columns:
- { name: id, type: Uuid, isNullable: false }
- { name: status, type: Text, isNullable: false, defaultValue: "'pending'" }
primaryKey: { columns: [id] }
Output
Migration completed successfully
SCHEMA INTEGRITY CHECK FAILED
public.t.status: default expected 'pending' but found 'pending'::text
grant Schema public: missing grant
grant AllTablesInSchema public: missing grant
Exit code 1, despite the database matching the YAML in every meaningful way.
Bug 1 — Text default round-trip
When you ALTER COLUMN ... SET DEFAULT 'pending' on a text column, Postgres stores the default in pg_attrdef as 'pending'::text. The verifier compares the raw YAML literal ('pending') against the inspector's reading ('pending'::text) and reports drift.
Affected file: Migration/Nimblesite.DataProvider.Migration.Core/SchemaIntegrityVerifier.cs. Whatever comparison decides "default expected X but found Y" needs to canonicalise away trailing ::<type> casts so 'pending' ≡ 'pending'::text.
Reproduces for every plain string default. Numeric / boolean / '[]'::jsonb (explicit cast) defaults are unaffected — only naked string literals.
Bug 2 — Multi-role grants
PostgresSupportSchemaInspector.ToGrantDefinitions groups inspector rows by (ObjectName, Role) and emits one PostgresGrantDefinition per group:
.Select(g => new PostgresGrantDefinition {
...
Roles = [g.Key.Role],
Privileges = g.Select(r => r.Privilege).Distinct().OrderBy(p => p).ToList(),
})
So the inspector always returns single-role grants. Meanwhile SameGrant in the verifier uses zip-equality:
private static bool SameIdentifiers(IReadOnlyList<string> actual, IReadOnlyList<string> expected) =>
actual.Count == expected.Count
&& actual.Zip(expected).All(pair => SameIdentifier(pair.First, pair.Second));
Any YAML grant with roles: [app_user, app_admin] has Count == 2, while every inspector grant has Count == 1 — never matches.
Suggested fix: in the verifier, expand a desired multi-role grant into one expected entry per role before searching live.Grants, or have the inspector group only by ObjectName (emitting Roles = [a, b, ...] per object).
Bug 3 — AllTablesInSchema target never inspected
PostgresSupportSchemaInspector.InspectGrants returns two kinds of grants:
InspectSchemaGrants→PostgresGrantTarget.SchemaInspectTableGrants→PostgresGrantTarget.Table
Nothing ever emits PostgresGrantTarget.AllTablesInSchema. But the YAML serialiser accepts target: AllTablesInSchema (PostgresGrantTargetYamlConverter), and the DDL generator presumably honours it on the way in. So the YAML can declare AllTablesInSchema, the migration applies it (we verified every table in public has the expected per-table privileges in information_schema.table_privileges), but SameGrant's actual.Target == expected.Target always fails because no inspector ever returns AllTablesInSchema.
Suggested fix: before calling SameGrant, the verifier should expand a desired AllTablesInSchema grant into one Table grant per table in the schema (cross-product with desired.Tables), then look each up in live.Grants. Alternatively, after InspectTableGrants, detect "every table has identical (role, privileges)" and synthesise an AllTablesInSchema reading.
Impact
This blocks any consumer of DP that uses multi-role grants or AllTablesInSchema from upgrading past 0.9.10-beta. The migration works; the verifier just refuses to accept its own emitted output.
Filed by Claude Code on behalf of NimblesiteAgenticPlatform. Happy to send a PR if you want — let me know.
- 主要言語
- C#
- スター
- 68
- フォーク
- 4
- 平均マージ
- 50分
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
Nimblesite/DataProvider のほかの issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 92/100
Nimblesite/DataProvider#137 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Nimblesite/DataProvider#72 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
Nimblesite/DataProvider#121 ·
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
Nimblesite/DataProvider#108 ·
メンテナーはふだん 1 日以内に返信
-
A check constraint the schema cannot name can never be retired, and keeps enforcing the old ruleオープン
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
Nimblesite/DataProvider#107 ·
メンテナーはふだん 1 日以内に返信
Nimblesite/DataProvider の issue をすべて見る
似ている issue
-
kronos:develop:queued priority:P0
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
nopSolutions/nopCommerce#8512 ·
メンテナーはふだん 4 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
modelcontextprotocol/csharp-sdk#2061 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信