Maintainer | Brandon Chinn <brandonchinn178@gmail.com> |
---|---|
Stability | experimental |
Portability | portable |
Safe Haskell | None |
Language | Haskell2010 |
Database.Persist.Migration.Internal
Description
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
- getCurrVersion :: MonadIO m => MigrateBackend -> SqlPersistT m (Maybe Version)
- getMigratePlan :: Migration -> Maybe Version -> Either (Version, Version) Migration
- getFirstVersion :: Migration -> Version
- getLatestVersion :: Migration -> Version
- newtype MigrateSettings = MigrateSettings {
- versionToLabel :: Version -> Maybe String
- defaultSettings :: MigrateSettings
- validateMigration :: Migration -> Either String ()
- runMigration :: MonadIO m => MigrateBackend -> MigrateSettings -> Migration -> SqlPersistT m ()
- getMigration :: MonadIO m => MigrateBackend -> MigrateSettings -> Migration -> SqlPersistT m [Text]
- rawExecute' :: MonadIO m => [Text] -> SqlPersistT m ()
- 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 {}
- validateColumn :: Column -> Either String ()
- data ColumnProp
- data TableConstraint
- = PrimaryKey [Text]
- | Unique Text [Text]
- getConstraintColumns :: TableConstraint -> [Text]
Documentation
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.
Constructors
Migrateable op => Operation | |
Fields
|
data MigrateBackend Source #
The backend to migrate with.
Constructors
MigrateBackend | |
Fields
|
class Show op => Migrateable op where Source #
The type class for data types that can be migrated.
Minimal complete definition
Methods
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.
getCurrVersion :: MonadIO m => MigrateBackend -> SqlPersistT m (Maybe Version) Source #
Get the current version of the database, or Nothing if none exists.
getMigratePlan :: Migration -> Maybe Version -> Either (Version, Version) Migration Source #
Get the migration plan given the current state of the database.
getFirstVersion :: Migration -> Version Source #
Get the first version in the given migration.
getLatestVersion :: Migration -> Version Source #
Get the most up-to-date version in the given migration.
newtype MigrateSettings Source #
Settings to customize migration steps.
Constructors
MigrateSettings | |
Fields
|
defaultSettings :: MigrateSettings Source #
Default migration settings.
runMigration :: MonadIO m => MigrateBackend -> MigrateSettings -> Migration -> SqlPersistT m () Source #
Run the given migration. After successful completion, saves the migration to the database.
getMigration :: MonadIO m => MigrateBackend -> MigrateSettings -> Migration -> SqlPersistT m [Text] Source #
Get the SQL queries for the given migration.
rawExecute' :: MonadIO m => [Text] -> SqlPersistT m () Source #
Execute the given SQL strings.
data CreateTable Source #
An operation to create a table according to the specified schema.
Constructors
CreateTable | |
Fields
|
Instances
An operation to drop the given table.
An operation to add the given column to an existing table.
Constructors
AddColumn | |
newtype DropColumn Source #
An operation to drop the given column to an existing table.
Constructors
DropColumn | |
Fields |
Instances
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 ()
Constructors
RawOperation | |
Instances
A noop operation.
Constructors
NoOp |
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
.
Constructors
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 |
Instances
data TableConstraint Source #
Table constraints in a CREATE query.
Constructors
PrimaryKey [Text] | PRIMARY KEY (col1, col2, ...) |
Unique Text [Text] | CONSTRAINT name UNIQUE (col1, col2, ...) |
Instances
getConstraintColumns :: TableConstraint -> [Text] Source #
Get the columns defined in the given TableConstraint.