dbupgrade


Namedbupgrade JSON
Version 2023.10.0 PyPI version JSON
download
home_pagehttps://github.com/srittau/dbupgrade
SummaryDatabase Migration Tool
upload_time2023-10-08 16:01:10
maintainer
docs_urlNone
authorSebastian Rittau
requires_python>=3.9,<4.0
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # dbupgrade

Database Migration Tool

[![Python](https://img.shields.io/pypi/pyversions/dbupgrade.svg)](https://pypi.python.org/pyversions/dbupgrade/)
[![MIT License](https://img.shields.io/pypi/l/dbupgrade.svg)](https://pypi.python.org/pypi/dbupgrade/)
[![GitHub](https://img.shields.io/github/release/srittau/dbupgrade/all.svg)](https://github.com/srittau/dbupgrade/releases/)
[![pypi](https://img.shields.io/pypi/v/dbupgrade.svg)](https://pypi.python.org/pypi/dbupgrade/)
[![GitHub Actions](https://img.shields.io/github/workflow/status/srittau/dbupgrade/Test%20and%20lint)](https://github.com/srittau/dbupgrade/actions)

## 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:

```sql
-- 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` or `sqlite`.
- **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 are `yes` (default) and `no`. 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.

## JSON Output

When supplying the `--json` option, `dbupgrade` will information about the
applied scripts as JSON to the standard output. Sample output:

```json
{
  "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
  }
}
```

`success` is `true` if all scripts were applied successfully or no scripts
were to be applied. In this case, the `failedScript` key is not defined.
The `appliedScripts` key is always defined. In case no scripts were applied,
it's an empty array.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/srittau/dbupgrade",
    "name": "dbupgrade",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Sebastian Rittau",
    "author_email": "srittau@rittau.biz",
    "download_url": "https://files.pythonhosted.org/packages/66/07/99e1e91808e6d2eab2c574171e384c2dba8f4248fbaaccf711a608cac7af/dbupgrade-2023.10.0.tar.gz",
    "platform": null,
    "description": "# dbupgrade\n\nDatabase Migration Tool\n\n[![Python](https://img.shields.io/pypi/pyversions/dbupgrade.svg)](https://pypi.python.org/pyversions/dbupgrade/)\n[![MIT License](https://img.shields.io/pypi/l/dbupgrade.svg)](https://pypi.python.org/pypi/dbupgrade/)\n[![GitHub](https://img.shields.io/github/release/srittau/dbupgrade/all.svg)](https://github.com/srittau/dbupgrade/releases/)\n[![pypi](https://img.shields.io/pypi/v/dbupgrade.svg)](https://pypi.python.org/pypi/dbupgrade/)\n[![GitHub Actions](https://img.shields.io/github/workflow/status/srittau/dbupgrade/Test%20and%20lint)](https://github.com/srittau/dbupgrade/actions)\n\n## Basic Usage\n\nUsage: `dbupgrade [OPTIONS] [-l API_LEVEL|-L] DBNAME SCHEMA DIRECTORY`\n\nUpgrade the given `SCHEMA` in the database specified as `DBNAME` with SQL\nscripts from `DIRECTORY`. `DIRECTORY` is searched for all files with the\n`.sql` suffix. These files are SQL scripts with a special header sections:\n\n```sql\n-- Schema: my-db-schema\n-- Version: 25\n-- API-Level: 3\n-- Dialect: postgres\n\nCREATE TABLE ...\n```\n\nThe following headers are required:\n\n- **Schema**  \n   Name of the schema to update.\n- **Dialect**  \n   Database dialect of this script. Use SQLalchemy's database\n  URL scheme identifier, e.g. `postgres` or `sqlite`.\n- **Version**  \n   The new version of the schema after this script was applied.\n  It is an error if two scripts have the same schema, dialect, and version.\n- **API-Level**  \n   The new API level of the schema after this script was applied.\n  For a given schema, the API level of a subsequent version must either be\n  equal or higher by one than the API level of the preceding version. For\n  example, if script version 44 has API level 3, script version 45 must\n  have API level 3 or 4.\n- **Transaction** _(optional)_  \n   Possible values are `yes` (default) and `no`. When this\n  header is yes, all statements of a single upgrade file and the\n  corresponding version upgrade statements are executed within a single\n  transaction. Otherwise each statement is executed separately. The former\n  is usually preferable so that all changes will be rolled back if a\n  script fails to apply, but the latter is required in some cases.\n\nThe database must contain a table `db_config` with three columns: `schema`,\n`version`, and `api_level`. If this table does not exist, it is created.\nThis table must contain exactly one row for the given schema. If this row\ndoes not exist, it is created with version and api_level initially set to 0.\n\nThe current version and API level of the schema are requested from the\ndatabase and all scripts with a higher version number are applied, in order.\nIf there are any version numbers missing, the script will stop after the\nlast version before the missing version.\n\nUnless the `-l` or `-L` option is supplied, only scripts that do not\nincrease the API level will be applied. If the `-l` option is given, all\nscripts up to the given API level will be applied. `-L` will apply all\nscripts without regard to the API level.\n\nEach script is executed in a seperate transaction. If a script fails, all\nchanges in that script will be rolled back and the script will stop with\nan error message and a non-zero return status.\n\n## JSON Output\n\nWhen supplying the `--json` option, `dbupgrade` will information about the\napplied scripts as JSON to the standard output. Sample output:\n\n```json\n{\n  \"success\": true,\n  \"oldVersion\": {\n    \"version\": 123,\n    \"apiLevel\": 15\n  },\n  \"newVersion\": {\n    \"version\": 125,\n    \"apiLevel\": 16\n  },\n  \"appliedScripts\": [\n    {\n      \"filename\": \"0124-create-foo.sql\",\n      \"version\": 124,\n      \"apiLevel\": 15\n    },\n    {\n      \"filename\": \"0125-delete-bar-sql\",\n      \"version\": 125,\n      \"apiLevel\": 16\n    }\n  ],\n  \"failedScript\": {\n    \"filename\": \"0126-change-stuff.sql\",\n    \"version\": 126,\n    \"apiLevel\": 16\n  }\n}\n```\n\n`success` is `true` if all scripts were applied successfully or no scripts\nwere to be applied. In this case, the `failedScript` key is not defined.\nThe `appliedScripts` key is always defined. In case no scripts were applied,\nit's an empty array.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Database Migration Tool",
    "version": "2023.10.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/srittau/dbupgrade/issues",
        "Changes": "https://github.com/srittau/dbupgrade/blob/main/CHANGELOG.md",
        "GitHub": "https://github.com/srittau/dbupgrade",
        "Homepage": "https://github.com/srittau/dbupgrade",
        "Repository": "https://github.com/srittau/dbupgrade"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "97b3a3c187841f2f3521ed163c0e60a8cd2fa26efeb591fa8eb8c411c6bc8c18",
                "md5": "b1d2ff615491c80c8417339a91842b5d",
                "sha256": "2b07b5ac9af7d68c33a54d6d99d6d8f884273c6ff8ab80880b09f82f8250b094"
            },
            "downloads": -1,
            "filename": "dbupgrade-2023.10.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b1d2ff615491c80c8417339a91842b5d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9,<4.0",
            "size": 14070,
            "upload_time": "2023-10-08T16:01:08",
            "upload_time_iso_8601": "2023-10-08T16:01:08.458783Z",
            "url": "https://files.pythonhosted.org/packages/97/b3/a3c187841f2f3521ed163c0e60a8cd2fa26efeb591fa8eb8c411c6bc8c18/dbupgrade-2023.10.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "660799e1e91808e6d2eab2c574171e384c2dba8f4248fbaaccf711a608cac7af",
                "md5": "3967eb45a8a6c3e168ee2d334c85fd9f",
                "sha256": "0cb037a238f0aae6791b58173e4105bebfa160cf1ef2dc0a811fea0b66c8a53a"
            },
            "downloads": -1,
            "filename": "dbupgrade-2023.10.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3967eb45a8a6c3e168ee2d334c85fd9f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9,<4.0",
            "size": 12011,
            "upload_time": "2023-10-08T16:01:10",
            "upload_time_iso_8601": "2023-10-08T16:01:10.197882Z",
            "url": "https://files.pythonhosted.org/packages/66/07/99e1e91808e6d2eab2c574171e384c2dba8f4248fbaaccf711a608cac7af/dbupgrade-2023.10.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-08 16:01:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "srittau",
    "github_project": "dbupgrade",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "dbupgrade"
}
        
Elapsed time: 0.12211s