on dev help sign in
migration docs
380dd16Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+20−4
@@ -8,8 +8,8 @@ Stability: experimental
8This module defines a `Migration` type to safely
8This module defines a `Migration` type to safely
9change the schema of your database over time. Let's see an example!
9change the schema of your database over time. Let's see an example!
10
10
11−>>> :set -XDataKinds -XDeriveGeneric -XOverloadedLabels
11+>>> :set -XDataKinds -XOverloadedLabels
12−>>> :set -XOverloadedStrings -XTypeApplications -XTypeOperators
12+>>> :set -XOverloadedStrings -XFlexibleContexts -XTypeOperators
13>>> :{
13>>> :{
14type UsersTable =
14type UsersTable =
15 '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
15 '[ "pk_users" ::: 'PrimaryKey '["id"] ] :=>
@@ -61,10 +61,26 @@ let
61 }
61 }
62:}
62:}
63
63
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+
64>>> let migration = makeUsers :>> makeEmails :>> Done
75>>> let migration = makeUsers :>> makeEmails :>> Done
76+>>> :{
65−>>> withConnection "host=localhost port=5432 dbname=exampledb" (migrateUp migration)
77+withConnection "host=localhost port=5432 dbname=exampledb" $
78+ migrateUp migration
79+ & pqThen numSteps
80+ & pqThen (migrateDown migration)
81+:}
66NOTICE: relation "migration" already exists, skipping
82NOTICE: relation "migration" already exists, skipping
67−>>> withConnection "host=localhost port=5432 dbname=exampledb" (migrateDown migration)
83+Row 2
68NOTICE: relation "migration" already exists, skipping
84NOTICE: relation "migration" already exists, skipping
69-}
85-}
70
86