{"id":21623023,"url":"https://github.com/pandatecham/be-lib-sharedkernel-postgres","last_synced_at":"2026-04-18T17:32:05.870Z","repository":{"id":264212158,"uuid":"892162908","full_name":"PandaTechAM/be-lib-sharedkernel-postgres","owner":"PandaTechAM","description":"Most common utilities used in every project by PandaTech + Postgres extensions","archived":false,"fork":false,"pushed_at":"2026-03-19T10:30:16.000Z","size":5842,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"development","last_synced_at":"2026-03-19T21:21:21.339Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PandaTechAM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-11-21T16:05:51.000Z","updated_at":"2026-03-19T10:27:41.000Z","dependencies_parsed_at":"2025-03-31T12:22:56.126Z","dependency_job_id":"ac43c138-2901-44b8-bcfe-1fd40bfa4ac2","html_url":"https://github.com/PandaTechAM/be-lib-sharedkernel-postgres","commit_stats":null,"previous_names":["pandatecham/be-lib-sharedkernel-postgres"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PandaTechAM/be-lib-sharedkernel-postgres","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandaTechAM%2Fbe-lib-sharedkernel-postgres","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandaTechAM%2Fbe-lib-sharedkernel-postgres/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandaTechAM%2Fbe-lib-sharedkernel-postgres/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandaTechAM%2Fbe-lib-sharedkernel-postgres/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PandaTechAM","download_url":"https://codeload.github.com/PandaTechAM/be-lib-sharedkernel-postgres/tar.gz/refs/heads/development","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PandaTechAM%2Fbe-lib-sharedkernel-postgres/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31977964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T17:30:12.329Z","status":"ssl_error","status_checked_at":"2026-04-18T17:29:59.069Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-25T00:11:16.755Z","updated_at":"2026-04-18T17:32:05.863Z","avatar_url":"https://github.com/PandaTechAM.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pandatech.SharedKernel.Postgres\n\nPostgreSQL integration helpers for ASP.NET Core 10. Wraps Npgsql, Entity Framework Core, health checks, exception\nmapping, query locks, snake_case naming, and audit trail wiring into a small set of extension methods so every service\nstarts from the same consistent baseline.\n\nRequires **.NET 10.0**. Uses C# 14 extension members and cannot be downgraded.\n\n---\n\n## Table of Contents\n\n1. [Installation](#installation)\n2. [What is included](#what-is-included)\n3. [Registering a DbContext](#registering-a-dbcontext)\n4. [Migrations](#migrations)\n5. [Model configuration helpers](#model-configuration-helpers)\n6. [Health checks](#health-checks)\n\n---\n\n## Installation\n\n```bash\ndotnet add package Pandatech.SharedKernel.Postgres\n```\n\n---\n\n## What is included\n\nEvery `AddPostgresContext*` overload automatically applies the following to your DbContext:\n\n| Feature                           | Source package                              |\n|-----------------------------------|---------------------------------------------|\n| Npgsql provider                   | `Npgsql.EntityFrameworkCore.PostgreSQL`     |\n| Snake_case naming convention      | `EFCore.NamingConventions`                  |\n| Query locks (`FOR UPDATE` etc.)   | `Pandatech.EFCore.PostgresExtensions`       |\n| Friendly exception mapping        | `EntityFrameworkCore.Exceptions.PostgreSQL` |\n| `AuditBase` property validation   | `Pandatech.EFCore.AuditBase`                |\n| Audit trail interceptors (opt-in) | `Pandatech.EFCore.Audit`                    |\n| Postgres health check             | `AspNetCore.HealthChecks.NpgSql`            |\n| Bulk extensions                   | `EFCore.BulkExtensions.PostgreSql`          |\n| Gridify query extensions          | `Pandatech.GridifyExtensions`               |\n\n---\n\n## Registering a DbContext\n\nAll overloads are on `WebApplicationBuilder` and return `WebApplicationBuilder` for chaining. Every variant\nautomatically registers a Postgres health check named `postgres_{DatabaseName}`.\n\n### Basic registration (no pooling, no audit trail)\n\n```csharp\n// Minimal — connection string only\nbuilder.AddPostgresContext\u003cAppDbContext\u003e(connectionString);\n\n// With migrations assembly by name\nbuilder.AddPostgresContext\u003cAppDbContext\u003e(connectionString, \"MyApp.Migrations\");\n\n// With migrations assembly by Assembly reference\nbuilder.AddPostgresContext\u003cAppDbContext\u003e(connectionString, typeof(Program).Assembly);\n\n// With migrations assembly by marker type\nbuilder.AddPostgresContext\u003cAppDbContext, Program\u003e(connectionString);\n\n// Full control via NpgsqlDbContextOptionsBuilder callback\nbuilder.AddPostgresContext\u003cAppDbContext\u003e(connectionString, npgsql =\u003e\n{\n    npgsql.MigrationsAssembly(\"MyApp.Migrations\");\n    npgsql.CommandTimeout(60);\n});\n```\n\n### With connection pooling\n\nSame set of overloads, prefixed with `Pool`:\n\n```csharp\nbuilder.AddPostgresContextPool\u003cAppDbContext\u003e(connectionString);\nbuilder.AddPostgresContextPool\u003cAppDbContext\u003e(connectionString, \"MyApp.Migrations\");\nbuilder.AddPostgresContextPool\u003cAppDbContext, Program\u003e(connectionString);\nbuilder.AddPostgresContextPool\u003cAppDbContext\u003e(connectionString, npgsql =\u003e { ... });\n```\n\nUse pooling for high-throughput services. Note that DbContext pooling requires that your context has no scoped\ndependencies injected via the constructor; use service provider overloads (`(sp, options) =\u003e ...`) for those cases.\n\n### With audit trail (no pooling)\n\nRegisters the `Pandatech.EFCore.Audit` interceptors alongside the standard options:\n\n```csharp\nbuilder.AddPostgresContextWithAuditTrail\u003cAppDbContext\u003e(connectionString);\nbuilder.AddPostgresContextWithAuditTrail\u003cAppDbContext\u003e(connectionString, \"MyApp.Migrations\");\nbuilder.AddPostgresContextWithAuditTrail\u003cAppDbContext, Program\u003e(connectionString);\nbuilder.AddPostgresContextWithAuditTrail\u003cAppDbContext\u003e(connectionString, npgsql =\u003e { ... });\n```\n\n### With pooling and audit trail\n\n```csharp\nbuilder.AddPostgresContextPoolWithAuditTrail\u003cAppDbContext\u003e(connectionString);\nbuilder.AddPostgresContextPoolWithAuditTrail\u003cAppDbContext\u003e(connectionString, \"MyApp.Migrations\");\nbuilder.AddPostgresContextPoolWithAuditTrail\u003cAppDbContext, Program\u003e(connectionString);\nbuilder.AddPostgresContextPoolWithAuditTrail\u003cAppDbContext\u003e(connectionString, npgsql =\u003e { ... });\n```\n\n---\n\n## Migrations\n\nApply pending migrations at startup:\n\n```csharp\n// Synchronous\napp.MigrateDatabase\u003cAppDbContext\u003e();\n\n// Asynchronous\nawait app.MigrateDatabaseAsync\u003cAppDbContext\u003e(ct);\n```\n\nBoth create a scoped service provider, resolve the context, and call `Database.Migrate` / `Database.MigrateAsync`.\nPlace these calls after `app.Build()` and before `app.Run()`.\n\n---\n\n## Model configuration helpers\n\nAdd to `ConfigureConventions` and `OnModelCreating` in your DbContext:\n\n```csharp\nprotected override void ConfigureConventions(ModelConfigurationBuilder builder)\n{\n    // Map all decimal properties to NUMERIC(40, 20) — prevents precision loss\n    builder.ConfigureDecimalType();\n}\n\nprotected override void OnModelCreating(ModelBuilder modelBuilder)\n{\n    // Set all foreign key delete behavior to Restrict (no accidental cascades)\n    modelBuilder.RestrictFkDeleteBehaviorByDefault();\n}\n```\n\n`ConfigureDecimalType` sets precision `(40, 20)` globally. Override individual properties via `[Precision]` or fluent\nAPI if you need a narrower type for a specific column.\n\n`RestrictFkDeleteBehaviorByDefault` iterates all foreign keys at model build time and sets `DeleteBehavior.Restrict`.\nOverride individual relationships fluently after this call if cascade delete is intentionally needed.\n\n---\n\n## Health checks\n\nThe health check is registered automatically by every `AddPostgresContext*` overload. It uses\n`AspNetCore.HealthChecks.NpgSql` with a 5-second timeout and is named `postgres_{DatabaseName}` where the database\nname is parsed from the connection string.\n\nTo expose the health check endpoint, use `MapHealthCheckEndpoints()` from `Pandatech.SharedKernel`:\n\n```csharp\napp.MapHealthCheckEndpoints(); // /above-board/health\n```\n\nOr register your own endpoint:\n\n```csharp\napp.MapHealthChecks(\"/health\");\n```\n\nIf the database name cannot be parsed from the connection string, registration throws `ArgumentException` at startup\nrather than silently registering a misnamed check.\n\n---\n\n## License\n\nMIT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandatecham%2Fbe-lib-sharedkernel-postgres","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpandatecham%2Fbe-lib-sharedkernel-postgres","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandatecham%2Fbe-lib-sharedkernel-postgres/lists"}