beam-automigrate-0.1.0.1: DB migration library for beam, targeting Postgres.

Safe HaskellNone
LanguageHaskell2010

Database.Beam.AutoMigrate.Validity

Contents

Synopsis

Types

data Reason Source #

Constructors

TableDoesntExist TableName

The Table we were trying to edit didn't exist.

TableAlreadyExist TableName Table

The Table we were trying to create already existed.

TableConstraintAlreadyExist TableName TableConstraint

The TableConstraint we were trying to add already existed.

TableConstraintDoesntExist TableName TableConstraint

The TableConstraint we were trying to delete didn't exist.

ColumnDoesntExist ColumnName

The Column we were trying to edit didn't exist.

ColumnAlreadyExist ColumnName Column

The Column we were trying to add already existed.

ColumnTypeMismatch ColumnName Column ColumnType

The old type for the input Column didn't match the type contained in the Edit step.

ColumnConstraintAlreadyExist (Qualified ColumnName) ColumnConstraint

The ColumnConstraint we were trying to add already existed.

ColumnConstraintDoesntExist (Qualified ColumnName) ColumnConstraint

The ColumnConstraint we were trying to delete didn't exist.

EnumDoesntExist EnumerationName

The Enum we were trying to edit didn't exist.

EnumAlreadyExist EnumerationName Enumeration

The Enum we were trying to add already existed.

EnumInsertionPointDoesntExist EnumerationName Enumeration Text

The value in this Enum to be used to insert a new one before/after it didn't exist.

SequenceAlreadyExist SequenceName Sequence

The Sequence we were trying to add already existed.

SequenceDoesntExist SequenceName

The Sequence we were trying to edit didn't exist.

TableReferencesDeletedColumnInConstraint TableName (Qualified ColumnName) TableConstraint

This Table references a deleted Column in one of its TableConstraints.

ColumnReferencesNonExistingEnum (Qualified ColumnName) EnumerationName

This Column references an Enum which doesn't exist.

ColumnInPrimaryKeyCantBeNull (Qualified ColumnName)

This Column allows NULL values but it has been selected as a PRIMARY key.

ColumnsInFkAreNotUniqueOrPrimaryKeyFields TableName [Qualified ColumnName]

This Table has a ForeignKey constaint in it which references external columns which are either not unique or not fields of a PRIMARY KEY.

ColumnStillReferencesSequence SequenceName (Qualified ColumnName) 
NotAllColumnsExist TableName (Set ColumnName) (Set ColumnName)

This TableConstraint references one or more Columns which don't exist.

DeletedConstraintAffectsExternalTables (TableName, TableConstraint) (Qualified ColumnName, TableConstraint)

Deleting this TableConstraint would affect the selected external Columns and some external TableConstraints.

EnumContainsDuplicateValues EnumerationName [Text] 
Instances
Eq Reason Source # 
Instance details

Defined in Database.Beam.AutoMigrate.Validity

Methods

(==) :: Reason -> Reason -> Bool #

(/=) :: Reason -> Reason -> Bool #

Show Reason Source # 
Instance details

Defined in Database.Beam.AutoMigrate.Validity

Applying edits to a Schema

applyEdits :: [WithPriority Edit] -> Schema -> Either ApplyFailed Schema Source #

Tries to apply a list of edits to a Schema to generate a new one. Fails with an ApplyFailed error if the input list of Edits would generate an invalid Schema.

Validing a Schema

validateSchema :: Schema -> Either [ValidationFailed] () Source #

Validate a Schema, returning an error in case the validation didn't succeed. We never contemplate the case where any of the entities names are empty (i.e. the empty string) as that clearly indicates a bug in the library, not a user error that needs to be reported.

validateSchemaTables :: Schema -> Either [ValidationFailed] () Source #

A Table is not valid if: 1. Any of its Columns are not valid; 2. Any of its TableConstraints are not valid.

validateSchemaEnums :: Schema -> Either [ValidationFailed] () Source #

A Schema enum is considered always valid in this context except if it contains duplicate values.

validateTableConstraint :: Schema -> TableName -> Table -> TableConstraint -> Either ValidationFailed () Source #

Validate a TableConstraint, making sure referential integrity is not violated. A Table constraint is valid IFF: 1. For a PrimaryKey, all the referenced columns must exist in the Table; 2. For a Unique, all the referenced columns must exist in the Table; 3. For a ForeignKey, all the columns (both local and referenced) must exist; 4. For a ForeignKey, the referenced columns must all be UNIQUE or PRIMARY keys.

validateColumn :: Schema -> TableName -> (ColumnName, Column) -> Either [ValidationFailed] () Source #

Validate Column. NOTE(adn) For now in this context a Column is always considered valid, except if it references an Enum type which doesn't exist.