Skip to content

Commit

Permalink
ez commits for green bar
Browse files Browse the repository at this point in the history
  • Loading branch information
zachrundle committed Aug 29, 2024
1 parent a2da98f commit c5dfb6c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 42 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
postgres:
docker run --name postgres -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_PASSWORD=<password> -d postgres:latest

createdb:
docker exec -it postgres createdb --username=root --owner=root simple_bank

dropdb:
docker exec -it postgres drobdb simple_bank

.PHONY: postgres createdb dropdb
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# go-playground
Go code for public personal projects

## project ideas
1. card counting app
2. some terminal based game?
3 changes: 3 additions & 0 deletions db/migration/000001_init_schema.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP TABLE IF EXISTS entries;
DROP TABLE IF EXISTS transfers;
DROP TABLE IF EXISTS accounts;
43 changes: 43 additions & 0 deletions db/migration/000001_init_schema.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
CREATE TABLE "accounts" (
"id" bigserial PRIMARY KEY,
"owner" varchar NOT NULL,
"balance" bigint NOT NULL,
"currency" varchar NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);

CREATE TABLE "entries" (
"id" bigserial PRIMARY KEY,
"account_id" bigint,
"amount" bigint NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);

CREATE TABLE "transfers" (
"id" bigserial PRIMARY KEY,
"from_account_id" bigint,
"to_account_id" bigint,
"amount" bigint NOT NULL,
"created_at" timestamptz NOT NULL DEFAULT (now())
);

CREATE INDEX ON "accounts" ("owner");

CREATE INDEX ON "entries" ("account_id");

CREATE INDEX ON "transfers" ("from_account_id");

CREATE INDEX ON "transfers" ("to_account_id");

CREATE INDEX ON "transfers" ("from_account_id", "to_account_id");

COMMENT ON COLUMN "entries"."amount" IS 'can be negative or positive';

COMMENT ON COLUMN "transfers"."amount" IS 'must be positive';

ALTER TABLE "entries" ADD FOREIGN KEY ("account_id") REFERENCES "accounts" ("id");

ALTER TABLE "transfers" ADD FOREIGN KEY ("from_account_id") REFERENCES "accounts" ("id");

ALTER TABLE "transfers" ADD FOREIGN KEY ("to_account_id") REFERENCES "accounts" ("id");

42 changes: 0 additions & 42 deletions db/simple bank.sql

This file was deleted.

0 comments on commit c5dfb6c

Please sign in to comment.