sqlite-utils 4.0, now with database schema migrations

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

Python developers working with SQLite can now run structured schema migrations and nested transactions through sqlite-utils 4.0, eliminating the need for a separate migration library.

Read this as

Simon Willison released version 4.0 of sqlite-utils, a free open-source command-line tool for managing SQLite databases. Its headline addition is database migrations: an ordered list of changes to a database's structure that the tool tracks and applies automatically. It also adds nested transactions, meaning groups of changes that can be undone together, and support for compound foreign keys. Anyone building small apps or data tools on SQLite is the audience; there are minor breaking changes requiring an upgrade guide.

sqlite-utils 4.0, the first major release since November 2020 and the project's 124th, folds schema migrations directly into the tool, absorbing Willison's separate sqlite-migrate package, which existing dependents keep working via a compatibility shim. The migrations design deliberately skips automatic generation and rollback support, unlike Django's migrations. Teams using the Datasette/LLM ecosystem gain a built-in migration path; minor breaking changes mean checking the upgrade guide before bumping versions.

sqlite-utils 4.0 adds a Migrations API: migration functions decorated via Migrations() are tracked in a _sqlite_migrations table (migration_set, name, applied_at) and applied via 'sqlite-utils migrate data.db migrations.py' or migrations.apply(db). Migrations rely on table.transform(), which implements SQLite's recommended 12-step ALTER TABLE workaround (recreate-copy-drop-rename). Also new: nestable db.atomic() context manager built on SQLite savepoints, and compound foreign key creation and introspection. Upserts now use INSERT ... ON CONFLICT ... DO UPDATE SET. Rollback support is intentionally omitted; the design originated in the sqlite-migrate package released three years ago.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

sqlite-utils Datasette LLM Django sqlite-migrate South

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading