Database
Flamenco Manager and Worker use SQLite as database, and GORM as object-relational mapper (but see the note below).
Since SQLite has limited support for altering table schemas, migration requires copying old data to a temporary table with the new schema, then swap out the tables.
Flamenco mostly uses GORM for interfacing with its SQLite database. This is gradually being phased out, to be replaced with SQLC.
SQLC can be installed (installation docs) with a go install
command just like any other Go package, but that does depend on a C/C++
compiler:
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
The precompiled sqlc binaries work just as well, so choose whatever works for you.
Installing sqlc itself is only necessary to regenerate the database code. Once generated, the code is independent of sqlc.
Since installing sqlc via
go install
requires a C/C++ compiler, it is not part of themake with-deps
script. Because of this, it is also not included in themake generate-go
script.
Database schema changes are managed with Goose. Every change is defined in a separate SQL file, and has the queries to make the change and to roll it back. Of course the roll-back is only possible when no data was removed.
SQLC needs to know the final schema those Goose migrations produced. To generate the SQLC schema from the database itself, run:
make db-migrate-up
go run ./cmd/sqlc-export-schema
To generate Go code with SQLC after changing schema.sql
or queries.sql
:
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
sqlc generate