groundhog-0.7.0.3: Type-safe datatype-database mapping library.

Safe HaskellNone
LanguageHaskell98

Database.Groundhog.Generic.Migration

Description

This helper module is intended for use by the backend creators

Synopsis

Documentation

type QualifiedName = (Maybe String, String) Source

Schema-qualified name of a table of another database object

data TableInfo Source

Constructors

TableInfo 

Fields

tableColumns :: [Column]
 
tableUniques :: [UniqueDefInfo]
 
tableReferences :: [(Maybe String, Reference)]

constraint name and reference

Instances

type UniqueDefInfo = UniqueDef' String (Either String String) Source

Either column name or expression

data AlterDB Source

Constructors

AddTable String 
AlterTable QualifiedName String TableInfo TableInfo [AlterTable]

Qualified table name, create statement, structure of table from DB, structure of table from datatype, alters

DropTrigger QualifiedName QualifiedName

Qualified trigger name, qualified table name

AddTriggerOnDelete QualifiedName QualifiedName String

Qualified trigger name, qualified table name, body

AddTriggerOnUpdate QualifiedName QualifiedName (Maybe String) String

Qualified trigger name, qualified table name, field name, body

CreateOrReplaceFunction String

Statement which creates the function

DropFunction QualifiedName

Qualified function name

CreateSchema String Bool

Schema name, if not exists

Instances

class (Applicative m, Monad m) => SchemaAnalyzer m where Source

Methods

schemaExists Source

Arguments

:: String

Schema name

-> m Bool 

getCurrentSchema :: m (Maybe String) Source

listTables Source

Arguments

:: Maybe String

Schema name

-> m [String] 

listTableTriggers Source

Arguments

:: QualifiedName

Qualified table name

-> m [String] 

analyzeTable Source

Arguments

:: QualifiedName

Qualified table name

-> m (Maybe TableInfo) 

analyzeTrigger Source

Arguments

:: QualifiedName

Qualified trigger name

-> m (Maybe String) 

analyzeFunction Source

Arguments

:: QualifiedName

Qualified function name

-> m (Maybe (Maybe [DbTypePrimitive], Maybe DbTypePrimitive, String))

Argument types, return type, and body

getMigrationPack :: m (MigrationPack m) Source

migrateRecursively Source

Arguments

:: (PersistBackend m, PersistEntity v) 
=> (String -> m SingleMigration)

migrate schema

-> (EntityDef -> m SingleMigration)

migrate entity

-> (DbType -> m SingleMigration)

migrate list

-> v

initial entity

-> Migration m 

Create migration for a given entity and all entities it depends on. The stateful Map is used to avoid duplicate migrations when an entity type occurs several times in a datatype

getAlters Source

Arguments

:: MigrationPack m 
-> TableInfo

From database

-> TableInfo

From datatype

-> [AlterTable]