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.mdSao 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
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
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
.Postgresproject copy exists (created in Phase 5 setup). Reports/{ProjectName}/MigrationChecklist.mdexists and is the source of truth for what to change.Reports/{ProjectName}/OracleRiskAnalysis.mdexists 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 otherOracle.*packages) - Add:
Npgsql(for ADO.NET) and/orNpgsql.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.Dataabstractions (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.StoredProcedurefor function calls. For procedures that useOUTparameters, PostgreSQL requiresCommandType.TextwithCALL 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, useExecuteReader()directly — no cursor parameter needed.
- For
…
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
Bình luận
- …
Thêm skill từ kho mã này
acquire-codebase-knowledge
40kGiúp agent của bạn hiểu và ghi tài liệu cho một dự án mã nguồn có sẵn. Hữu ích khi đón thành viên mới hoặc nắm tổng quan về kiến trúc.
acreadiness-assess
40kGiúp agent của bạn đánh giá mức độ sẵn sàng cho AI của dự án và tạo báo cáo. Hữu ích để biết dự án đã sẵn sàng dùng công cụ AI đến đâu.
acreadiness-generate-instructions
40kGiúp agent của bạn tạo hướng dẫn cho công cụ AI dựa trên kết quả đánh giá. Hữu ích để cải thiện cách AI làm việc với mã và khắc phục các khoảng trống.
acreadiness-policy
40kGiúp agent của bạn xác định hoặc áp dụng chính sách đánh giá dự án bằng AI. Hữu ích để chuẩn hóa cách đánh giá dự án và đảm bảo tuân thủ.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.