dbupgrade
Database Migration Tool
Basic Usage
Usage: dbupgrade [OPTIONS] [-l API_LEVEL|-L] DBNAME SCHEMA DIRECTORY
Upgrade the given SCHEMA in the database specified as DBNAME with SQL
scripts from DIRECTORY. DIRECTORY is searched for all files with the
.sql suffix. These files are SQL scripts with a special header sections:
-- Schema: my-db-schema
-- Version: 25
-- API-Level: 3
-- Dialect: postgresql
CREATE TABLE ...
The following headers are required:
- Schema
Name of the schema to update. - Dialect
Database dialect of this script. Use SQLalchemy's database URL dialect identifier, e.g.postgresqlorsqlite, but do not include the driver used to connect to the database. E.g. usepostgresqlinstead ofpostgresql+psycopg. - Version
The new version of the schema after this script was applied. It is an error if two scripts have the same schema, dialect, and version. - API-Level
The new API level of the schema after this script was applied. For a given schema, the API level of a subsequent version must either be equal or higher by one than the API level of the preceding version. For example, if script version 44 has API level 3, script version 45 must have API level 3 or 4. - Transaction (optional)
Possible values areyes(default) andno. When this header is yes, all statements of a single upgrade file and the corresponding version upgrade statements are executed within a single transaction. Otherwise each statement is executed separately. The former is usually preferable so that all changes will be rolled back if a script fails to apply, but the latter is required in some cases.
The database must contain a table db_config with three columns: schema,
version, and api_level. If this table does not exist, it is created.
This table must contain exactly one row for the given schema. If the row
does not exist, it will be created with the version and api_level columns
initially set to 0.
The current version and API level of the schema are retrieved from the database, and all scripts with a higher version number are applied in order. If any version numbers are missing, the script will stop after the last version before the missing version.
Unless the -l or -L option is supplied, only scripts that do not
increase the API level will be applied. If the -l option is given, all
scripts up to the given API level will be applied. -L will apply all
scripts without regard to the API level.
Each script is executed in a separate transaction. If a script fails, all changes made by that script will be rolled back, and the script will terminate with an error message and a non-zero return status.
JSON Output
When supplying the --json option, dbupgrade will print information about
the applied scripts as JSON to the standard output. Sample output:
{
"success": true,
"oldVersion": {
"version": 123,
"apiLevel": 15
},
"newVersion": {
"version": 125,
"apiLevel": 16
},
"appliedScripts": [
{
"filename": "0124-create-foo.sql",
"version": 124,
"apiLevel": 15
},
{
"filename": "0125-delete-bar-sql",
"version": 125,
"apiLevel": 16
}
],
"failedScript": {
"filename": "0126-change-stuff.sql",
"version": 126,
"apiLevel": 16
}
}
The success key is true if all scripts were applied successfully or if no
scripts needed to be applied. In this case, the failedScript key is not
included. The appliedScripts key is always present and contains an array
of applied scripts. If no scripts were applied, this array is empty.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dbupgrade-2026.8.0.tar.gz.
File metadata
- Download URL: dbupgrade-2026.8.0.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ea8bfa27bfb69c67e256dd6f0b52f868a78f93a27de98e3647dfc17427d37c8
|
|
| MD5 |
f63950e1f78b2fdfc63e23fc9e9bf546
|
|
| BLAKE2b-256 |
75e78407a4d7c2610d2b87cc4c0a0a0ee99c30f87c7263525672f63438c8eb86
|
File details
Details for the file dbupgrade-2026.8.0-py3-none-any.whl.
File metadata
- Download URL: dbupgrade-2026.8.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
418a882d627966650274869a04608e22b83f9180f9fbd14f594f9d2c056d2499
|
|
| MD5 |
3642eb020299aacab8cc2319a42819d5
|
|
| BLAKE2b-256 |
aa7fd2953dfb2d2579b8df0aa0c3593c2b2aa8f0df3eb337339ed2847a2f26fa
|