persistent-migration-0.1.0: Manual migrations for the persistent library

MaintainerBrandon Chinn <brandonchinn178@gmail.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Database.Persist.Migration

Contents

Description

Defines a migration framework for the persistent library.

Synopsis

Documentation

hasMigration :: MonadIO m => Migration -> SqlPersistT m Bool Source #

True if the persistent library detects more migrations unaccounted for.

checkMigration :: MonadIO m => Migration -> SqlPersistT m () Source #

Fails if the persistent library detects more migrations unaccounted for.

Re-exports

newtype MigrateSettings Source #

Settings to customize migration steps.

Constructors

MigrateSettings 

Fields

defaultSettings :: MigrateSettings Source #

Default migration settings.

validateMigration :: Migration -> Either String () Source #

Validate the given migration.

data PersistValue #

A raw value which can be stored in any backend and can be marshalled to and from a PersistField.

Constructors

PersistText Text 
PersistByteString ByteString 
PersistInt64 Int64 
PersistDouble Double 
PersistRational Rational 
PersistBool Bool 
PersistDay Day 
PersistTimeOfDay TimeOfDay 
PersistUTCTime UTCTime 
PersistNull 
PersistList [PersistValue] 
PersistMap [(Text, PersistValue)] 
PersistObjectId ByteString

Intended especially for MongoDB backend

PersistDbSpecific ByteString

Using PersistDbSpecific allows you to use types specific to a particular backend For example, below is a simple example of the PostGIS geography type:

data Geo = Geo ByteString

instance PersistField Geo where
  toPersistValue (Geo t) = PersistDbSpecific t

  fromPersistValue (PersistDbSpecific t) = Right $ Geo $ Data.ByteString.concat ["'", t, "'"]
  fromPersistValue _ = Left "Geo values must be converted from PersistDbSpecific"

instance PersistFieldSql Geo where
  sqlType _ = SqlOther "GEOGRAPHY(POINT,4326)"

toPoint :: Double -> Double -> Geo
toPoint lat lon = Geo $ Data.ByteString.concat ["'POINT(", ps $ lon, " ", ps $ lat, ")'"]
  where ps = Data.Text.pack . show

If Foo has a geography field, we can then perform insertions like the following:

insert $ Foo (toPoint 44 44)
Instances
Eq PersistValue 
Instance details

Defined in Database.Persist.Types.Base

Data PersistValue # 
Instance details

Defined in Database.Persist.Migration.Operation.Types

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> PersistValue -> c PersistValue #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c PersistValue #

toConstr :: PersistValue -> Constr #

dataTypeOf :: PersistValue -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c PersistValue) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c PersistValue) #

gmapT :: (forall b. Data b => b -> b) -> PersistValue -> PersistValue #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> PersistValue -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> PersistValue -> r #

gmapQ :: (forall d. Data d => d -> u) -> PersistValue -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> PersistValue -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> PersistValue -> m PersistValue #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> PersistValue -> m PersistValue #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> PersistValue -> m PersistValue #

Ord PersistValue 
Instance details

Defined in Database.Persist.Types.Base

Read PersistValue 
Instance details

Defined in Database.Persist.Types.Base

Show PersistValue 
Instance details

Defined in Database.Persist.Types.Base

ToJSON PersistValue 
Instance details

Defined in Database.Persist.Types.Base

FromJSON PersistValue 
Instance details

Defined in Database.Persist.Types.Base

ToHttpApiData PersistValue 
Instance details

Defined in Database.Persist.Types.Base

FromHttpApiData PersistValue 
Instance details

Defined in Database.Persist.Types.Base

PathPiece PersistValue 
Instance details

Defined in Database.Persist.Types.Base

PersistFieldSql PersistValue 
Instance details

Defined in Database.Persist.Sql.Class

PersistField PersistValue 
Instance details

Defined in Database.Persist.Class.PersistField

data SqlType #

A SQL data type. Naming attempts to reflect the underlying Haskell datatypes, eg SqlString instead of SqlVarchar. Different SQL databases may have different translations for these types.

Constructors

SqlString 
SqlInt32 
SqlInt64 
SqlReal 
SqlNumeric Word32 Word32 
SqlBool 
SqlDay 
SqlTime 
SqlDayTime

Always uses UTC timezone

SqlBlob 
SqlOther Text

a backend-specific name