Class PostgresProjectionSchema
- Namespace
- Excalibur.EventSourcing.Postgres
- Assembly
- Excalibur.EventSourcing.Postgres.dll
The table a Postgres projection store reads and writes, as a script you can run.
public static class PostgresProjectionSchema
- Inheritance
-
PostgresProjectionSchema
- Inherited Members
Remarks
A projection table's columns are dictated by the store, not by the projection type. The
projection body is stored as JSON in a single data column, so a table whose columns are
named after the projection's own properties will create, deploy, and then fail at the first apply
— on the consumer's database, where nothing in this framework can see it.
The table name is a per-projection option, so this cannot be a fixed script the way the event store's schema is. It is emitted instead, from the same sentinel the store itself reads, which is what keeps the two from drifting.
The schema is a parameter, and it must match the store's. Every statement the store runs
is qualified from its own configured schema, so a table created in a different schema is a table
the store cannot find — with no error until the first read. Pass the same value the store is
configured with; both default to public. Both identifiers are quoted, so their case is
preserved exactly as given and Public is not public.
It does not create the table for you. A store that silently created a missing table would also create it in the wrong database when a connection string is wrong, and a projection reading an empty table it just made is indistinguishable from one that is merely behind.
Methods
CreateTableScript(string, string)
Builds the CREATE TABLE script for a projection table, idempotently.
public static string CreateTableScript(string tableName, string schema = "public")
Parameters
tableNamestringThe table name, matching the store's configured table name.
schemastringThe schema to create it in, matching the store's configured schema.
Returns
- string
A script that creates the table if it does not already exist.
Exceptions
- ArgumentException
A name is empty, whitespace, or contains a character that is not a letter, a digit or an underscore. The identifiers are interpolated into the script, so they are restricted rather than quoted-and-hoped: these names are deployment-time constants, never user input.
CreateTransactionalTableScript(string, string)
Creates a dedicated aggregate-local transactional projection table.
public static string CreateTransactionalTableScript(string tableName, string schema = "public")
Parameters
tableNamestringPhysical destination table, including its generation suffix.
schemastringSQL schema.
Returns
- string
Idempotent creation script; existing ordinary tables are not converted.