-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3ec299
commit a2da98f
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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"); |