Skip to content

Commit

Permalink
Add instruction and one of example on how to test or play with locally.
Browse files Browse the repository at this point in the history
  • Loading branch information
choestelus committed Oct 7, 2021
1 parent 638b600 commit ea73a9d
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions PLpgSQL/choestelus/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Code to Coffee with PL/pgSQL
---

## Prerequisite

1. postgresql (tested with postgresql 13)
2. any postgresql client (this example will use `psql`)

## Instructions

Using containerized postgres instance, this example comes with `docker-compose.yml` for setup local DB instance.

```sh
# make sure port 15432 is not in-use or change port exposed to
# available unused port
# consult with lsof manpage on macOS or ss/netstat for more info
# for example
# lsof -i :15432
# ss -tulpn | grep 15432

# 1. cd into directory with current readme, from root of git repository
cd $(git rev-parse --show-toplevel)/PLpgSQL/choestelus

# 2. bring up postgresql instance
docker-compose up -d

# 3. assuming psql is available in localhost, run migration ordered by name, descending
# log below command is output example.

psql -U postgres -h localhost -p 15432 -f ./1_init.sql

# $ psql -U postgres -h localhost -p 15432 -f 1_init.sql
# Password for user postgres: <refer to docker-compose.yml> which is 'coffee' in this example
# CREATE TABLE
# CREATE TABLE
# CREATE TABLE
# CREATE FUNCTION
# CREATE FUNCTION
# CREATE TRIGGER
# CREATE TRIGGER
# INSERT 0 1
# INSERT 0 1


# 4. run insert data migration to test migrated stored function and triggers
# log below command is output example.

psql -U postgres -h localhost -p 15432 -f ./2_consume_drink.sql

# Password for user postgres: <refer to docker-compose.yml> which is 'coffee' in this example
# psql:2_consume_drink.sql:1: NOTICE: can i haz java gulp gulp
# psql:2_consume_drink.sql:1: NOTICE: coding from drinked java
# INSERT 0 1
# INSERT 0 1
# INSERT 0 1
# psql:2_consume_drink.sql:4: NOTICE: can i haz mocha gulp gulp
# psql:2_consume_drink.sql:4: NOTICE: coding from drinked mocha
# INSERT 0 1

# 5. (optional) try to look around with changes made in affected tables
psql -U postgres -h localhost -p 15432 -d postgres -c 'select * from public.codes;'
psql -U postgres -h localhost -p 15432 -d postgres -c 'select * from public.drink_entities;'
```

0 comments on commit ea73a9d

Please sign in to comment.