Maintainer | Brandon Chinn <brandonchinn178@gmail.com> |
---|---|
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Defines a migration framework for the persistent library.
- type Version = Int
- type OperationPath = (Version, Version)
- (~>) :: Int -> Int -> OperationPath
- data Operation = Migrateable op => Operation {
- opPath :: OperationPath
- opOp :: op
- type Migration = [Operation]
- data MigrateBackend = MigrateBackend {
- createTable :: Bool -> CreateTable -> SqlPersistT IO [Text]
- dropTable :: DropTable -> SqlPersistT IO [Text]
- addColumn :: AddColumn -> SqlPersistT IO [Text]
- dropColumn :: DropColumn -> SqlPersistT IO [Text]
- class Show op => Migrateable op where
- newtype MigrateSettings = MigrateSettings {
- versionToLabel :: Version -> Maybe String
- defaultSettings :: MigrateSettings
- hasMigration :: Migration -> SqlPersistT IO Bool
- checkMigration :: Migration -> SqlPersistT IO ()
- data CreateTable = CreateTable {
- ctName :: Text
- ctSchema :: [Column]
- ctConstraints :: [TableConstraint]
- newtype DropTable = DropTable {}
- data AddColumn = AddColumn {}
- newtype DropColumn = DropColumn {}
- data RawOperation = RawOperation {}
- data NoOp = NoOp
- type ColumnIdentifier = (Text, Text)
- dotted :: ColumnIdentifier -> Text
- data Column = Column {}
- data ColumnProp
- data TableConstraint
- = PrimaryKey [Text]
- | Unique Text [Text]
Operation types
The version of a database. An operation migrates from the given version to another version.
The version must be increasing, such that the lowest version is the first version and the highest version is the most up-to-date version.
type OperationPath = (Version, Version) Source #
The path that an operation takes.
(~>) :: Int -> Int -> OperationPath Source #
An infix constructor for OperationPath
.
An operation that can be migrated.
Migrateable op => Operation | |
|
Migration types
data MigrateBackend Source #
The backend to migrate with.
MigrateBackend | |
|
class Show op => Migrateable op where Source #
The type class for data types that can be migrated.
validateOperation :: op -> Either String () Source #
Validate any checks for the given operation.
getMigrationText :: MigrateBackend -> op -> SqlPersistT IO [Text] Source #
Get the SQL queries to run the migration.
Migration functions
newtype MigrateSettings Source #
Settings to customize migration steps.
MigrateSettings | |
|
defaultSettings :: MigrateSettings Source #
Default migration settings.
hasMigration :: Migration -> SqlPersistT IO Bool Source #
True if the persistent library detects more migrations unaccounted for.
checkMigration :: Migration -> SqlPersistT IO () Source #
Fails if the persistent library detects more migrations unaccounted for.
Core operations
data CreateTable Source #
An operation to create a table according to the specified schema.
CreateTable | |
|
An operation to drop the given table.
An operation to add the given column to an existing table.
newtype DropColumn Source #
An operation to drop the given column to an existing table.
data RawOperation Source #
A custom operation that can be defined manually.
RawOperations should primarily use rawSql
and rawExecute
from the persistent library. If the
operation depends on the backend being run, query connRDBMS
from the SqlBackend
:
asks connRDBMS >>= case "sqlite" -> ... _ -> return ()
Auxiliary types
type ColumnIdentifier = (Text, Text) Source #
A column identifier, table.column
dotted :: ColumnIdentifier -> Text Source #
Make a ColumnIdentifier displayable.
The definition for a Column in a SQL database.
data ColumnProp Source #
A property for a Column
.
NotNull | Makes a column non-nullable (defaults to nullable) |
References ColumnIdentifier | Mark this column as a foreign key to the given column |
AutoIncrement | Makes a column auto-incrementing |
data TableConstraint Source #
Table constraints in a CREATE query.
PrimaryKey [Text] | PRIMARY KEY (col1, col2, ...) |
Unique Text [Text] | CONSTRAINT name UNIQUE (col1, col2, ...) |