-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Manual migrations for the persistent library -- -- Manual migrations for the persistent library. @package persistent-migration @version 0.0.1 -- | Define functions useful for data constructors. module Database.Persist.Migration.Utils.Data -- | Return True if the given list has duplicate constructors. hasDuplicateConstrs :: Data a => [a] -> Bool -- | Define functions useful for compiling a plan of migration. module Database.Persist.Migration.Utils.Plan -- | Given a list of edges and their data and a start/end node, return the -- shortest path. -- -- Errors if no path is found. getPath :: [(Edge, a)] -> Node -> Node -> Maybe [a] -- | Defines a migration framework for the persistent library. module Database.Persist.Migration.Internal -- | 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 Version = Int -- | The path that an operation takes. type OperationPath = (Version, Version) -- | An infix constructor for OperationPath. (~>) :: Int -> Int -> OperationPath -- | An operation that can be migrated. data Operation Operation :: OperationPath -> op -> Operation [opPath] :: Operation -> OperationPath [opOp] :: Operation -> op -- | A migration is simply a list of operations. type Migration = [Operation] -- | The backend to migrate with. data MigrateBackend MigrateBackend :: (Bool -> CreateTable -> SqlPersistT IO [Text]) -> (DropTable -> SqlPersistT IO [Text]) -> (AddColumn -> SqlPersistT IO [Text]) -> (DropColumn -> SqlPersistT IO [Text]) -> MigrateBackend -- | create a table (True = IF NOT EXISTS) [createTable] :: MigrateBackend -> Bool -> CreateTable -> SqlPersistT IO [Text] [dropTable] :: MigrateBackend -> DropTable -> SqlPersistT IO [Text] [addColumn] :: MigrateBackend -> AddColumn -> SqlPersistT IO [Text] [dropColumn] :: MigrateBackend -> DropColumn -> SqlPersistT IO [Text] -- | The type class for data types that can be migrated. class Show op => Migrateable op -- | Validate any checks for the given operation. validateOperation :: Migrateable op => op -> Either String () -- | Get the SQL queries to run the migration. getMigrationText :: Migrateable op => MigrateBackend -> op -> SqlPersistT IO [Text] -- | Get the current version of the database, or Nothing if none exists. getCurrVersion :: MonadIO m => MigrateBackend -> SqlPersistT m (Maybe Version) -- | Get the migration plan given the current state of the database. getMigratePlan :: Migration -> Maybe Version -> Either (Version, Version) Migration -- | Get the first version in the given migration. getFirstVersion :: Migration -> Version -- | Get the most up-to-date version in the given migration. getLatestVersion :: Migration -> Version -- | Settings to customize migration steps. newtype MigrateSettings MigrateSettings :: (Version -> Maybe String) -> MigrateSettings -- | A function to optionally label certain versions [versionToLabel] :: MigrateSettings -> Version -> Maybe String -- | Default migration settings. defaultSettings :: MigrateSettings -- | Validate the given migration. validateMigration :: Migration -> Either String () -- | Run the given migration. After successful completion, saves the -- migration to the database. runMigration :: MonadIO m => MigrateBackend -> MigrateSettings -> Migration -> SqlPersistT m () -- | Get the SQL queries for the given migration. getMigration :: MonadIO m => MigrateBackend -> MigrateSettings -> Migration -> SqlPersistT m [Text] -- | Execute the given SQL strings. rawExecute' :: MonadIO m => [Text] -> SqlPersistT m () -- | An operation to create a table according to the specified schema. data CreateTable CreateTable :: Text -> [Column] -> [TableConstraint] -> CreateTable [ctName] :: CreateTable -> Text [ctSchema] :: CreateTable -> [Column] [ctConstraints] :: CreateTable -> [TableConstraint] -- | An operation to drop the given table. newtype DropTable DropTable :: Text -> DropTable [dtName] :: DropTable -> Text -- | An operation to add the given column to an existing table. data AddColumn AddColumn :: Text -> Column -> Maybe Text -> AddColumn [acTable] :: AddColumn -> Text [acColumn] :: AddColumn -> Column -- | The default for existing rows; required if the column is non-nullable [acDefault] :: AddColumn -> Maybe Text -- | An operation to drop the given column to an existing table. newtype DropColumn DropColumn :: ColumnIdentifier -> DropColumn [dcColumn] :: DropColumn -> ColumnIdentifier -- | 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 () --data RawOperation RawOperation :: Text -> SqlPersistT IO [Text] -> RawOperation [message] :: RawOperation -> Text [rawOp] :: RawOperation -> SqlPersistT IO [Text] -- | A noop operation. data NoOp NoOp :: NoOp -- | A column identifier, table.column type ColumnIdentifier = (Text, Text) -- | Make a ColumnIdentifier displayable. dotted :: ColumnIdentifier -> Text -- | The definition for a Column in a SQL database. data Column Column :: Text -> SqlType -> [ColumnProp] -> Column [colName] :: Column -> Text [colType] :: Column -> SqlType [colProps] :: Column -> [ColumnProp] -- | Validate a Column. validateColumn :: Column -> Either String () -- | A property for a Column. data ColumnProp -- | Makes a column non-nullable (defaults to nullable) NotNull :: ColumnProp -- | Mark this column as a foreign key to the given column References :: ColumnIdentifier -> ColumnProp -- | Makes a column auto-incrementing AutoIncrement :: ColumnProp -- | Table constraints in a CREATE query. data TableConstraint -- | PRIMARY KEY (col1, col2, ...) PrimaryKey :: [Text] -> TableConstraint -- | CONSTRAINT name UNIQUE (col1, col2, ...) Unique :: Text -> [Text] -> TableConstraint -- | Get the columns defined in the given TableConstraint. getConstraintColumns :: TableConstraint -> [Text] instance GHC.Show.Show Database.Persist.Migration.Internal.CreateTable instance Data.Data.Data Database.Persist.Migration.Internal.TableConstraint instance GHC.Show.Show Database.Persist.Migration.Internal.TableConstraint instance GHC.Show.Show Database.Persist.Migration.Internal.AddColumn instance GHC.Show.Show Database.Persist.Migration.Internal.Column instance Data.Data.Data Database.Persist.Migration.Internal.ColumnProp instance GHC.Classes.Eq Database.Persist.Migration.Internal.ColumnProp instance GHC.Show.Show Database.Persist.Migration.Internal.ColumnProp instance GHC.Show.Show Database.Persist.Migration.Internal.DropColumn instance GHC.Show.Show Database.Persist.Migration.Internal.NoOp instance GHC.Show.Show Database.Persist.Migration.Internal.DropTable instance GHC.Show.Show Database.Persist.Migration.Internal.Operation instance Database.Persist.Migration.Internal.Migrateable Database.Persist.Migration.Internal.CreateTable instance Database.Persist.Migration.Internal.Migrateable Database.Persist.Migration.Internal.DropTable instance Database.Persist.Migration.Internal.Migrateable Database.Persist.Migration.Internal.AddColumn instance Database.Persist.Migration.Internal.Migrateable Database.Persist.Migration.Internal.DropColumn instance Database.Persist.Migration.Internal.Migrateable Database.Persist.Migration.Internal.RawOperation instance Database.Persist.Migration.Internal.Migrateable Database.Persist.Migration.Internal.NoOp instance GHC.Show.Show Database.Persist.Migration.Internal.RawOperation -- | Defines a migration framework for the persistent library. module Database.Persist.Migration -- | 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 Version = Int -- | The path that an operation takes. type OperationPath = (Version, Version) -- | An infix constructor for OperationPath. (~>) :: Int -> Int -> OperationPath -- | An operation that can be migrated. data Operation Operation :: OperationPath -> op -> Operation [opPath] :: Operation -> OperationPath [opOp] :: Operation -> op -- | A migration is simply a list of operations. type Migration = [Operation] -- | The backend to migrate with. data MigrateBackend MigrateBackend :: (Bool -> CreateTable -> SqlPersistT IO [Text]) -> (DropTable -> SqlPersistT IO [Text]) -> (AddColumn -> SqlPersistT IO [Text]) -> (DropColumn -> SqlPersistT IO [Text]) -> MigrateBackend -- | create a table (True = IF NOT EXISTS) [createTable] :: MigrateBackend -> Bool -> CreateTable -> SqlPersistT IO [Text] [dropTable] :: MigrateBackend -> DropTable -> SqlPersistT IO [Text] [addColumn] :: MigrateBackend -> AddColumn -> SqlPersistT IO [Text] [dropColumn] :: MigrateBackend -> DropColumn -> SqlPersistT IO [Text] -- | The type class for data types that can be migrated. class Show op => Migrateable op -- | Validate any checks for the given operation. validateOperation :: Migrateable op => op -> Either String () -- | Get the SQL queries to run the migration. getMigrationText :: Migrateable op => MigrateBackend -> op -> SqlPersistT IO [Text] -- | Settings to customize migration steps. newtype MigrateSettings MigrateSettings :: (Version -> Maybe String) -> MigrateSettings -- | A function to optionally label certain versions [versionToLabel] :: MigrateSettings -> Version -> Maybe String -- | Default migration settings. defaultSettings :: MigrateSettings -- | True if the persistent library detects more migrations unaccounted -- for. hasMigration :: Migration -> SqlPersistT IO Bool -- | Fails if the persistent library detects more migrations unaccounted -- for. checkMigration :: Migration -> SqlPersistT IO () -- | An operation to create a table according to the specified schema. data CreateTable CreateTable :: Text -> [Column] -> [TableConstraint] -> CreateTable [ctName] :: CreateTable -> Text [ctSchema] :: CreateTable -> [Column] [ctConstraints] :: CreateTable -> [TableConstraint] -- | An operation to drop the given table. newtype DropTable DropTable :: Text -> DropTable [dtName] :: DropTable -> Text -- | An operation to add the given column to an existing table. data AddColumn AddColumn :: Text -> Column -> Maybe Text -> AddColumn [acTable] :: AddColumn -> Text [acColumn] :: AddColumn -> Column -- | The default for existing rows; required if the column is non-nullable [acDefault] :: AddColumn -> Maybe Text -- | An operation to drop the given column to an existing table. newtype DropColumn DropColumn :: ColumnIdentifier -> DropColumn [dcColumn] :: DropColumn -> ColumnIdentifier -- | 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 () --data RawOperation RawOperation :: Text -> SqlPersistT IO [Text] -> RawOperation [message] :: RawOperation -> Text [rawOp] :: RawOperation -> SqlPersistT IO [Text] -- | A noop operation. data NoOp NoOp :: NoOp -- | A column identifier, table.column type ColumnIdentifier = (Text, Text) -- | Make a ColumnIdentifier displayable. dotted :: ColumnIdentifier -> Text -- | The definition for a Column in a SQL database. data Column Column :: Text -> SqlType -> [ColumnProp] -> Column [colName] :: Column -> Text [colType] :: Column -> SqlType [colProps] :: Column -> [ColumnProp] -- | A property for a Column. data ColumnProp -- | Makes a column non-nullable (defaults to nullable) NotNull :: ColumnProp -- | Mark this column as a foreign key to the given column References :: ColumnIdentifier -> ColumnProp -- | Makes a column auto-incrementing AutoIncrement :: ColumnProp -- | Table constraints in a CREATE query. data TableConstraint -- | PRIMARY KEY (col1, col2, ...) PrimaryKey :: [Text] -> TableConstraint -- | CONSTRAINT name UNIQUE (col1, col2, ...) Unique :: Text -> [Text] -> TableConstraint -- | Defines helper functions for writing SQL queries. module Database.Persist.Migration.Utils.Sql -- | Split the given line by commas, ignoring commas within parentheses. -- --
-- commas "a,b,c" == ["a", "b", "c"] -- commas "a,b,c (d,e),z" == ["a", "b", "c (d,e)", "z"] -- commas "a,b,c (d,e,(f,g)),z" == ["a", "b", "c (d,e,(f,g))", "z"] --commas :: Text -> [Text] -- | Join the given Text with commas separating each item. uncommas :: [Text] -> Text -- | Quote the given Text. quote :: Text -> Text -- | Interpolate the given values into the SQL string. interpolate :: Text -> [PersistValue] -> Text -- | Defines the migration backend for PostgreSQL. module Database.Persist.Migration.Postgres -- | The migration backend for Postgres. backend :: MigrateBackend -- | Get a migration with the Postgres backend. getMigration :: MigrateSettings -> Migration -> SqlPersistT IO [Text] -- | Run a migration with the Postgres backend. runMigration :: MigrateSettings -> Migration -> SqlPersistT IO ()