Skip to content

Commit 4ebc14f

Browse files
keyvjinkeyviKavikaPalletenne
authored
Mm1/setup dir (#40)
* cleaned up mm repo * added how to use to readme * kevin/improve bashrc a lil bit * added more colours to terminal * fixed linting * protobuffs * stubbed out money module routes * added stuff to money module dir * Revert "added stuff to money module dir" This reverts commit d5201df. * added to go.mod * linted files * finished cra in repo layer for postgres, also finished controller layer * reverted postgres folder to commit d5201df * changed account_types to account_type, and introduced owner_type enum for owner_type field * fixed compile error * schema changes * lower-case postgres enum values --------- Co-authored-by: keyvi <z5482396@ad.unsw.edu.au> Co-authored-by: Kavika <kavika.palletenne@devsoc.app>
1 parent eed71d8 commit 4ebc14f

23 files changed

Lines changed: 2902 additions & 22 deletions

.devcontainer/Dockerfile

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,35 @@ ENV PATH="/root/go/bin:${PATH}"
1818
RUN go install golang.org/x/tools/gopls@latest \
1919
&& go install github.com/go-delve/delve/cmd/dlv@latest \
2020
&& go install golang.org/x/tools/cmd/goimports@latest \
21+
# needed for db migrations
2122
&& go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest \
2223
&& go install github.com/pressly/goose/v3/cmd/goose@latest \
24+
# needed for proto generation
25+
&& go install google.golang.org/protobuf/cmd/protoc-gen-go@latest \
26+
# needed for grpc
27+
&& go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest \
2328
&& curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $(go env GOPATH)/bin
2429

2530
# set-up bashrc to have basic colours
2631
RUN { \
27-
echo "alias ls='ls --color=auto'"; \
28-
echo "alias ll='ls -la --color=auto'"; \
29-
echo "alias grep='grep --color=auto'"; \
30-
echo "export PS1='\\[\\033[1;32m\\][dev-container]\\[\\033[0m\\] \\w \\$ '"; \
32+
echo '# Function to get the current git branch'; \
33+
echo 'parse_git_branch() {'; \
34+
echo ' git branch 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/ (\1)/"'; \
35+
echo '}'; \
36+
echo ''; \
37+
echo '# Set custom colored prompt: user@[devcontainer] path (git branch)'; \
38+
echo 'export PS1="\[\033[0;32m\]\u\[\033[0m\]@\[\033[1;32m\][devcontainer]\[\033[0m\] \[\033[0;34m\]\w\[\033[0m\]\[\033[0;33m\]\$(parse_git_branch)\[\033[0m\] $ "'; \
39+
echo '# Enable colors for ls'; \
40+
echo 'alias ls="ls --color=auto"'; \
41+
echo 'alias ll="ls -alF --color=auto"'; \
42+
echo 'alias la="ls -A --color=auto"'; \
43+
echo ''; \
44+
echo '# Enable colored auto-completion (for when you hit Tab)'; \
45+
echo 'bind "set colored-stats on"'; \
46+
echo 'bind "set colored-completion-prefix on"'; \
3147
} >> ~/.bashrc
48+
# marks git as safe so we can see branches in the .bashrc
49+
RUN git config --global --add safe.directory '*'
3250

3351
# make warchest folder
3452
RUN mkdir /root/warchest

money-module/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# *Warchest Money Module*
2+
## What is Money Module:
3+
This is an implementation of a logged ledger around Tigerbeetle as the OLTP and Postgres as the OLGP.
4+
5+
6+
# For Developers:
7+
## Use of directories:
8+
### Cmd:
9+
Money module drivers and handlers here
10+
### Internal:
11+
Private code, for money-module this will just be our config
12+
Folder has special treatment from Go compilers
13+
Money-Module business logic should also exist here
14+
Simple MVC like structure with grpc/service/repository layers here
15+
### Pkg:
16+
Public code, basically library code/generic helps should be placed here
17+
### Cmd:
18+
Only main.go will live here for now
19+
## Endpoints:
20+
### Example Endpoint

money-module/db/postgres/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Database Development at Warchest
2+
3+
When adding a new database table or domain to the system, follow these steps to ensure clean integration with our `sqlc`, `goose`, and `pgx` pipeline. All work should be done from within the `backend/db/` directory.
4+
5+
## 1. Create a Migration (`goose`)
6+
7+
Create a new file in the `migrations/` directory using goose conventions. It's recommended to name them sequentially or with timestamps.
8+
9+
**Use plural, lowercase naming conventions** (e.g., `users`, `orders`, `match_history`).
10+
11+
As an example, say you are trying to make a table called "users".
12+
13+
```bash
14+
cd backend/db
15+
goose -dir migrations create create_users sql
16+
```
17+
18+
Or simply create the file manually:
19+
```bash
20+
touch migrations/00001_create_users.sql
21+
```
22+
23+
## 2. Define the Structure (`migrations/`)
24+
25+
Write your standard PostgreSQL `CREATE TABLE` statements in the migration file. Add `+goose Up` and `+goose Down` annotations.
26+
27+
> **Rule of thumb:** Always include a primary key and standard audit timestamps (e.g., `created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()`).
28+
29+
Example (`migrations/00001_create_users.sql`):
30+
```sql
31+
-- +goose Up
32+
CREATE TABLE users (
33+
id BIGSERIAL PRIMARY KEY,
34+
username VARCHAR(255) NOT NULL UNIQUE,
35+
email VARCHAR(255) NOT NULL UNIQUE,
36+
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
37+
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
38+
);
39+
40+
-- +goose Down
41+
DROP TABLE users;
42+
```
43+
44+
## 3. Define the Actions (`queries/`)
45+
46+
Write your SQL queries with the required `sqlc` annotations so the Go compiler knows exactly how to generate the functions.
47+
Do this in a new file in the `queries/` directory, e.g., `queries/users.sql`.
48+
49+
```sql
50+
-- name: GetUser :one
51+
SELECT * FROM users
52+
WHERE id = $1 LIMIT 1;
53+
54+
-- name: CreateUser :one
55+
INSERT INTO users (username, email)
56+
VALUES ($1, $2)
57+
RETURNING *;
58+
```
59+
60+
## 4. Generate Go Code (`sqlc`)
61+
62+
`sqlc.yaml` is configured to automatically pick up any `.sql` files in the `migrations/` and `queries/` directories.
63+
64+
Run `sqlc generate` from within the `backend/db/` directory:
65+
66+
```bash
67+
cd backend/db
68+
sqlc generate
69+
```
70+
71+
This will output the type-safe Go bindings (using `pgx/v5`) directly in the `backend/db/` directory.
72+
73+
## 5. Applying Migrations
74+
75+
Apply your migrations against your development database using `goose`:
76+
77+
```bash
78+
goose -dir migrations postgres "user=postgres password=postgres dbname=warchest sslmode=disable" up
79+
```

money-module/db/postgres/generated/accounts.sql.go

Lines changed: 66 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

money-module/db/postgres/generated/db.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

money-module/db/postgres/generated/models.go

Lines changed: 157 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)