Take control over your live stream video by running it yourself. Streaming + chat out of the box.
HTML activitypubbroadcastingchatdecentralizedfederationfediversegolanghacktoberfesthlslivelivestreamowncastrtmpself-hostedstreaming-videovideo
docs(db): explain migrations + sqlc workflow, drop stale schema.sql reference
Gabe Kangasa4b359b03824
diff --git a/CLAUDE.md b/CLAUDE.mdindex 59366f8797..fa1d36410c 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -49,3 +49,4 @@ Do not access the web application via http://localhost:8080 or build the web pro13. You should never commit the `static/web` directory to the repository. It is generated from the `web` directory and should be ignored in your commits.14. Don't use emoji in code comments or commit messages. That's lame.15. User interface components should use Ant Design v4 components, not Ant Design v5.+16. Database schema changes (new tables, columns, indexes) are made by adding a new numbered goose migration in `persistence/migrations/`. Never edit a shipped migration. Queries live in `db/query.sql`; after changing schema or queries run `make sqlc` to regenerate the type-safe Go. Don't hand-write raw SQL in Go. See `db/README.md` for the full walkthrough.diff --git a/db/README.md b/db/README.mdindex 9711224afc..a52ff9dd37 100644--- a/db/README.md+++ b/db/README.md@@ -1,38 +1,59 @@-# SQL Queries+# Database-sqlc generates **type-safe code** from SQL. Here's how it works:+Two pieces work together here:-1. You define the schema in `schema.sql`.-1. You write your queries in `query.sql` using regular SQL.-1. You run `sqlc generate` to generate Go code with type-safe interfaces to those queries.-1. You write application code that calls the generated code.+- **Schema** lives in `persistence/migrations/` as numbered [goose](https://github.com/pressly/goose) SQL migrations. These are the single source of truth for what the tables look like. They run automatically on startup.+- **Queries** live in `db/query.sql`. [sqlc](https://sqlc.dev) reads them (plus the schema from `persistence/migrations/`, see `sqlc.yaml`) and generates the type-safe Go in `db/query.sql.go` and `db/models.go`.-Only those who need to create or update SQL queries will need to have `sqlc` installed on their system. **It is not a dependency required to build the codebase.**+There is no `schema.sql`. sqlc derives the schema from the migrations.-## Using sqlc+## Adding or changing a column (or any schema change)-Run from the repository root:+1. **Write a migration.** Create the next numbered file in `persistence/migrations/`, e.g. `00005_add_widget_color.sql`. Copy the structure of an existing one. Put your `ALTER TABLE` / `CREATE TABLE` between the goose markers, and write the reverse in the `Down` section:-```bash-make sqlc-```+ ```sql+ -- +goose Up+ -- +goose StatementBegin+ ALTER TABLE users ADD COLUMN widget_color TEXT NOT NULL DEFAULT '';+ -- +goose StatementEnd-Or manually:+ -- +goose Down+ -- +goose StatementBegin+ ALTER TABLE users DROP COLUMN widget_color;+ -- +goose StatementEnd+ ```-```bash-./bin/sqlc generate-```+ Rules: never edit a migration that has already shipped (add a new one instead), keep the numbers sequential, and make statements idempotent where practical (`IF NOT EXISTS`).++2. **Update queries** in `db/query.sql` if you need to read or write the new column.++3. **Regenerate** the Go code:++ ```bash+ make sqlc+ ```++4. **Build.** `go build ./...` — the migration applies on next startup; no manual step.-## Managing Tool Versions+Do not hand-write raw SQL in Go for new work. Add it to `db/query.sql` and regenerate.-To upgrade sqlc to a specific version, edit `tools/go.mod` and run:+### Tables that are not yet sqlc-managed++Some older repositories still use hand-written SQL and are **not** wired into sqlc — for example `persistence/webhookrepository/`. For those tables, `make sqlc` generates nothing and there are no generated files to edit. The schema change still goes in a goose migration, but you then edit the raw SQL by hand in that repository (the `INSERT`, the `SELECT`, and the matching struct fields).++Watch for `SELECT *` with a positional `rows.Scan(...)`: adding a column changes how many values the row returns, so you must add the new column to the `Scan` argument list (in column order — a column added via `ALTER TABLE` lands last) or the scan fails at runtime. `GetWebhooks()` in the webhook repository is exactly this shape.++## sqlc++Only contributors who change SQL need sqlc installed; it is **not** required to build the project. `make sqlc` installs it into `./bin` automatically.++To upgrade sqlc, edit `tools/go.mod`, then:```bashcd tools && go get github.com/sqlc-dev/sqlc@latest && go mod tidy+rm ../bin/sqlc && cd .. && make sqlc```-Then reinstall:+## Legacy installs-```bash-rm ./bin/sqlc && make sqlc-```+Installs that predate goose tracked schema state in a `config.version` row advanced by a switch statement in `persistence/legacymigrations`. That package is **frozen** — no new cases. On startup, old installs are caught up to the goose baseline and then goose takes over. All new schema work goes in `persistence/migrations/` only. See `persistence/migrations/migrations.go`.