| Copyright | Flipstone Technology Partners 2023 |
|---|---|
| License | MIT |
| Stability | Stable |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Orville.PostgreSQL.Schema.ConstraintDefinition
Description
Since: 1.0.0.0
Synopsis
- data ConstraintDefinition
- uniqueConstraint :: NonEmpty FieldName -> ConstraintDefinition
- foreignKeyConstraint :: TableIdentifier -> NonEmpty ForeignReference -> ConstraintDefinition
- foreignKeyConstraintWithOptions :: TableIdentifier -> NonEmpty ForeignReference -> ForeignKeyOptions -> ConstraintDefinition
- data ForeignReference = ForeignReference {}
- foreignReference :: FieldName -> FieldName -> ForeignReference
- data ConstraintMigrationKey = ConstraintMigrationKey {
- constraintKeyType :: ConstraintKeyType
- constraintKeyColumns :: Maybe [FieldName]
- constraintKeyForeignTable :: Maybe TableIdentifier
- constraintKeyForeignColumns :: Maybe [FieldName]
- constraintKeyForeignKeyOnUpdateAction :: Maybe ForeignKeyAction
- constraintKeyForeignKeyOnDeleteAction :: Maybe ForeignKeyAction
- data ConstraintKeyType
- constraintMigrationKey :: ConstraintDefinition -> ConstraintMigrationKey
- constraintSqlExpr :: ConstraintDefinition -> TableConstraint
- data ForeignKeyAction
- = NoAction
- | Restrict
- | Cascade
- | SetNull
- | SetDefault
- data ForeignKeyOptions
- defaultForeignKeyOptions :: ForeignKeyOptions
- data TableConstraints
- emptyTableConstraints :: TableConstraints
- addConstraint :: ConstraintDefinition -> TableConstraints -> TableConstraints
- tableConstraintDefinitions :: TableConstraints -> [ConstraintDefinition]
- tableConstraintKeys :: TableConstraints -> Set ConstraintMigrationKey
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
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
Constructors
| ForeignReference | |
Fields | |
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
Constructors
Instances
data ConstraintKeyType Source #
The kind of constraint that is described by a ConstraintMigrationKey (e.g.
unique, foreign key).
Since: 1.0.0.0
Constructors
| UniqueConstraint | |
| ForeignKeyConstraint |
Instances
| Show ConstraintKeyType Source # | |
Defined in Orville.PostgreSQL.Schema.ConstraintDefinition Methods showsPrec :: Int -> ConstraintKeyType -> ShowS # show :: ConstraintKeyType -> String # showList :: [ConstraintKeyType] -> ShowS # | |
| Eq ConstraintKeyType Source # | |
Defined in Orville.PostgreSQL.Schema.ConstraintDefinition Methods (==) :: ConstraintKeyType -> ConstraintKeyType -> Bool # (/=) :: ConstraintKeyType -> ConstraintKeyType -> Bool # | |
| Ord ConstraintKeyType Source # | |
Defined in Orville.PostgreSQL.Schema.ConstraintDefinition Methods compare :: ConstraintKeyType -> ConstraintKeyType -> Ordering # (<) :: ConstraintKeyType -> ConstraintKeyType -> Bool # (<=) :: ConstraintKeyType -> ConstraintKeyType -> Bool # (>) :: ConstraintKeyType -> ConstraintKeyType -> Bool # (>=) :: ConstraintKeyType -> ConstraintKeyType -> Bool # max :: ConstraintKeyType -> ConstraintKeyType -> ConstraintKeyType # min :: ConstraintKeyType -> ConstraintKeyType -> ConstraintKeyType # | |
constraintMigrationKey :: ConstraintDefinition -> ConstraintMigrationKey Source #
Gets the ConstraintMigrationKey for the ConstraintDefinition.
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 ForeignKeyAction Source #
The actions that can be set on ForeignKeyOptions.
Since: 1.0.0.0
Constructors
| NoAction | |
| Restrict | |
| Cascade | |
| SetNull | |
| SetDefault |
Instances
| Show ForeignKeyAction Source # | |
Defined in Orville.PostgreSQL.Schema.ConstraintDefinition Methods showsPrec :: Int -> ForeignKeyAction -> ShowS # show :: ForeignKeyAction -> String # showList :: [ForeignKeyAction] -> ShowS # | |
| Eq ForeignKeyAction Source # | |
Defined in Orville.PostgreSQL.Schema.ConstraintDefinition Methods (==) :: ForeignKeyAction -> ForeignKeyAction -> Bool # (/=) :: ForeignKeyAction -> ForeignKeyAction -> Bool # | |
| Ord ForeignKeyAction Source # | |
Defined in Orville.PostgreSQL.Schema.ConstraintDefinition Methods compare :: ForeignKeyAction -> ForeignKeyAction -> Ordering # (<) :: ForeignKeyAction -> ForeignKeyAction -> Bool # (<=) :: ForeignKeyAction -> ForeignKeyAction -> Bool # (>) :: ForeignKeyAction -> ForeignKeyAction -> Bool # (>=) :: ForeignKeyAction -> ForeignKeyAction -> Bool # max :: ForeignKeyAction -> ForeignKeyAction -> ForeignKeyAction # min :: ForeignKeyAction -> ForeignKeyAction -> ForeignKeyAction # | |
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
defaultForeignKeyOptions :: ForeignKeyOptions Source #
The default ForeignKeyOptions, containing NoAction for both
foreignKeyOptionsOnUpdate and foreignKeyOptionsOnDelete.
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
Instances
| Monoid TableConstraints Source # | |
Defined in Orville.PostgreSQL.Schema.ConstraintDefinition Methods mappend :: TableConstraints -> TableConstraints -> TableConstraints # mconcat :: [TableConstraints] -> TableConstraints # | |
| Semigroup TableConstraints Source # | |
Defined in Orville.PostgreSQL.Schema.ConstraintDefinition Methods (<>) :: TableConstraints -> TableConstraints -> TableConstraints # sconcat :: NonEmpty TableConstraints -> TableConstraints # stimes :: Integral b => b -> TableConstraints -> TableConstraints # | |
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