packages feed

drifter-postgresql 0.0.1 → 0.0.2

raw patch · 5 files changed

+83/−7 lines, 5 filesdep ~basedep ~drifterdep ~postgresql-simplePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base, drifter, postgresql-simple

API changes (from Hackage documentation)

- Drifter.PostgreSQL: histDescription :: ChangeHistory -> Maybe Description
- Drifter.PostgreSQL: histId :: ChangeHistory -> ChangeId
- Drifter.PostgreSQL: histName :: ChangeHistory -> ChangeName
- Drifter.PostgreSQL: histTime :: ChangeHistory -> UTCTime
- Drifter.PostgreSQL: instance Drifter PGMigration
- Drifter.PostgreSQL: instance Eq ChangeHistory
- Drifter.PostgreSQL: instance Eq ChangeId
- Drifter.PostgreSQL: instance FromField ChangeId
- Drifter.PostgreSQL: instance FromRow ChangeHistory
- Drifter.PostgreSQL: instance Ord ChangeHistory
- Drifter.PostgreSQL: instance Ord ChangeId
- Drifter.PostgreSQL: instance Show ChangeHistory
- Drifter.PostgreSQL: instance Show ChangeId
+ Drifter.PostgreSQL: [histDescription] :: ChangeHistory -> Maybe Description
+ Drifter.PostgreSQL: [histId] :: ChangeHistory -> ChangeId
+ Drifter.PostgreSQL: [histName] :: ChangeHistory -> ChangeName
+ Drifter.PostgreSQL: [histTime] :: ChangeHistory -> UTCTime
+ Drifter.PostgreSQL: instance Database.PostgreSQL.Simple.FromField.FromField Drifter.PostgreSQL.ChangeId
+ Drifter.PostgreSQL: instance Database.PostgreSQL.Simple.FromRow.FromRow Drifter.PostgreSQL.ChangeHistory
+ Drifter.PostgreSQL: instance Drifter.Graph.Drifter Drifter.PostgreSQL.PGMigration
+ Drifter.PostgreSQL: instance GHC.Classes.Eq Drifter.PostgreSQL.ChangeHistory
+ Drifter.PostgreSQL: instance GHC.Classes.Eq Drifter.PostgreSQL.ChangeId
+ Drifter.PostgreSQL: instance GHC.Classes.Ord Drifter.PostgreSQL.ChangeHistory
+ Drifter.PostgreSQL: instance GHC.Classes.Ord Drifter.PostgreSQL.ChangeId
+ Drifter.PostgreSQL: instance GHC.Show.Show Drifter.PostgreSQL.ChangeHistory
+ Drifter.PostgreSQL: instance GHC.Show.Show Drifter.PostgreSQL.ChangeId

Files

README.md view
@@ -1,3 +1,8 @@ # drifter-postgresql  PostgreSQL support for the drifter schema migration tool+++# Examples++See the `examples` directory for an example of how to use drifter-postgresql.
changelog.md view
@@ -0,0 +1,4 @@+0.0.2+* Loosen bounds+0.0.1+* Initial release
drifter-postgresql.cabal view
@@ -1,7 +1,9 @@ name:                drifter-postgresql-version:             0.0.1+version:             0.0.2 synopsis:            PostgreSQL support for the drifter schema migration tool-description:         Support for postgresql-simple Query migrations as well as arbitrary Haskell IO functions.+description:         Support for postgresql-simple Query migrations as well as+                     arbitrary Haskell IO functions. Be sure to check the+                     examples dir for a usage example. license:             MIT license-file:        LICENSE author:              Michael Xavier@@ -13,6 +15,8 @@ extra-source-files:   README.md   changelog.md+  examples/Example.hs+  test/Main.hs  flag lib-Werror   default: False@@ -20,9 +24,9 @@  library   exposed-modules:   Drifter.PostgreSQL-  build-depends:       base >=4.5 && <4.9-                     , postgresql-simple >= 0.2 && < 0.5-                     , drifter >= 0.2 && < 0.3+  build-depends:       base >=4.5 && <5+                     , postgresql-simple >= 0.2+                     , drifter >= 0.2                      , time                      , either                      , mtl
+ examples/Example.hs view
@@ -0,0 +1,62 @@+{-# LANGUAGE OverloadedStrings #-}+module Main+    ( main+    ) where+++-------------------------------------------------------------------------------+import           Control.Exception+import           Data.Monoid+import           Database.PostgreSQL.Simple+import           Drifter                    (Change (..), ChangeName (..),+                                             changeSequence)+import           Drifter.PostgreSQL         (Method (..), PGMigration (..),+                                             runMigrations)+-------------------------------------------------------------------------------+++main :: IO ()+main = bracket (connect defaultConnectInfo) close $ \conn -> do+  either error return =<< runMigrations conn changes+++-------------------------------------------------------------------------------+changes :: [Change PGMigration]+changes = changeSequence [ createTable+                         , addIndexes+                         , fireMissiles+                         ]+++-------------------------------------------------------------------------------+createTable :: Change PGMigration+createTable = Change { changeName = ChangeName "create table"+                     , changeDescription = Just "create some tables"+                     -- we'll have changeSequence sort out our dependencies+                     , changeDependencies = []+                     -- Query is a monoid, we can 'mappend' or even 'mconcat' them+                     , changeMethod = MigrationQuery (q1 <> q2)+                     }+  where q1 = "CREATE TABLE foo ( name pgtext );"+        q2 = "CREATE TABLE bar ( name pgtext );"+++-------------------------------------------------------------------------------+addIndexes :: Change PGMigration+addIndexes = Change { changeName = ChangeName "add indexes"+                    , changeDescription = Just "add some indexes"+                    , changeDependencies = []+                    , changeMethod = MigrationQuery q+                    }+  where q = "CREATE UNIQUE INDEX foo_name ON foo ( name );"+++-------------------------------------------------------------------------------+fireMissiles :: Change PGMigration+fireMissiles = Change { changeName = ChangeName "fire missiles"+                      , changeDescription = Just "a migration that isn't a query"+                      , changeDependencies = []+                      , changeMethod = MigrationCode doEvil+                      }+  where doEvil :: Connection -> IO (Either String ())+        doEvil _ = error "boom!"
src/Drifter/PostgreSQL.hs view
@@ -109,7 +109,7 @@ findNext [] cs = return cs findNext (h:hs) (c:cs)   | (histName h) == (changeName c) = do-    putStrLn $ "Skipping: " ++ show (changeName c)+    putStrLn $ "Skipping: " ++ show (changeNameText (changeName c))     findNext hs cs   | otherwise = return (c:cs) findNext _ _ = do@@ -170,6 +170,7 @@  ------------------------------------------------------------------------------- -- | Check the schema_migrations table for all the migrations that--- have previously run.+-- have previously run. This is run internally by 'runMigrations' to+-- determine which migrations to run. getChangeHistory :: Connection -> IO [ChangeHistory] getChangeHistory conn = query_ conn changeHistoryQ