54 lines
1.5 KiB
Markdown
54 lines
1.5 KiB
Markdown
# Initial setup
|
|
|
|
## Pre-requisite tools
|
|
|
|
```shell
|
|
go install github.com/a-h/templ/cmd/templ@latest
|
|
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
|
|
go install github.com/swaggo/swag/cmd/swag@latest
|
|
```
|
|
|
|
## Database
|
|
This project now uses [goose](https://github.com/pressly/goose) for DB migrations.
|
|
|
|
Install via `brew install goose` on a mac, or install via golang with command `go install github.com/pressly/goose/v3/cmd/goose@latest`
|
|
|
|
Create a new up/down migration file with this command
|
|
```shell
|
|
goose -dir db/migrations sqlite3 ./db.sqlite3 create init sql
|
|
```
|
|
|
|
```shell
|
|
sqlc generate
|
|
```
|
|
|
|
## HTML templates
|
|
Run `templ generate -path ./components` to generate code based on template files
|
|
|
|
## Documentation
|
|
Run `swag init --exclude "pkg.mod,pkg.build,pkg.tools" -o server/router/docs`
|
|
|
|
#### Database Configuration
|
|
By default the app uses SQLite and creates/opens `db.sqlite3`. You can opt into PostgreSQL
|
|
by setting environment variables:
|
|
|
|
- `DB_DRIVER`: `sqlite` (default) or `postgres`
|
|
- `DB_URL`: SQLite file path/DSN or PostgreSQL DSN
|
|
|
|
Examples:
|
|
```shell
|
|
# SQLite (default)
|
|
DB_DRIVER=sqlite DB_URL=./db.sqlite3
|
|
|
|
# PostgreSQL
|
|
DB_DRIVER=postgres DB_URL=postgres://user:pass@localhost:5432/vctp?sslmode=disable
|
|
```
|
|
|
|
PostgreSQL migrations live in `db/migrations_postgres`, while SQLite migrations remain in
|
|
`db/migrations`.
|
|
|
|
#### Snapshot Retention
|
|
Hourly and daily snapshot table retention can be configured with environment variables:
|
|
|
|
- `HOURLY_SNAPSHOT_MAX_AGE_DAYS` (default: 60)
|
|
- `DAILY_SNAPSHOT_MAX_AGE_MONTHS` (default: 12) |