<commit_before>===================
Database Migrations
===================

Keystone uses SQLAlchemy Migrate (``sqlalchemy-migrate``) to manage migrations.

.. WARNING::

    Backup your database before applying migrations. Migrations may attempt to modify both your schema and data, and could result in data loss.

    Always review the behavior of migrations in a staging environment before applying them in production.

Getting Started
===============

Migrations are tracked using a metadata table. Place an existing database under version control to enable migration support (SQLite in this case)::

    $ python keystone/backends/sqlalchemy/migrate_repo/manage.py version_control --url=sqlite:///bin/keystone.db --repository=keystone/backends/sqlalchemy/migrate_repo/

If you are starting with an existing schema, you can set your database to the current schema version number using a
SQL command. For example, if you're starting from a
diablo-compatible database, set your current database version to ``1``::

    UPDATE migrate_version SET version=1;

Upgrading & Downgrading
=======================

Fresh installs of Keystone will need to run database upgrades, which will build a schema and bootstrap it with any necessary data.

Upgrade::

    $ python keystone/backends/sqlalchemy/migrate_repo/manage.py upgrade --url=sqlite:///bin/keystone.db --repository=keystone/backends/sqlalchemy/migrate_repo/

Downgrade (will likely result in data loss!)::

    $ python keystone/backends/sqlalchemy/migrate_repo/manage.py downgrade 1 --url=sqlite:///bin/keystone.db --repository=keystone/backends/sqlalchemy/migrate_repo/

Useful Links
============

Principles to follow when developing migrations `OpenStack Deployability <http://wiki.openstack.org/OpenstackDeployability>`_<commit_msg>Clarified language on migration instructions<commit_after>===================
Database Migrations
===================

Keystone uses SQLAlchemy Migrate (``sqlalchemy-migrate``) to manage migrations.

.. WARNING::

    Backup your database before applying migrations. Migrations may attempt to modify both your schema and data, and could result in data loss.

    Always review the behavior of migrations in a staging environment before applying them in production.

Getting Started
===============

Migrations are tracked using a metadata table. Place a new or existing schema under version control to enable migration support (SQLite in this case)::

    $ python keystone/backends/sqlalchemy/migrate_repo/manage.py version_control --url=sqlite:///bin/keystone.db --repository=keystone/backends/sqlalchemy/migrate_repo/

If you are starting with an existing schema, you **must** set your database to the appropriate schema version number using a
SQL command. For example, if you're starting from a ``diablo`` or ``diablo/stable`` database, set your current database version to ``1``::

    UPDATE migrate_version SET version=1;

Upgrading & Downgrading
=======================

Fresh installs of Keystone will need to run database upgrades, which will build a schema and bootstrap it with any necessary data.

Upgrade::

    $ python keystone/backends/sqlalchemy/migrate_repo/manage.py upgrade --url=sqlite:///bin/keystone.db --repository=keystone/backends/sqlalchemy/migrate_repo/

Downgrade (will likely result in data loss!)::

    $ python keystone/backends/sqlalchemy/migrate_repo/manage.py downgrade 1 --url=sqlite:///bin/keystone.db --repository=keystone/backends/sqlalchemy/migrate_repo/

Useful Links
============

Principles to follow when developing migrations `OpenStack Deployability <http://wiki.openstack.org/OpenstackDeployability>`_
{'fraction_non_alphanumeric': 0.11971444261394838, 'fraction_numerical': 0.0016474464579901153, 'mean_word_length': 5.102177554438861, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4004258', 'n_tokens_mistral': 1031, 'n_tokens_neox': 956, 'n_words': 357}