<pblock label="Plan artifact repair" kind="repair">
# Plan Artifact Repair

Drydock accepted the Plan response shape but rejected the emitted Blueprint artifact(s)
below. Repair only the deterministic defect. Preserve all unrelated content, contracts,
headings, decisions, and acceptance assertions byte-for-byte where possible.
Do not remove or weaken a valid assertion while adding a missing one. Every artifact with
a programmatic surface retains at least two concrete Python acceptance assertions. Every
DECISIONS.json is the sole decision disclosure surface; do not emit Markdown question sections.

Emit each artifact below in exactly this form, and emit no other text:

=== BEGIN ARTIFACT <FILENAME> ===
<the complete file body>
=== END ARTIFACT ===

The filename appears once, in the opening delimiter. The closing delimiter is the
constant token above and never carries a name.

Emit exactly one such block for each of: DATABASE.md.

Repair pass: 1

Deterministic validation defect:
DATABASE.md [## Access Patterns]: DATABASE.md: FEATURE-DB-001 has invalid repository operation 'schema.initialize': it names one declared table and one verb as `<table>.<verb>`, lowercase, where the verb is one of get, list, create, update, delete

Every `| Owner |` names one of these Features, exactly as written, or `DATABASE.md` for a pattern no single Feature owns — a log or other surface several Features reach, which any Blueprint may then cite. There are no other legal values: a Screen, a service, a module, and a file not on this list are each a defect.

- FEATURE-Account-Category-Loading.md
- FEATURE-Account-Management.md
- FEATURE-Balance-Invariant.md
- FEATURE-CLI-Dispatcher.md
- FEATURE-CLI-Validation.md
- FEATURE-Conformance.md
- FEATURE-Database-Configuration.md
- FEATURE-Project-Tests.md
- FEATURE-Report-Balances.md
- FEATURE-Report-Categories.md
- FEATURE-Report-Monthly.md
- FEATURE-Transaction-Loading.md
- FEATURE-Transaction-Management.md
- FEATURE-Transfers.md

Normative Compass sections. They bind every assertion you write or retain, including one you add to satisfy the defect above.

## Constraints

- Implement in the language and database named under `## Stack` in `sources/INSTRUCTIONS.md`.
- Provide an executable named `ledger` at the application root, invoked as `./ledger <command>`.
- Read the database location from `DATABASE_URL`, then `DATABASE_PATH`, then `data/app.db`.
- Store amounts as integer cents.
- Check every command in full before its first write.
- Run without network access other than to a PostgreSQL server named by `DATABASE_URL`.
- Diagnostics go to standard error and are never compared.

## Guardrails

- Do not modify, rewrite, regenerate, or substitute any file under `sources/`.
- Do not read `sources/run.sh` or any seed file from application code. Seed files reach the
  database only through `ledger load`.
- Do not hardcode a report row, a count, or a total. Every value comes from a query.
- Do not open a database driver outside the shipped persistence library.
- Do not use floating point for money at any layer.

## Verification Protocol

| Story kind | Command | Asserts |
|---|---|---|
| Every behavioral story | `sh bin/test.sh` | exit `0` |
| Terminal story (once, last) | `sh sources/run.sh` | exit `0` |

<!-- drydock:build-write-guardrail:start -->

Original DATABASE.md, in the same form your reply must use:
=== BEGIN ARTIFACT DATABASE.md ===
# DATABASE: Ledger Persistence

| Field       | Value |
|-------------|-------|
| Version     | 20261020 V1 |
| Description | Define the relational ledger schema and typed persistence operations. |
| Depends On  | ARCHITECTURE.md |
| Provides    | accounts table, categories table, transactions table, schema initialization |
| Consumes    | — |

## Questions

- None.

## Stores

The application uses the relational database selected by `DATABASE_URL`, then `DATABASE_PATH`, then `data/app.db`. SQLite paths may be prefixed with `sqlite://`; PostgreSQL DSNs begin with `postgres://` or `postgresql://`. Application callers use only `persistence.open_database`.

## Access Patterns

### FEATURE-DB-001 — Initialize schema

| Field | Value |
|---|---|
| Owner | DATABASE.md |
| Access | write |
| Repository operation | `schema.initialize` |
| Compatibility | rebuild |

Input: `InitializeSchema`

| Field | Type |
|---|---|
| drop_existing | INTEGER |

Output: `SchemaStatus`

| Field | Type |
|---|---|
| tables | TEXT |

### FEATURE-DB-002 — Account operations

| Field | Value |
|---|---|
| Owner | FEATURE-Account-Category-Loading.md |
| Access | read-write |
| Repository operation | `accounts.create` |
| Compatibility | unchanged |

Input: `AccountInput`

| Field | Type |
|---|---|
| account | VARCHAR(12) |
| name | VARCHAR(40) |

Output: `AccountRow`

| Field | Type |
|---|---|
| account | VARCHAR(12) |
| name | VARCHAR(40) |

### FEATURE-DB-003 — Category operations

| Field | Value |
|---|---|
| Owner | FEATURE-Account-Category-Loading.md |
| Access | read-write |
| Repository operation | `categories.create` |
| Compatibility | unchanged |

Input: `CategoryInput`

| Field | Type |
|---|---|
| category | VARCHAR(12) |
| description | VARCHAR(40) |

Output: `CategoryRow`

| Field | Type |
|---|---|
| category | VARCHAR(12) |
| description | VARCHAR(40) |

### FEATURE-DB-004 — Transaction operations

| Field | Value |
|---|---|
| Owner | FEATURE-Transaction-Loading.md |
| Access | read-write |
| Repository operation | `transactions.create` |
| Compatibility | unchanged |

Input: `TransactionInput`

| Field | Type |
|---|---|
| txn_id | INTEGER |
| date | VARCHAR(10) |
| account | VARCHAR(12) |
| category | VARCHAR(12) |
| amount | INTEGER |
| memo | VARCHAR(60) |

Output: `TransactionRow`

| Field | Type |
|---|---|
| txn_id | INTEGER |
| date | VARCHAR(10) |
| account | VARCHAR(12) |
| category | VARCHAR(12) |
| amount | INTEGER |
| memo | VARCHAR(60) |

### FEATURE-DB-005 — Account reads and mutations

| Field | Value |
|---|---|
| Owner | FEATURE-Account-Management.md |
| Access | read-write |
| Repository operation | `accounts.get` |
| Compatibility | unchanged |

Input: `AccountLookup`

| Field | Type |
|---|---|
| account | VARCHAR(12) |

Output: `AccountBalanceRow`

| Field | Type |
|---|---|
| account | VARCHAR(12) |
| name | VARCHAR(40) |
| transactions | INTEGER |
| balance | INTEGER |

### FEATURE-DB-006 — Transaction reads and mutations

| Field | Value |
|---|---|
| Owner | FEATURE-Transaction-Management.md |
| Access | read-write |
| Repository operation | `transactions.get` |
| Compatibility | unchanged |

Input: `TransactionLookup`

| Field | Type |
|---|---|
| txn_id | INTEGER |

Output: `TransactionRow`

| Field | Type |
|---|---|
| txn_id | INTEGER |
| date | VARCHAR(10) |
| account | VARCHAR(12) |
| category | VARCHAR(12) |
| amount | INTEGER |
| memo | VARCHAR(60) |

### FEATURE-DB-007 — Report reads

| Field | Value |
|---|---|
| Owner | DATABASE.md |
| Access | read |
| Repository operation | `accounts.list` |
| Compatibility | unchanged |

Input: `ReportQuery`

| Field | Type |
|---|---|
| report | TEXT |

Output: `ReportRow`

| Field | Type |
|---|---|
| values | TEXT |

## Schema

## `accounts`

| Field | Type | Notes |
|---|---|---|
| account | VARCHAR(12) PK NOT NULL | Account code |
| name | VARCHAR(40) NOT NULL | Account name |

## `categories`

| Field | Type | Notes |
|---|---|---|
| category | VARCHAR(12) PK NOT NULL | Category code |
| description | VARCHAR(40) NOT NULL | Category description |

## `transactions`

| Field | Type | Notes |
|---|---|---|
| txn_id | INTEGER PK NOT NULL | Transaction identifier |
| date | VARCHAR(10) NOT NULL | Calendar date in `YYYY-MM-DD` form |
| account | VARCHAR(12) NOT NULL REFERENCES accounts(account) | Account code |
| category | VARCHAR(12) NOT NULL REFERENCES categories(category) | Category code |
| amount | INTEGER NOT NULL | Integer cents |
| memo | VARCHAR(60) NOT NULL | Transaction memo |

## Atomicity and Invariants

Schema initialization drops and recreates all three tables. Foreign keys are enforced. Every command validates all inputs and prospective balance effects before its first write. Transactions are committed atomically.

## Programmatic Acceptance

- None. Schema construction, generated persistence operations, and connectivity invariants are owned and verified deterministically by Drydock's persistence foundation.

## User Acceptance

- None.

## Guardrails

- Amounts are stored as integer cents.
- No application module may open a database driver directly.
- Every rejected command must preserve all existing rows.
- Schema initialization must leave all three tables empty.
=== END ARTIFACT ===
</pblock>

