Returns a structured representation of all of the DB changes required to migrate the Entity from its current state in the database to the state described in Haskell.
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
- Packagepersistent-postgresql-2.14.3.0
- Exports44
- LanguageHaskell2010
- LicenceMIT
- SourceMigration.hs
Returns a structured representation of all of the DB changes required to migrate the listed entities from their current state in the database to the state described in Haskell. This function avoids N+1 queries, so if you have a lot of entities to migrate, it's much faster to use this rather than using migrateStructured in a loop.
Returns a structured representation of all of the DB changes required to migrate the Entity to the state described in Haskell, assuming it currently does not exist in the database.
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.
Constructors
Instances2Eq, Show
Eq SchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.MigrationShow SchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
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
EntityDoesNotExistThe table does not exist in the database
EntityExists ExistingEntitySchemaStateThe table does exist in the database
Instances2Eq, Show
Eq EntitySchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.MigrationShow EntitySchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
Information about an existing table in the database
Constructors
ExistingEntitySchemaStateessColumns :: 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
Eq ExistingEntitySchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.MigrationShow ExistingEntitySchemaStateDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
Query a database in order to assemble a SchemaState containing information about each of the entities in the given list. Every entity name in the input should be present in the returned Map.
Check for the existence of each of the input tables. The keys in the returned Map are exactly the entity names in the argument; True means the table exists.
Get all columns for the listed tables from the database, ignoring foreign key references (those are filled in later).
Get all constraints for the listed tables from the database, except for foreign keys and primary keys (those go in the Column data type)
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.
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.MigrationShow SafeToRemoveDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
Represents a change to a Postgres column in a DB statement.
Instances2Eq, Show
Eq AlterColumnDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.MigrationShow AlterColumnDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
Represents a change to a Postgres table in a DB statement.
Instances2Eq, Show
Eq AlterTableDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.MigrationShow AlterTableDefined in persistent-postgresql-2.14.3.0 · Database.Persist.Postgresql.Internal.Migration
Represents a change to a Postgres DB in a statement.
Create a table if it doesn't exist.
Postgres' default maximum identifier length in bytes (You can re-compile Postgres with a new limit, but I'm assuming that virtually noone does this). See https://www.postgresql.org/docs/11/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
Intelligent comparison of SQL types, to account for SqlInt32 vs SqlOther integer
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=`
Check if a column name is listed as the "safe to remove" in the entity list.
Get the references to be added to a table for the given column.
findAlters :: [EntityDef]The list of all entity definitions that persistent is aware of.
-> EntityDefThe entity definition for the entity that we're working on.
-> ColumnThe 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.
-> [Column]The columns for this table, as they currently exist in the database.
-> ([AlterColumn], [Column])