# `ExGAM.Ledger.Store.Postgres`
[🔗](https://github.com/elchemista/ex_gam/blob/0.1.0/lib/ex_gam/ledger/store/postgres.ex#L1)

PostgreSQL ledger adapter backed by the host application's Repo.

ExGAM intentionally has no database dependency. The application supplies
`:repo`; by default SQL is executed dynamically through
`Ecto.Adapters.SQL.query/4` and transactions through the Repo's
`transaction/2` and `rollback/1` callbacks. A different compatible SQL module
may be supplied with `:query_module`.

Each logical batch is stored once as canonical bytes. A transaction-scoped
advisory lock serializes one Domain, while a revision-guarded head update and
database constraints preserve CAS and idempotency. Write transactions force
`synchronous_commit` on; the host remains responsible for keeping PostgreSQL
`fsync` enabled. The host provisions the schema in a migration using the SQL returned
by `migration_sql/1`.

`compressed: true` optionally compresses each new canonical batch before
storage. Readers accept compressed and plain batches independently of that
setting. Indexed `head/2` and `read_batch/3` support bounded recovery input;
full load/export remain explicit historical operations.

# `migration_sql`

```elixir
@spec migration_sql(keyword()) ::
  {:ok, %{up: [String.t()], down: [String.t()]}} | {:error, term()}
```

Returns the PostgreSQL DDL for a versioned host migration.

# `namespace`

```elixir
@spec namespace(keyword()) ::
  {:ok, %{schema: String.t(), table_prefix: String.t()}} | {:error, term()}
```

Returns the validated SQL namespace used for the ledger tables.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
