HORIZON HASKELLDocslts/ghc-9.14.x3e2d5682026-10-11Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · 3e2d568 · 2026-10-11

Modulepersistent-postgresql-2.14.3.0Haskell2010

Database.Persist.Postgresql.Internal.Migration

Generate postgresql migrations for a set of EntityDefs, either from scratch or based on the current state of a database.

  • 7 types
  • 37 values
newtypenewtype SchemaState
#

In order to ensure that generating migrations is fast and avoids N+1 queries, we split it into two phases. The first phase involves querying the database to gather all of the information we need about the existing schema. The second phase then generates migrations based on the information from the first phase. This data type represents all of the data that's gathered during the first phase: information about the current state of the entities we're migrating in the database.

Instances2Eq, Show
  • Eq SchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
  • Show SchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
datadata EntitySchemaState
#

The state of a particular entity (i.e. table) in the database; we generate migrations based on the diff of this versus an EntityDef.

Constructors

Instances2Eq, Show
  • Eq EntitySchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
  • Show EntitySchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration

Information about an existing table in the database

Constructors

  • ExistingEntitySchemaState
    • essColumns :: Map FieldNameDB (Column, Set ColumnReference)

      The columns in this entity, together with the set of foreign key constraints that they are subject to. Usually the ColumnReference list will contain 0-1 elements, but in the event that there are multiple FK constraints applying to a given column in the database we need to keep track of them all because we don't yet know which one has the right name (based on what is in the corresponding model's EntityDef).

      Note that cReference will be unset for these columns, for the same reason: there may be multiple FK constraints and we don't yet know which one to use.

    • essUniqueConstraints :: Map ConstraintNameDB [FieldNameDB]

      A map of unique constraint names to the columns that are affected by those constraints.

Instances2Eq, Show

Get foreign key constraint information for all columns in the supplied tables from the database. We return a list of references per column because there may be duplicate FK constraints in the database.

Note that we only care about FKs where the column in question has ordinal position 1 i.e. is the first column appearing in the FK constraint. Eventually we may want to fill this gap so that multi-column FK constraints can be dealt with by this migrator, but for now that is not something that persistent-postgresql handles.

newtypenewtype SafeToRemove
#

Indicates whether a Postgres Column is safe to drop.

Constructors

Instances2Eq, Show
  • Eq SafeToRemoveDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
  • Show SafeToRemoveDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
datadata AlterColumn
#
Instances2Eq, Show
  • Eq AlterColumnDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
  • Show AlterColumnDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration

Generate the default foreign key constraint name for a given source table and source column name. Note that this function should generally not be used except as an argument to postgresMkColumns, because if you use it in other contexts, you're likely to miss nonstandard constraint names declared in the persistent models files via `constraint=`

valuefindAlters
  1. :: [EntityDef]

    The list of all entity definitions that persistent is aware of.

  2. -> EntityDef

    The entity definition for the entity that we're working on.

  3. -> Column

    The column that we're searching for potential alterations for, derived from the Persistent EntityDef. That is: this is how we _want_ the column to look, and not necessarily how it actually looks in the database right now.

  4. -> [Column]

    The columns for this table, as they currently exist in the database.

  5. -> ([AlterColumn], [Column])
#