Using sqlfu
sqlfu is a SQL-first data toolkit. If this skill triggered, treat the current project/package as using sqlfu for its database workflow: SQL is the authored source and TypeScript is generated from it.
First read the config
Find the nearest sqlfu.config.ts for the project/package you are changing. It tells you where sqlfu's files live:
definitions: desired schema SQL.migrations: ordered migration history, if the project uses migrations.queries: checked-in.sqlquery files.db: the database used bymigrate,check,sync,goto,baseline, and the UI, if configured.generate: typegen options such as schema authority, runtime validators, sync wrappers, and import extension.
Paths are relative to the config file. Do not assume the defaults if the config says otherwise.
Source files
- Edit
definitions.sqlor the configureddefinitionsfile when changing the desired schema. - Do not hand-author a new migration file. Run
sqlfu draft, then review and edit the drafted SQL if needed. - Edit query
.sqlfiles under the configuredqueriesdirectory. Generated wrappers live under<queries>/.generated/; do not edit them directly.
Schema changes
When migrations is configured:
- Update the configured
definitionsfile. - Run
sqlfu draft. - Review the new migration. Pay attention to renames, destructive changes, backfills, and SQLite table rebuilds.
- Run
sqlfu migratefor the configured dev database. - Run
sqlfu generateif generated outputs may have changed. - Run
sqlfu checkbefore considering the schema work complete.
sqlfu draft derives a migration filename when no name is supplied. Only pass an explicit name when the user or repo convention calls for one.
When migrations is not configured, there is no migration history to draft. Update the configured definitions file and run the commands that still apply for the project, usually sqlfu generate and any repo tests.
Query changes
- Add or edit a
.sqlfile under the configuredqueriesdirectory. - Run
sqlfu generate. - Import and call the generated wrapper from application code.
If generated TypeScript looks wrong, fix the SQL source or config first. The generated file is output, not the source of truth.
Useful commands
sqlfu init: create a new sqlfu project.sqlfu config: print the resolved project config.sqlfu draft: create a reviewable migration from the definitions-vs-migrations diff.sqlfu migrate: apply pending migrations to the configured database.sqlfu pending: list unapplied migration files.sqlfu applied: list migrations recorded in the database.sqlfu goto <target>: move the database schema and migration history to a target migration.sqlfu baseline <target>: update migration history to a target without changing live schema.sqlfu sync: push the desired schema directly to the live database; use for local development only.sqlfu generate: regenerate TypeScript outputs from checked-in query files.sqlfu check: verify the repo and configured database agree, and report recommended next actions.sqlfuorsqlfu serve: start the local backend forhttps://sqlfu.dev/ui.
Use the project's normal command runner for these commands, such as a package script, pnpm sqlfu ..., npx sqlfu ..., or a local/global sqlfu binary already available in the environment.