Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres examples #732

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

peterbecich
Copy link
Contributor

@peterbecich peterbecich commented Dec 14, 2024

This PR adds two executables to the Postgres Pagila example.

  1. cabal run prints 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")) 
.
.
.
.
  1. cabal run pagila-migration
    This 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.

@peterbecich peterbecich force-pushed the postgres-example-executable branch from 01c842e to 867fc8a Compare December 23, 2024 08:48
@peterbecich peterbecich changed the title Postgres example executable Postgres examples Dec 23, 2024
@LaurentRDC LaurentRDC self-requested a review December 24, 2024 19:00
@peterbecich peterbecich force-pushed the postgres-example-executable branch from bcdb53e to 43b43e9 Compare December 25, 2024 07:05
@peterbecich peterbecich force-pushed the postgres-example-executable branch 4 times, most recently from 4a41c8c to d2a78e4 Compare December 25, 2024 22:12
@peterbecich peterbecich force-pushed the postgres-example-executable branch from d2a78e4 to 4bd1773 Compare December 25, 2024 22:16
@peterbecich
Copy link
Contributor Author

@LaurentRDC , this PR makes the example schema usable. The user must provide the instance of Postgres to target.

It also generates random data to populate the database with rows. There is a safety check for the user before any change is applied to the database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant