Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)40k · #7294

migrating-oracle-to-postgres-data-access-code

Skill này làm gì

Đoạn mã này giúp chuyển một chương trình từ cơ sở dữ liệu Oracle sang cơ sở dữ liệu PostgreSQL. Nó điều chỉnh các phần mã giao tiếp với cơ sở dữ liệu.

Khi nào nên dùng

  • ✓Khi bạn chuyển một dự án .NET từ Oracle sang PostgreSQL.
  • ✓Khi bạn cập nhật các kết nối và lệnh cơ sở dữ liệu trong mã.
  • ✓Khi bạn cần đảm bảo kiểu dữ liệu và lời gọi thủ tục hoạt động đúng với cơ sở dữ liệu mới.

Liên kết skill

https://github.com/github/awesome-copilot/blob/main/skills/migrating-oracle-to-postgres-data-access-code/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/migrating-oracle-to-postgres-data-access-code/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Chuyển mã truy cập dữ liệu của dự án .NET của tôi từ Oracle sang PostgreSQL, theo danh sách kiểm tra chuyển đổi.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Mã thay các gói Oracle cũ bằng gói dành cho PostgreSQL, điều chỉnh cách chương trình kết nối đến cơ sở dữ liệu, và sửa các khác biệt về lệnh và kiểu dữ liệu giữa hai cơ sở dữ liệu.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Migrating .NET Data Access Code from Oracle to PostgreSQL

Migrate the C# data access layer of a single .Postgres-copy project from Oracle (Oracle.ManagedDataAccess) to PostgreSQL (Npgsql). Work item by item through Reports/{ProjectName}/MigrationChecklist.md.

Prerequisites

  • The .Postgres project copy exists (created in Phase 5 setup).
  • Reports/{ProjectName}/MigrationChecklist.md exists and is the source of truth for what to change.
  • Reports/{ProjectName}/OracleRiskAnalysis.md exists for cross-referencing behavioral differences.

Workflow

Progress:
- [ ] Step 1: Replace NuGet packages
- [ ] Step 2: Update connection string configuration
- [ ] Step 3: Rewrite ADO.NET type references
- [ ] Step 4: Fix DbType mappings
- [ ] Step 5: Migrate stored procedure invocation
- [ ] Step 6: Address Oracle-specific SQL and syntax
- [ ] Step 7: Build and verify

Step 1: Replace NuGet packages

In the .csproj of the .Postgres project:

  • Remove: Oracle.ManagedDataAccess.Core, Oracle.EntityFrameworkCore (and any other Oracle.* packages)
  • Add: Npgsql (for ADO.NET) and/or Npgsql.EntityFrameworkCore.PostgreSQL (for EF Core)
  • Keep version pinning consistent with the target .NET version; do not introduce newer package versions than what the solution already uses for similar packages.
  • If System.Data abstractions (IDbConnection, IDbCommand) are used project-wide, the surface-level code may need fewer changes — identify them first.

Step 2: Update connection string configuration

  • Locate the Oracle connection string in appsettings.json, appsettings.{env}.json, web.config, app.config, or environment variable configuration.
  • Replace with a Npgsql-compatible connection string: Host=localhost;Port=5432;Database=mydb;Username=myuser;Password=mypassword
  • Do not hardcode credentials — use the same configuration mechanism already in use (e.g., environment variables, secrets manager, IConfiguration).
  • Update any named connection string keys only if they were Oracle-specific (e.g., OracleConnection). Prefer keeping the same key name to minimize application config changes.

Step 3: Rewrite ADO.NET type references

Replace Oracle-specific ADO.NET types with Npgsql equivalents:

Oracle type Npgsql replacement
OracleConnection NpgsqlConnection
OracleCommand NpgsqlCommand
OracleDataReader NpgsqlDataReader
OracleDataAdapter NpgsqlDataAdapter
OracleParameter NpgsqlParameter
OracleTransaction NpgsqlTransaction
OracleException NpgsqlException
OracleDbType NpgsqlDbType (from NpgsqlTypes namespace)

Update using directives accordingly (using Oracle.ManagedDataAccess.Client → using Npgsql).

If the codebase uses IDbConnection/IDbCommand abstractions registered via DI, update only the DI registration and connection string — the consuming code may not need changes.

Step 4: Fix DbType and NpgsqlDbType mappings

Oracle parameter types do not map 1:1 to Npgsql. Review every OracleParameter (now NpgsqlParameter) that sets an explicit type:

Oracle type Notes
OracleDbType.Varchar2 Use NpgsqlDbType.Varchar or omit (Npgsql infers from value)
OracleDbType.Clob Use NpgsqlDbType.Text
OracleDbType.Number Use NpgsqlDbType.Numeric or NpgsqlDbType.Integer depending on precision
OracleDbType.Date Use NpgsqlDbType.Date (date only) or NpgsqlDbType.Timestamp (if time component used)
OracleDbType.TimeStamp Use NpgsqlDbType.Timestamp
OracleDbType.RefCursor Use NpgsqlDbType.Refcursor — see Step 5
OracleDbType.Char Use NpgsqlDbType.Char

For parameters where Oracle inferred the type from the value, Npgsql also infers — explicit type setting is often unnecessary and can be removed.

Step 5: Migrate stored procedure invocation

Oracle and PostgreSQL stored procedure invocation differ significantly:

  • Command type: Retain CommandType.StoredProcedure for function calls. For procedures that use OUT parameters, PostgreSQL requires CommandType.Text with CALL proc_name(...) syntax in some versions of Npgsql — verify against the target Npgsql version.
  • RefCursor handling: Oracle returns ref cursors as output parameters; PostgreSQL returns them differently:
    • For RETURNS TABLE / RETURNS SETOF, use ExecuteReader() directly — no cursor parameter needed.

…

Câu hỏi thường gặp

NuGet packages là gì?

Đó giống như các “hộp công cụ” thêm chức năng cho chương trình của bạn. Đoạn mã này thay các hộp công cụ Oracle bằng hộp công cụ dành cho PostgreSQL.

Chuỗi kết nối (connection string) là gì?

Đó giống như địa chỉ và thông tin đăng nhập để chương trình tìm và truy cập cơ sở dữ liệu. Đoạn mã cập nhật địa chỉ này cho cơ sở dữ liệu PostgreSQL mới.

Vì sao cần sửa kiểu dữ liệu?

Các cơ sở dữ liệu hiểu kiểu dữ liệu (văn bản, số, ngày tháng) hơi khác nhau. Đoạn mã đảm bảo dùng đúng kiểu trong PostgreSQL.

Chi tiết

Mô tả gốc của tác giả

Migrates .NET/C# data access code from Oracle to PostgreSQL (Npgsql). Replaces Oracle NuGet packages, rewrites OracleConnection/OracleCommand/OracleDataReader usage, fixes DbType mappings, updates stored procedure invocation patterns, and adapts connection string configuration. Use when migrating the application code layer of a .NET project during an Oracle-to-PostgreSQL database migration.

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7294
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự