forked from haskell-beam/beam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example applies migration to real Postgres instance
- Loading branch information
1 parent
13065ad
commit 9c1c872
Showing
4 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module RunMigration where | ||
|
||
import Prelude | ||
import Database.PostgreSQL.Simple (connect, close, ConnectInfo(..)) | ||
import Pagila.Schema (migrateDB) | ||
|
||
-- https://hackage.haskell.org/package/postgresql-simple-0.7.0.0/docs/Database-PostgreSQL-Simple.html#t:ConnectInfo | ||
connInfo :: ConnectInfo | ||
connInfo = ConnectInfo "localhost" (read "5432") "postgres" "foo" "postgres" | ||
|
||
main :: IO () | ||
main = do | ||
putStrLn "Running migration..." | ||
c <- connect connInfo | ||
|
||
_ <- migrateDB c | ||
|
||
close c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,30 @@ | ||
# Pagila example | ||
|
||
`cabal run` to see rendering of Postgres migration. | ||
There are two executables: | ||
|
||
### 1. `cabal run` | ||
`cabal run` to see rendering of Postgres migration. This converts the Haskell to SQL statements and prints these to the console. | ||
|
||
### 2. Destructive: apply migration to Postgres instance | ||
|
||
Hard-code your Postgres connection parameters into `app/RunMigration.hs` `connInfo`. | ||
Then `cabal run pagila-migration`. *This will overwrite your Postgres data*. | ||
|
||
The result will be the Pagila database schema in your Postgres instance: | ||
``` | ||
postgres=# \d | ||
List of relations | ||
Schema | Name | Type | Owner | ||
--------+-------------------------------+----------+---------- | ||
public | actor | table | postgres | ||
public | actor_actor_id_seq | sequence | postgres | ||
public | address | table | postgres | ||
public | address_address_id_seq | sequence | postgres | ||
public | beam_migration | table | postgres | ||
public | beam_version | table | postgres | ||
public | category | table | postgres | ||
. | ||
. | ||
. | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters