Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,35 @@ ENV PATH="/root/go/bin:${PATH}"
RUN go install golang.org/x/tools/gopls@latest \
&& go install github.com/go-delve/delve/cmd/dlv@latest \
&& go install golang.org/x/tools/cmd/goimports@latest \
# needed for db migrations
&& go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest \
&& go install github.com/pressly/goose/v3/cmd/goose@latest \
# needed for proto generation
&& go install google.golang.org/protobuf/cmd/protoc-gen-go@latest \
# needed for grpc
&& go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest \
&& curl -sSfL https://golangci-lint.run/install.sh | sh -s -- -b $(go env GOPATH)/bin

# set-up bashrc to have basic colours
RUN { \
echo "alias ls='ls --color=auto'"; \
echo "alias ll='ls -la --color=auto'"; \
echo "alias grep='grep --color=auto'"; \
echo "export PS1='\\[\\033[1;32m\\][dev-container]\\[\\033[0m\\] \\w \\$ '"; \
echo '# Function to get the current git branch'; \
echo 'parse_git_branch() {'; \
echo ' git branch 2> /dev/null | sed -e "/^[^*]/d" -e "s/* \(.*\)/ (\1)/"'; \
echo '}'; \
echo ''; \
echo '# Set custom colored prompt: user@[devcontainer] path (git branch)'; \
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\] $ "'; \
echo '# Enable colors for ls'; \
echo 'alias ls="ls --color=auto"'; \
echo 'alias ll="ls -alF --color=auto"'; \
echo 'alias la="ls -A --color=auto"'; \
echo ''; \
echo '# Enable colored auto-completion (for when you hit Tab)'; \
echo 'bind "set colored-stats on"'; \
echo 'bind "set colored-completion-prefix on"'; \
} >> ~/.bashrc
# marks git as safe so we can see branches in the .bashrc
RUN git config --global --add safe.directory '*'

# make warchest folder
RUN mkdir /root/warchest
Expand Down
20 changes: 20 additions & 0 deletions money-module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# *Warchest Money Module*
## What is Money Module:
This is an implementation of a logged ledger around Tigerbeetle as the OLTP and Postgres as the OLGP.


# For Developers:
## Use of directories:
### Cmd:
Money module drivers and handlers here
### Internal:
Private code, for money-module this will just be our config
Folder has special treatment from Go compilers
Money-Module business logic should also exist here
Simple MVC like structure with grpc/service/repository layers here
### Pkg:
Public code, basically library code/generic helps should be placed here
### Cmd:
Only main.go will live here for now
## Endpoints:
### Example Endpoint
79 changes: 79 additions & 0 deletions money-module/db/postgres/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Database Development at Warchest

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.

## 1. Create a Migration (`goose`)

Create a new file in the `migrations/` directory using goose conventions. It's recommended to name them sequentially or with timestamps.

**Use plural, lowercase naming conventions** (e.g., `users`, `orders`, `match_history`).

As an example, say you are trying to make a table called "users".

```bash
cd backend/db
goose -dir migrations create create_users sql
```

Or simply create the file manually:
```bash
touch migrations/00001_create_users.sql
```

## 2. Define the Structure (`migrations/`)

Write your standard PostgreSQL `CREATE TABLE` statements in the migration file. Add `+goose Up` and `+goose Down` annotations.

> **Rule of thumb:** Always include a primary key and standard audit timestamps (e.g., `created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()`).

Example (`migrations/00001_create_users.sql`):
```sql
-- +goose Up
CREATE TABLE users (
id BIGSERIAL PRIMARY KEY,
username VARCHAR(255) NOT NULL UNIQUE,
email VARCHAR(255) NOT NULL UNIQUE,
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

-- +goose Down
DROP TABLE users;
```

## 3. Define the Actions (`queries/`)

Write your SQL queries with the required `sqlc` annotations so the Go compiler knows exactly how to generate the functions.
Do this in a new file in the `queries/` directory, e.g., `queries/users.sql`.

```sql
-- name: GetUser :one
SELECT * FROM users
WHERE id = $1 LIMIT 1;

-- name: CreateUser :one
INSERT INTO users (username, email)
VALUES ($1, $2)
RETURNING *;
```

## 4. Generate Go Code (`sqlc`)

`sqlc.yaml` is configured to automatically pick up any `.sql` files in the `migrations/` and `queries/` directories.

Run `sqlc generate` from within the `backend/db/` directory:

```bash
cd backend/db
sqlc generate
```

This will output the type-safe Go bindings (using `pgx/v5`) directly in the `backend/db/` directory.

## 5. Applying Migrations

Apply your migrations against your development database using `goose`:

```bash
goose -dir migrations postgres "user=postgres password=postgres dbname=warchest sslmode=disable" up
```
66 changes: 66 additions & 0 deletions money-module/db/postgres/generated/accounts.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions money-module/db/postgres/generated/db.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

157 changes: 157 additions & 0 deletions money-module/db/postgres/generated/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading