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

Đang mở Phù hợp với người mới
#137 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
92/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp, postgresql, sql
Lĩnh vực
database

Hướng nghiên cứu

Bắt đầu với truy vấn danh mục functions và trình đọc trong Migration/Nimblesite.DataProvider.Migration.Postgres/PostgresSupportSchemaInspector.cs, so sánh các cột được chọn với các thứ tự được GetString, IsDBNull và GetBoolean sử dụng. Chạy DataProviderMigrate migrate --provider postgres với schema được cung cấp có chứa functions: để tái hiện lỗi tính toàn vẹn. Hoàn tất khi hàm được kiểm tra với đúng chủ sở hữu, đường dẫn tìm kiếm và các cờ thu hồi, quá trình di chuyển vượt qua kiểm tra tính toàn vẹn và việc chạy lại không làm thay đổi gì.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).
Ngôn ngữ chính
C#
Star
68
Fork
4
Merge trung bình
50 phút
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Nimblesite/DataProvider

Tất cả issue của Nimblesite/DataProvider

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.