Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

purview-persistence

/purview-persistence

Pomaga w wyborze trwałego zapisu danych w projekcie .NET: EF Core, PostgreSQL, SQL Server i klucze GUID, pomijając projekty bez zapisu.

Repozytorium
unions ↗
Licencja
MIT
Ostatnia zmiana repozytorium
12.11.2026

Ocena i bezpieczeństwo

90/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść25 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
6
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 12.11.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Pomaga w wyborze trwałego zapisu danych w projekcie .NET: EF Core, PostgreSQL, SQL Server i klucze GUID, pomijając projekty bez zapisu.

Oryginalny opis (EN)

Use when a .NET project actually persists data and you are choosing a storage approach, integrating or abstracting EF Core, deriving a well-known identifier, or selecting a GUID primary-key strategy. Gives provider-specific guidance — SQL Server and PostgreSQL differ and must not be treated alike — and stays silent for projects that do not persist anything.

Jak działa

  1. 1. Shape the data access proportionally
  2. 2. Local dependencies
  3. 3. EF Core integration
  4. 4. Identifiers — derived or generated
  5. 5. Value objects as keys
  6. 6. Migrations and schema
  7. Checks before you answer
  8. See also
Sekcje z nagłówków SKILL.md, w oryginale · 137 linii, 1 153 słów
Podgląd SKILL.md
---
name: purview-persistence
description: >-
  Use when a .NET project actually persists data and you are choosing a storage approach, integrating
  or abstracting EF Core, deriving a well-known identifier, or selecting a GUID primary-key strategy.
  Gives provider-specific guidance — SQL Server and PostgreSQL differ and must not be treated alike —
  and stays silent for projects that do not persist anything.
license: MIT
metadata:
  author: Purview-Dev
  version: "1.2"
  repository: purview-dev/engineering-playbook
---

# Purview persistence

**Activation condition:** this skill applies only when persistence is real. If the project is a
stateless CLI, a pure library, or a service that calls an API and stores nothing, stop here — none of
this is relevant, and raising a database GUID strategy with that project is noise.

Confirm persistence from the repository before proceeding (see `purview-architecture`): a data-access
`PackageReference`, a `DbContext`, a connection string, or an explicit requirement to store state.

## 1. Shape the data access proportionally

| Scale | Shape |
| -- | -- |
| Small | `DbContext` used directly from the code that needs it. No repository, no unit-of-work wrapper — `DbContext` already is both. |
| Medium | A boundary when domain rules must not know about EF Core, or when a query is complex enough to deserve a name. Often that is a few focused query types, not a generic `IRepository<T>`. |
| Large | Independent infrastructure implementations where there genuinely are several, with the dependency direction enforced by a test. |

**Do not wrap EF Core in a repository for testability.** `Purview.Containers` gives you a real
database in tests, which is both more faithful and less code than an abstraction built to be mocked.
A repository earns its place when you must swap the store or when `DbContext` is genuinely leaking
into domain decisions — not before.

## 2. Local dependencies

`Purview.Containers` provides Aspire resource integrations for the dependencies you need in
development and integration tests — including `MsSql`, `PostgreSql`, `MySql`, `Redis`, `Nats`,
`RabbitMq`, `Azurite` and an Azure Key Vault emulator. Prefer a real container over an in-memory
provider: the in-memory provider does not enforce the constraints that break you in production.

## 3. EF Core integration

When EF Core is the store, keep the integration in four places:

- **`DbContext` is the boundary.** Use it directly; do not add `IRepository<T>` or a unit-of-work wrapper
  for testability. `Purview.Containers` gives you a real database in tests.
- **Choose the provider where the context is registered.** Carry the choice as context-options data, not
  a `Database.ProviderName` branch at model-build time.
- **Map value objects once.** Configure converters and comparers in the model, not per property. A
  value-object key needs a converter-aware value generator.
- **Keep design time and runtime in step.** Both paths make the same provider, strategy and
  `ReplaceService` choices, or the migration snapshot describes a different model.

Migrations are code, reviewed and applied by a deliberate step; the API does not migrate at startup in
production. The full rule, composition sample and checks are in `references/ef-core-integration.md`.

## 4. Identifiers — derived or generated

Two decisions live here, and they are independent. Ask them in this order.

### The deterministic-identifier gate

Derive an identifier only when its **value must be known before storage** — a system tenant, a seeded
reference row, an installation's service principal, or an ingested object whose provider key is stable
and never recycled. Then derive it with UUIDv5 over an installation-scoped namespace and configure
`ValueGeneratedNever()`, so the sequential convention below leaves it alone. A project with random keys
and no seeding has no use for UUIDv5. An outbox row that merely needs an id before `SaveChanges` takes
the generated strategy below, not a derived one.

The full rule, catalogue, naming rules, migration caveat and tests are in
`references/well-known-identifiers.md`.

### The generated-key decision

Resolve these before recommending anything; most are answered by the repository:

1. Are GUIDs primary keys, or merely external identifiers over an integer key?
2. Is the value generated by the application or by the database?
3. Which provider, and which version?
4. Does index locality matter at the expected write volume?
5. Must the identifier exist before the row is persisted?

Question 5 usually decides it. If the application needs the identifier before `SaveChanges` — for an
outbox row, a correlation value, or to build an object graph client-side — the database cannot be the
generator, and the remaining questions are about *which* client-side strategy.

### The rule that matters most

**SQL Server and PostgreSQL do not benefit from the same sequential GUID implementation.** Their
index structures and their GUID comparison semantics differ, and a "sequential GUID" that helps one
can be no better than random on the other. Never carry a strategy from one to the other without
re-deriving it.

- SQL Server specifics: `references/sqlserver.md`
- PostgreSQL specifics: `references/postgresql.md`
- Choosing between them, and when a custom generator is justified: `references/guid-generation.md`

### Prefer built-in capability

Use the framework or database capability when it is sufficient — `Guid.CreateVersion7()` on .NET 9+,
`NEWSEQUENTIALID()`, EF Core's own value generators, a provider's native UUIDv7 function. A custom
generator is a maintenance obligation and a correctness risk; introduce one only against a measured
requirement.

**No NuGet package provides this pattern.** A reviewed generator such as `FastGuid` supplies a
store-ordered implementation, but the strategy witness, options extension, value generator with
value-converter support, and model-finalising convention are repository-local: copy them, do not depend
on a package that claims to own the wiring. Introduce it only for a measured requirement: a second
provider, or an identifier needed before `SaveChanges`. Until the second provider exists, a built-in
capability is the answer.

## 5. Value objects as keys

`Purview.ValueObjects` gives strongly-typed identifiers that stop an `OrderId` being passed where a
`CustomerId` belongs. They need an EF Core value converter; configure it once in the model rather
than per property.

This is about type safety at the boundary, not about the generation strategy — the two decisions are
independent.

## 6. Migrations and schema

- Migrations are code: reviewed, tested against a real container, and applied by a deliberate step —
  not by the application at startup in production.
- Expect the schema to be ahead of or behind the code during a deployment; design changes to be
  compatible in both directions.
- Keep the connection string out of source. Keep it out of telemetry too.

## Checks before you answer

- Have you confirmed persistence is actually required?
- If the project uses EF Core, are you recommending the `DbContext` directly rather than a repository
  wrapper added for testability?
- Does the design-time path make the same provider and strategy choices as the runtime path?
- Does every generated value have one owner — application, store or derivation — and no second writer?
- If you are deriving an identifier, is its value genuinely known before storage, and is it keyed
  `ValueGeneratedNever()`?
- If you are recommending a GUID strategy, do you know the provider *and* its version?
- If you are proposing the strategy/convention, is there a second provider or a pre-save identifier?
- Are you proposing an abstraction you can justify by something other than testability?
- Have you preferred a built-in capability over a custom generator?

## See also

- `purview-architecture` — context discovery and proportional structure
- `purview-telemetry` — instrument the data access too; it is where the latency is
Pliki w paczce (6)
  • SKILL.md 8 KB
  • references/ef-core-integration.md 5 KB
  • references/guid-generation.md 5 KB
  • references/postgresql.md 6 KB
  • references/sqlserver.md 6 KB
  • references/well-known-identifiers.md 5 KB

Wersje

W bazie nie ma innych skilli o nazwie purview-persistence.

Migawka bazy z 13.11.2026 · wersja paczki 90805e86f7bd (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100pm-purview
    Wskazuje narzędzia i praktyki Purview pasujące do projektu .NET, takie jak telemetria, walidacja i testy integracyjne.
  • 100purview-engineering-principles
    Ustawia i przegląda repozytorium .NET zgodnie z konwencjami Purview: konwencja ponad konfigurację, testy architektury i ostrzeżenia jako błędy.
  • 100purview-openapi-xmlcomments-duplicates
    Naprawia błąd zduplikowanych kluczy w dokumentacji OpenAPI ASP.NET Core: znajduje kolidujące identyfikatory XML i konfiguruje Purview.
  • 100purview-architecture
    Pomaga ustalić kształt rozwiązania .NET z bibliotekami Purview: liczbę projektów, warstwy, kontrakty API i moment użycia BFF.
  • 100fai-sql-code-review-skill
    Przegląda kod SQL pod kątem poprawności, wydajności, bezpieczeństwa i utrzymywalności w PostgreSQL, SQL Server i MySQL, w PR i skryptach migracji baz.
  • 86postgresql
    Pomaga projektować bazy PostgreSQL, optymalizować zapytania SQL, pisać procedury i zapytania JSONB.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.