orville-postgresql-1.0.0.0: A Haskell library for PostgreSQL
CopyrightFlipstone Technology Partners 2023
LicenseMIT
StabilityStable
Safe HaskellSafe-Inferred
LanguageHaskell2010

Orville.PostgreSQL.Schema.ConstraintDefinition

Description

Since: 1.0.0.0

Synopsis

Documentation

data ConstraintDefinition Source #

Defines a constraint that can be added to a TableDefinition. Use one of the constructor functions below (such as uniqueConstraint) to construct the constraint definition you wish to have and then use addTableConstraints to add them to your table definition. Orville will then add the constraint next time you run auto-migrations.

Since: 1.0.0.0

uniqueConstraint :: NonEmpty FieldName -> ConstraintDefinition Source #

Constructs a ConstraintDefinition for a UNIQUE constraint on the given columns.

Since: 1.0.0.0

foreignKeyConstraint Source #

Arguments

:: TableIdentifier

Identifier of the table referenced by the foreign key.

-> NonEmpty ForeignReference

The columns constrained by the foreign key and those that they reference in the foreign table.

-> ConstraintDefinition 

Builds a ConstraintDefinition for a FOREIGN KEY constraint.

Since: 1.0.0.0

foreignKeyConstraintWithOptions Source #

Arguments

:: TableIdentifier

Identifier of the table referenced by the foreign key.

-> NonEmpty ForeignReference

The columns constrained by the foreign key and those that they reference in the foreign table.

-> ForeignKeyOptions 
-> ConstraintDefinition 

Builds a ConstraintDefinition for a FOREIGN KEY constraint, with ON UPDATE and ON DELETE actions.

Since: 1.0.0.0

data ForeignReference Source #

A ForeignReference represents one part of a foreign key. The entire foreign key may comprise multiple columns. The ForeignReference defines a single column in the key and which column it references in the foreign table.

Since: 1.0.0.0

foreignReference Source #

Arguments

:: FieldName

The name of the field in the table with the constraint.

-> FieldName

The name of the field in the foreign table that the local field references.

-> ForeignReference 

Constructs a ForeignReference.

Since: 1.0.0.0

data ConstraintMigrationKey Source #

The key used by Orville to determine whether a constraint should be added to a table when performing auto-migrations. For most use cases, the constructor functions that build a ConstraintDefinition will create this automatically for you.

Since: 1.0.0.0

constraintSqlExpr :: ConstraintDefinition -> TableConstraint Source #

Gets the SQL expression that will be used to add the constraint to the table.

Since: 1.0.0.0

data ForeignKeyOptions Source #

Defines the options for a foreign key constraint. To construct ForeignKeyOptions, perform a record update on defaultForeignKeyOptions.

Since: 1.0.0.0

data TableConstraints Source #

A collection of constraints to be added to a table. This collection is indexed by ConstraintMigrationKey. If multiple constraints with the same ConstraintMigrationKey are added, the most recently-added one will be kept and the previous one dropped.

Since: 1.0.0.0

emptyTableConstraints :: TableConstraints Source #

Constructs an empty TableConstraints.

Since: 1.0.0.0

addConstraint :: ConstraintDefinition -> TableConstraints -> TableConstraints Source #

Adds a ConstraintDefinition to an existing TableConstraints. If a constraint already exists with the same ConstraintMigrationKey, it is replaced with the new constraint.

Since: 1.0.0.0

tableConstraintDefinitions :: TableConstraints -> [ConstraintDefinition] Source #

Gets the list of ConstraintDefinitions that have been added to the TableConstraints.

Since: 1.0.0.0

tableConstraintKeys :: TableConstraints -> Set ConstraintMigrationKey Source #

Gets the list of ConstraintDefinitions that have been added to the TableConstraints.

Since: 1.0.0.0