Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Example projects

The repository's examples/ directory has small, realistic projects for common stacks. Each has a schema (usually migrations), a few queries, a hand-written sqlsift.toml to copy, and a broken/ directory with intentional mistakes and the diagnostics they produce. They are checked in sqlsift's CI, so the setup they show keeps working.

ExampleStacksqlsift.toml
sqlc-gosqlc + golang-migrate, PostgreSQLschema_dir = "db/migrations", files = ["db/query/**/*.sql"]
prisma-typedsqlPrisma Migrate + TypedSQL, $queryRawschema_dir = "prisma/migrations", files = ["prisma/sql/*.sql", "src/**/*.ts"], embedded_sql_tags = ["sql", "$queryRaw", "$executeRaw"]
aiosqlaiosql (Python) + yoyo-migrations, PostgreSQLschema_dir = "migrations", files = ["queries/**/*.sql"]
postgres-jspostgres.js tagged templates + dbmateschema_dir = "db/migrations", files = ["src/**/*.ts"]
sqlxsqlx query_file! / query_file_as! + migrate!()schema_dir = "migrations", files = ["queries/**/*.sql"]
postgres-migrationsPlain SQL + migrations, PostgreSQLschema_dir = "migrations", files = ["queries/**/*.sql"]
mysqlFlyway-style migrations, MySQLschema_dir = "migrations", files = ["queries/**/*.sql"], dialect = "mysql"
dbt-postgresdbt on PostgreSQLschema = ["warehouse/raw.sql"], files = ["models/**/*.sql"]

A migration that breaks a query

postgres-migrations shows the case sqlsift is built for. Migration 0003 renames customers.name to full_name, and one report query still uses the old name:

error[E0002]: Column 'name' not found in table 'customers'
  --> broken/top_customers.sql:4:16
    |
  4 | SELECT c.id, c.name, sum(o.total) AS lifetime_value
    |                ^^^^
    = help: 'name' was renamed to 'full_name' in migrations/0003_rename_customer_name.sql:2

The query still parses and nothing else in the pull request touches it; without sqlsift it fails only once it runs against the migrated database. To get this in pull requests, check every query file in CI (see Re-check everything when the schema changes).