@@ -8,8 +8,8 @@ Stability: experimental
88This module defines a `Migration` type to safely
99change the schema of your database over time. Let's see an example!
1010
11−>>> :set -XDataKinds -XDeriveGeneric -XOverloadedLabels
12−>>> :set -XOverloadedStrings -XTypeApplications -XTypeOperators
11+>>> :set -XDataKinds -XOverloadedLabels
12+>>> :set -XOverloadedStrings -XFlexibleContexts -XTypeOperators
1313>>> :{
1414type UsersTable =
1515 '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
@@ -61,10 +61,26 @@ let
6161 }
6262:}
6363
64+>>> :{
65+let
66+ numSteps
67+ :: Has "migration" schema MigrationTable
68+ => PQ schema schema IO ()
69+ numSteps = do
70+ result <- runQuery (selectStar (from (table (#migration `As` #m))))
71+ RowNumber num <- ntuples result
72+ liftBase $ print num
73+:}
74+
6475>>> let migration = makeUsers :>> makeEmails :>> Done
65−>>> withConnection "host=localhost port=5432 dbname=exampledb" (migrateUp migration)
76+>>> :{
77+withConnection "host=localhost port=5432 dbname=exampledb" $
78+ migrateUp migration
79+ & pqThen numSteps
80+ & pqThen (migrateDown migration)
81+:}
6682NOTICE: relation "migration" already exists, skipping
67−>>> withConnection "host=localhost port=5432 dbname=exampledb" (migrateDown migration)
83+Row 2
6884NOTICE: relation "migration" already exists, skipping
6985-}
7086