beam
beam copied to clipboard
Postgres examples
This PR adds two executables to the Postgres Pagila example.
cabal runprints the migration to the screen to help understanding.
$ cabal run
Migration steps:
Initial commit
Add film actor, inventory, rental table
-------------
For each migration step, the sequence of SQL scripts:
Initial commit
SQL command type: PgCommandTypeDdl
SQL script:
CREATE TABLE "actor" ("actor_id" SERIAL, "first_name" VARCHAR(45) NOT NULL, "last_name" VARCHAR(45) NOT NULL UNIQUE, "last_update" TIMESTAMP DEFAULT NOW() NOT NULL, PRIMARY KEY("actor_id"))
SQL command type: PgCommandTypeDdl
SQL script:
CREATE TABLE "address" ("address_id" SMALLSERIAL, "address" VARCHAR(50) NOT NULL, "address2" VARCHAR(50), "district" VARCHAR(20) NOT NULL, "city_id" SMALLINT NOT NULL, "postal_code" VARCHAR(10), "phone" VARCHAR(20) NOT NULL, "last_update" TIMESTAMP DEFAULT NOW() NOT NULL, PRIMARY KEY("address_id"))
SQL command type: PgCommandTypeDdl
SQL script:
CREATE TABLE "city" ("city_id" SMALLINT, "city" VARCHAR(50) NOT NULL, "country_id" SMALLINT NOT NULL, "last_update" TIMESTAMP DEFAULT NOW() NOT NULL, PRIMARY KEY("city_id"))
SQL command type: PgCommandTypeDdl
SQL script:
CREATE TABLE "country" ("country_id" SMALLINT, "country" VARCHAR(50) NOT NULL, "last_update" TIMESTAMP DEFAULT NOW() NOT NULL, PRIMARY KEY("country_id"))
.
.
.
.
cabal run pagila-migrationThis applies the migration to a Postgres instance. It will overwrite the data in this Postgres instance. This is documented: https://github.com/haskell-beam/beam/blob/867fc8ae1ebbcc3b5832300a7492516902af3206/beam-postgres/examples/readme.md#pagila-example
The migration example will generate countries and staff and insert them into the database after migration V0001. Then V0002 migration is applied and the staff are migrated to V0002.NewStaff.