Postgres function inspector reads wrong column ordinals: any schema with a function fails integrity inspection

未关闭 适合新手
#137 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1-3 小时
新手友好度
92/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
csharp, postgresql, sql
领域
database

调研方向

从 Migration/Nimblesite.DataProvider.Migration.Postgres/PostgresSupportSchemaInspector.cs 中的 functions 目录查询和读取器开始,将所选列与 GetString、IsDBNull 和 GetBoolean 使用的序号进行比较。针对包含 functions: 的所提供 schema 运行 DataProviderMigrate migrate --provider postgres,以重现完整性故障。当函数使用正确的所有者、搜索路径和 revoke 标志进行检查、迁移通过完整性验证,并且重新执行时不会产生任何更改时,即告完成。

由索引模型根据 Issue 内容生成。

描述

Bug

At refactor/deslop-ten-percent (3b4e356522affc61b466d8e87ef5232319c9d7a0), DataProviderMigrate migrate --provider postgres fails for every schema that has a function in the inspected schema (for example a top-level functions: entry):

Error: schema integrity inspection failed: Reading as 'System.String' is not supported for fields having DataTypeName 'boolean'
Error: migration apply failed: Schema integrity verification failed before commit

Cause

Migration/Nimblesite.DataProvider.Migration.Postgres/PostgresSupportSchemaInspector.cs: the functions catalog query selects, in order,

ordinal column
7 p.prosecdef
8 p.prosrc
9 owner.rolname AS owner_role
10 search_path_config
11 revoke_public_execute (boolean)
12 execute_roles

but the reader uses

OwnerRole = reader.GetString(10),
SearchPath = ParseSearchPathConfig(reader.IsDBNull(11) ? null : reader.GetString(11)),
RevokePublicExecute = reader.GetBoolean(9),

so it reads a boolean as a string (and the owner as a boolean).

Fix

OwnerRole = reader.GetString(9),
SearchPath = ParseSearchPathConfig(reader.IsDBNull(10) ? null : reader.GetString(10)),
RevokePublicExecute = reader.GetBoolean(11),

Verified on PostgreSQL with a securityDefiner function declaring ownerRole, searchPath, executeRoles and revokePublicExecute: with the three ordinals corrected, migrate applies, passes the integrity check and replays as a no-op.

Repro

roles:
  - { name: demo_writer, login: false }
functions:
  - schema: demo
    name: touch
    returns: void
    language: sql
    volatility: volatile
    securityDefiner: true
    ownerRole: demo_writer
    searchPath: [pg_catalog]
    body: SELECT 1

Related gaps found at the same time

  • Grants have no column lists (GRANT SELECT (a, b) ON TABLE …); only table-level privileges can be declared, inspected and verified.
  • Roles have no way to receive a password (for example from an environment variable).
  • A schema cannot be created by the migration (CREATE SCHEMA must be run by hand first).
主要语言
C#
星标
68
派生
4
平均合并
50 分钟
30 天内合并 PR
2

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Nimblesite/DataProvider 的其他 Issue

查看 Nimblesite/DataProvider 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。