Database Migration Tool
Project description
dbupgrade
Database Migration Tool
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: postgres
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 scheme identifier, e.g.postgres
orsqlite
. - 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 this row
does not exist, it is created with version and api_level initially set to 0.
The current version and API level of the schema are requested from the database and all scripts with a higher version number are applied, in order. If there are any version numbers 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 seperate transaction. If a script fails, all changes in that script will be rolled back and the script will stop with an error message and a non-zero return status.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file dbupgrade-2.1.0-py3-none-any.whl
.
File metadata
- Download URL: dbupgrade-2.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4310fed9aa83430a258b73813617fdfd01de1e852f459c0b626787b67ba9f7f |
|
MD5 | b12df5b75434532bccb715e54380797e |
|
BLAKE2b-256 | 7f229081270640e1bcda6371a76a1a0abab684d6e4677259aa57a42151052b41 |