cstar-migrate


Namecstar-migrate JSON
Version 1.0.0rc2 PyPI version JSON
download
home_page
SummaryCassandra schema migration tool
upload_time2023-08-22 11:33:51
maintainer
docs_urlNone
author
requires_python<4,>=3.8
licenseCopyright (C) 2020, 2021 Andrey Martyanov Copyright (C) 2017 Cobli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords cassandra schema migration tool
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            cstar-migrate
=============

.. start-inclusion-marker-do-not-remove

.. image:: https://github.com/martyanov/cstar-migrate/workflows/CI/badge.svg?event=push
   :alt: Build Status
   :target: https://github.com/martyanov/cstar-migrate/actions?query=event%3Apush+branch%3Amaster+workflow%3ACI

.. image:: https://img.shields.io/pypi/v/cstar-migrate.svg
   :alt: PyPI Version
   :target: https://pypi.python.org/pypi/cstar-migrate

.. image:: https://img.shields.io/pypi/pyversions/cstar-migrate.svg
   :alt: Supported Python Versions
   :target: https://pypi.python.org/pypi/cstar-migrate

.. image:: https://img.shields.io/pypi/l/cstar-migrate.svg
   :alt: License
   :target: https://pypi.python.org/pypi/cstar-migrate

Cassandra schema migration tool, a fork of `cassandra-migrate`_.

Installation
------------

Run ``python -m pip install cstar-migrate``.

Reasoning
---------

Unlike other available tools, this one:

- Written in Python for easy installation
- Does not require ``cqlsh``, just the Cassandra Python driver
- Supports baselining existing database to given versions
- Supports partial advancement
- Supports locking for concurrent instances using Lightweight Transactions
- Verifies stored migrations against configured migrations
- Stores content, checksum, date and state of every migration
- Supports deploying with different keyspace configurations for different environments
- Supports cql and python scripts migrations

Configuration
-------------

Databases are configured through YAML files. For example:

.. code:: yaml

    keyspace: cstar
    profiles:
      prod:
        replication:
          class: SimpleStrategy
          replication_factor: 3
    migrations_path: ./migrations

Where the ``migrations`` folder (relative to the config file). contains
``.cql`` or ``.py`` files. The files are loaded in lexical order.

The default convention is to name them in the form: ``001_my_migration.{cql | py}``.
A custom naming scheme can be specified with the ``new_migration_name`` option.

For example

.. code:: yaml

    # Default migration names
    new_migration_name: "{next_version:03d}_{desc}"

    # Date-based migration names
    new_migration_name: "{date:YYYYMMDDHHmmss}_{desc}"

    # Custom initial migration content for cql scripts
    new_cql_migration_text: |
      /* Cassandra migration for keyspace {keyspace}.
         Version {next_version} - {date}

         {full_desc} */

    # Custom initial migration content for python scripts
    new_python_migration_text: |
      # Cassandra migration for keyspace {keyspace}.
      # Version {next_version} - {date}
      # {full_desc} */

      def execute(session, **kwargs):
          """
          Main method for your migration. Do not rename this method.

          Raise an exception of any kind to abort the migration.
          """

          print("Cassandra session: ", session)


``new_migration_name`` is a new-style Python format string, which can use the
following parameters:

- ``next_version``: Number of the newly generated migration (as an ``int``).
- ``desc``: filename-clean description of the migration, as specified
  by the user.
- ``full_desc``: unmodified description, possibly containing special characters.
- ``date``: current date in UTC. Pay attention to the choice of formatting,
  otherwise you might include spaces in the file name. The above example should
  be a good starting point.
- ``keyspace``: name of the configured keyspace.

The format string should *not* contain the .cql or .py extensions, as it they
added automatically.

``new_cql_migraton_text`` defines the initial content of CQL migration files.

``new_python_migraton_text`` defines the initial content of Python migration
files.


Profiles
--------

Profiles can be defined in the configuration file. They can configure
the ``replication`` and ``durable_writes`` parameters for
``CREATE KEYSPACE``. A default ``dev`` profile is implicitly defined
using a replication factor of 1.

Usage
-----

Common parameters:

::

  -H HOSTS, --hosts HOSTS
                        Comma-separated list of contact points
  -p PORT, --port PORT
                        Connection port
  -u USER, --user USER
                        Connection username
  -P PASSWORD, --password PASSWORD
                        Connection password
  -c CONFIG_FILE, --config-file CONFIG_FILE
                        Path to configuration file
  -l PROTOCOL_VERSION, --protocol-version PROTOCOL_VERSION
                        Connection protocol version
  -m PROFILE, --profile PROFILE
                        Name of keyspace profile to use
  -s SSL_CERT, --ssl-cert SSL_CERT
                        File path of .pem or .crt containing certificate of
                        the cassandra host you are connecting to (or the
                        certificate of the CA that signed the host
                        certificate). If this option is provided, cassandra-
                        migrate will use ssl to connect to the cluster. If
                        this option is not provided, the -k and -t options
                        will be ignored.
  -k SSL_CLIENT_PRIVATE_KEY, --ssl-client-private-key SSL_CLIENT_PRIVATE_KEY
                        File path of the .key file containing the private key
                        of the host on which the cstar-migrate command is
                        run. This option must be used in conjuction with the
                        -t option. This option is ignored unless the -s option
                        is provided.
  -t SSL_CLIENT_CERT, --ssl-client-cert SSL_CLIENT_CERT
                        File path of the .crt file containing the public
                        certificate of the host on which the cstar-migrate
                        command is run. This certificate (or the CA that
                        signed it) must be trusted by the cassandra host that
                        migrations are run against. This option must be used
                        in conjuction with the -k option. This option is
                        ignored unless the -s option is provided.
  -y, --assume-yes
                        Automatically answer "yes" for all questions

migrate
~~~~~~~

Advances a database to the latest (or chosen) version of migrations.
Creates the keyspace and migrations table if necessary.

Migrate will refuse to run if a previous attempt failed. To override
that after cleaning up any leftovers (as Cassandra has no DDL
transactions), use the ``--force`` option.

Examples:

.. code:: bash

    # Migrate to the latest database version using the default configuration file,
    # connecting to Cassandra in the local machine
    cstar-migrate -H 127.0.0.1 migrate

    # Migrate to version 2 using a specific config file
    cstar-migrate -c mydb.yml migrate 2

    # Migrate to a version by name
    cstar-migrate migrate 002_my_changes.cql

    # Force migration after a failure
    cstar-migrate migrate 2 --force

reset
~~~~~

Reset the database by dropping an existing keyspace, then running a migration.

Examples:

.. code:: bash

    # Reset the database to the latest version
    cstar-migrate reset

    # Reset the database to a specifis version
    cstar-migrate reset 3

clear
~~~~~

Clear the database by dropping an existing keyspace.

Example:

.. code:: bash

    # Clear the database
    cstar-migrate clear

baseline
~~~~~~~~

Advance an existing database version without actually running the
migrations.

Useful for starting to manage a pre-existing database without recreating
it from scratch.

Examples:

.. code:: bash

    # Baseline the existing database to the latest version
    cstar-migrate baseline

    # Baseline the existing database to a specific version
    cstar-migrate baseline 5

status
~~~~~~

Print the current status of the database.

Example:

.. code:: bash

    cstar-migrate status

generate
~~~~~~~~

Generate a new migration file with the appropriate name and a basic header
template, in the configured ``migrations_path``.

When running the command interactively, the file will be opened by the default
editor. The newly-generated file name will be printed to stdout.

To generate a Python script, specify the ``--python`` option.

See the configuration section for details on migration naming.

Examples:

.. code:: bash

    cstar-migrate generate "My migration description"

    cstar-migrate generate "My migration description" --python

.. _cassandra-migrate: https://github.com/Cobliteam/cassandra-migrate

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "cstar-migrate",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<4,>=3.8",
    "maintainer_email": "",
    "keywords": "cassandra,schema,migration,tool",
    "author": "",
    "author_email": "Andrey Martyanov <andrey@martyanov.com>",
    "download_url": "https://files.pythonhosted.org/packages/a9/3a/c0e262892442250fe7bfba5704ecc2f38c5216817b4157bd310fb8ea2377/cstar-migrate-1.0.0rc2.tar.gz",
    "platform": null,
    "description": "cstar-migrate\n=============\n\n.. start-inclusion-marker-do-not-remove\n\n.. image:: https://github.com/martyanov/cstar-migrate/workflows/CI/badge.svg?event=push\n   :alt: Build Status\n   :target: https://github.com/martyanov/cstar-migrate/actions?query=event%3Apush+branch%3Amaster+workflow%3ACI\n\n.. image:: https://img.shields.io/pypi/v/cstar-migrate.svg\n   :alt: PyPI Version\n   :target: https://pypi.python.org/pypi/cstar-migrate\n\n.. image:: https://img.shields.io/pypi/pyversions/cstar-migrate.svg\n   :alt: Supported Python Versions\n   :target: https://pypi.python.org/pypi/cstar-migrate\n\n.. image:: https://img.shields.io/pypi/l/cstar-migrate.svg\n   :alt: License\n   :target: https://pypi.python.org/pypi/cstar-migrate\n\nCassandra schema migration tool, a fork of `cassandra-migrate`_.\n\nInstallation\n------------\n\nRun ``python -m pip install cstar-migrate``.\n\nReasoning\n---------\n\nUnlike other available tools, this one:\n\n- Written in Python for easy installation\n- Does not require ``cqlsh``, just the Cassandra Python driver\n- Supports baselining existing database to given versions\n- Supports partial advancement\n- Supports locking for concurrent instances using Lightweight Transactions\n- Verifies stored migrations against configured migrations\n- Stores content, checksum, date and state of every migration\n- Supports deploying with different keyspace configurations for different environments\n- Supports cql and python scripts migrations\n\nConfiguration\n-------------\n\nDatabases are configured through YAML files. For example:\n\n.. code:: yaml\n\n    keyspace: cstar\n    profiles:\n      prod:\n        replication:\n          class: SimpleStrategy\n          replication_factor: 3\n    migrations_path: ./migrations\n\nWhere the ``migrations`` folder (relative to the config file). contains\n``.cql`` or ``.py`` files. The files are loaded in lexical order.\n\nThe default convention is to name them in the form: ``001_my_migration.{cql | py}``.\nA custom naming scheme can be specified with the ``new_migration_name`` option.\n\nFor example\n\n.. code:: yaml\n\n    # Default migration names\n    new_migration_name: \"{next_version:03d}_{desc}\"\n\n    # Date-based migration names\n    new_migration_name: \"{date:YYYYMMDDHHmmss}_{desc}\"\n\n    # Custom initial migration content for cql scripts\n    new_cql_migration_text: |\n      /* Cassandra migration for keyspace {keyspace}.\n         Version {next_version} - {date}\n\n         {full_desc} */\n\n    # Custom initial migration content for python scripts\n    new_python_migration_text: |\n      # Cassandra migration for keyspace {keyspace}.\n      # Version {next_version} - {date}\n      # {full_desc} */\n\n      def execute(session, **kwargs):\n          \"\"\"\n          Main method for your migration. Do not rename this method.\n\n          Raise an exception of any kind to abort the migration.\n          \"\"\"\n\n          print(\"Cassandra session: \", session)\n\n\n``new_migration_name`` is a new-style Python format string, which can use the\nfollowing parameters:\n\n- ``next_version``: Number of the newly generated migration (as an ``int``).\n- ``desc``: filename-clean description of the migration, as specified\n  by the user.\n- ``full_desc``: unmodified description, possibly containing special characters.\n- ``date``: current date in UTC. Pay attention to the choice of formatting,\n  otherwise you might include spaces in the file name. The above example should\n  be a good starting point.\n- ``keyspace``: name of the configured keyspace.\n\nThe format string should *not* contain the .cql or .py extensions, as it they\nadded automatically.\n\n``new_cql_migraton_text`` defines the initial content of CQL migration files.\n\n``new_python_migraton_text`` defines the initial content of Python migration\nfiles.\n\n\nProfiles\n--------\n\nProfiles can be defined in the configuration file. They can configure\nthe ``replication`` and ``durable_writes`` parameters for\n``CREATE KEYSPACE``. A default ``dev`` profile is implicitly defined\nusing a replication factor of 1.\n\nUsage\n-----\n\nCommon parameters:\n\n::\n\n  -H HOSTS, --hosts HOSTS\n                        Comma-separated list of contact points\n  -p PORT, --port PORT\n                        Connection port\n  -u USER, --user USER\n                        Connection username\n  -P PASSWORD, --password PASSWORD\n                        Connection password\n  -c CONFIG_FILE, --config-file CONFIG_FILE\n                        Path to configuration file\n  -l PROTOCOL_VERSION, --protocol-version PROTOCOL_VERSION\n                        Connection protocol version\n  -m PROFILE, --profile PROFILE\n                        Name of keyspace profile to use\n  -s SSL_CERT, --ssl-cert SSL_CERT\n                        File path of .pem or .crt containing certificate of\n                        the cassandra host you are connecting to (or the\n                        certificate of the CA that signed the host\n                        certificate). If this option is provided, cassandra-\n                        migrate will use ssl to connect to the cluster. If\n                        this option is not provided, the -k and -t options\n                        will be ignored.\n  -k SSL_CLIENT_PRIVATE_KEY, --ssl-client-private-key SSL_CLIENT_PRIVATE_KEY\n                        File path of the .key file containing the private key\n                        of the host on which the cstar-migrate command is\n                        run. This option must be used in conjuction with the\n                        -t option. This option is ignored unless the -s option\n                        is provided.\n  -t SSL_CLIENT_CERT, --ssl-client-cert SSL_CLIENT_CERT\n                        File path of the .crt file containing the public\n                        certificate of the host on which the cstar-migrate\n                        command is run. This certificate (or the CA that\n                        signed it) must be trusted by the cassandra host that\n                        migrations are run against. This option must be used\n                        in conjuction with the -k option. This option is\n                        ignored unless the -s option is provided.\n  -y, --assume-yes\n                        Automatically answer \"yes\" for all questions\n\nmigrate\n~~~~~~~\n\nAdvances a database to the latest (or chosen) version of migrations.\nCreates the keyspace and migrations table if necessary.\n\nMigrate will refuse to run if a previous attempt failed. To override\nthat after cleaning up any leftovers (as Cassandra has no DDL\ntransactions), use the ``--force`` option.\n\nExamples:\n\n.. code:: bash\n\n    # Migrate to the latest database version using the default configuration file,\n    # connecting to Cassandra in the local machine\n    cstar-migrate -H 127.0.0.1 migrate\n\n    # Migrate to version 2 using a specific config file\n    cstar-migrate -c mydb.yml migrate 2\n\n    # Migrate to a version by name\n    cstar-migrate migrate 002_my_changes.cql\n\n    # Force migration after a failure\n    cstar-migrate migrate 2 --force\n\nreset\n~~~~~\n\nReset the database by dropping an existing keyspace, then running a migration.\n\nExamples:\n\n.. code:: bash\n\n    # Reset the database to the latest version\n    cstar-migrate reset\n\n    # Reset the database to a specifis version\n    cstar-migrate reset 3\n\nclear\n~~~~~\n\nClear the database by dropping an existing keyspace.\n\nExample:\n\n.. code:: bash\n\n    # Clear the database\n    cstar-migrate clear\n\nbaseline\n~~~~~~~~\n\nAdvance an existing database version without actually running the\nmigrations.\n\nUseful for starting to manage a pre-existing database without recreating\nit from scratch.\n\nExamples:\n\n.. code:: bash\n\n    # Baseline the existing database to the latest version\n    cstar-migrate baseline\n\n    # Baseline the existing database to a specific version\n    cstar-migrate baseline 5\n\nstatus\n~~~~~~\n\nPrint the current status of the database.\n\nExample:\n\n.. code:: bash\n\n    cstar-migrate status\n\ngenerate\n~~~~~~~~\n\nGenerate a new migration file with the appropriate name and a basic header\ntemplate, in the configured ``migrations_path``.\n\nWhen running the command interactively, the file will be opened by the default\neditor. The newly-generated file name will be printed to stdout.\n\nTo generate a Python script, specify the ``--python`` option.\n\nSee the configuration section for details on migration naming.\n\nExamples:\n\n.. code:: bash\n\n    cstar-migrate generate \"My migration description\"\n\n    cstar-migrate generate \"My migration description\" --python\n\n.. _cassandra-migrate: https://github.com/Cobliteam/cassandra-migrate\n",
    "bugtrack_url": null,
    "license": "Copyright (C) 2020, 2021 Andrey Martyanov Copyright (C) 2017 Cobli  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Cassandra schema migration tool",
    "version": "1.0.0rc2",
    "project_urls": {
        "Issues": "https://github.com/martyanov/cstar-migrate/issues",
        "Repository": "https://github.com/martyanov/cstar-migrate"
    },
    "split_keywords": [
        "cassandra",
        "schema",
        "migration",
        "tool"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a0d1715d2e7dc595ca0fc421a306b43cd4619706dab5c06c53e6f3c3343809c5",
                "md5": "e77a7d8165b5524e00e5f9f1e40c412c",
                "sha256": "69cfa75f0c51eec269337ca4971c21336f04eb910574721941dfafd8a03d4bbe"
            },
            "downloads": -1,
            "filename": "cstar_migrate-1.0.0rc2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e77a7d8165b5524e00e5f9f1e40c412c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.8",
            "size": 19059,
            "upload_time": "2023-08-22T11:33:49",
            "upload_time_iso_8601": "2023-08-22T11:33:49.357905Z",
            "url": "https://files.pythonhosted.org/packages/a0/d1/715d2e7dc595ca0fc421a306b43cd4619706dab5c06c53e6f3c3343809c5/cstar_migrate-1.0.0rc2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a93ac0e262892442250fe7bfba5704ecc2f38c5216817b4157bd310fb8ea2377",
                "md5": "310acdee3e8f83f5f3e6e5094e99695a",
                "sha256": "e6761b18242a15cdc04eb286dc7bc11f7bf6a13ff2bf958984ca6b3e519c4cbb"
            },
            "downloads": -1,
            "filename": "cstar-migrate-1.0.0rc2.tar.gz",
            "has_sig": false,
            "md5_digest": "310acdee3e8f83f5f3e6e5094e99695a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.8",
            "size": 17782,
            "upload_time": "2023-08-22T11:33:51",
            "upload_time_iso_8601": "2023-08-22T11:33:51.022774Z",
            "url": "https://files.pythonhosted.org/packages/a9/3a/c0e262892442250fe7bfba5704ecc2f38c5216817b4157bd310fb8ea2377/cstar-migrate-1.0.0rc2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-22 11:33:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "martyanov",
    "github_project": "cstar-migrate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cstar-migrate"
}
        
Elapsed time: 0.15487s