From c5dfb6c2ffccaa9f740d219c3b3b26a081e37ead Mon Sep 17 00:00:00 2001 From: cybershady Date: Wed, 28 Aug 2024 21:57:44 -0600 Subject: [PATCH] ez commits for green bar --- Makefile | 10 ++++++ README.md | 4 +++ db/migration/000001_init_schema.down.sql | 3 ++ db/migration/000001_init_schema.up.sql | 43 ++++++++++++++++++++++++ db/simple bank.sql | 42 ----------------------- 5 files changed, 60 insertions(+), 42 deletions(-) create mode 100644 Makefile delete mode 100644 db/simple bank.sql diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6b1af42 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +postgres: + docker run --name postgres -p 5432:5432 -e POSTGRES_USER=root -e POSTGRES_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 diff --git a/README.md b/README.md index 1314b22..a297e93 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # go-playground Go code for public personal projects + +## project ideas +1. card counting app +2. some terminal based game? diff --git a/db/migration/000001_init_schema.down.sql b/db/migration/000001_init_schema.down.sql index e69de29..db43f93 100644 --- a/db/migration/000001_init_schema.down.sql +++ b/db/migration/000001_init_schema.down.sql @@ -0,0 +1,3 @@ +DROP TABLE IF EXISTS entries; +DROP TABLE IF EXISTS transfers; +DROP TABLE IF EXISTS accounts; diff --git a/db/migration/000001_init_schema.up.sql b/db/migration/000001_init_schema.up.sql index e69de29..f7949cd 100644 --- a/db/migration/000001_init_schema.up.sql +++ b/db/migration/000001_init_schema.up.sql @@ -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"); + diff --git a/db/simple bank.sql b/db/simple bank.sql deleted file mode 100644 index d6522a7..0000000 --- a/db/simple bank.sql +++ /dev/null @@ -1,42 +0,0 @@ -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");