fenix/fenix/db/migration
Tomi Juvonen 244fb3ced0 Detailed session information and enhancements
- Add GET /v1/maintenance/{session_id}/detail
- Add 'maintenance.session' event. This can be used
  to track workflow. It gives you percent of hosts
  maintained.

Other enhancements:
- Add Sample VNFM for OpenStack: vnfm.py
  (Kubernetes renamed to vnfm_k8s.py)
- Add Sample VNF for OpenStack:
  maintenance_hot_tpl.yaml
- Update testing instructions (tools)
- Update documentation
- Add more tools for testing:
  - fenix_db_reset (flushed the database)
  - set_config.py (set the AODH / Ceilometer config)
- Add admin tool: infra_admin.py
  This tool can run maintenance workflow and
  track its progress
- Make sure everything is written in database.
  If Fenix is restarted, it initialise existing
  'ongoing' workflows from database. More functions
  to database API and utilization in example workflows.

story: 2004336
Task: #27922

Change-Id: I794b11a8684f5fc513cb8f5affcd370ec70f3dbc
Signed-off-by: Tomi Juvonen <tomi.juvonen@nokia.com>
2020-04-17 13:05:21 +03:00
..
alembic_migrations Detailed session information and enhancements 2020-04-17 13:05:21 +03:00
README Initial DB support 2018-11-29 13:42:04 +02:00
__init__.py Initial DB support 2018-11-29 13:42:04 +02:00
alembic.ini Initial DB support 2018-11-29 13:42:04 +02:00
cli.py Initial DB support 2018-11-29 13:42:04 +02:00

README

# Copyright 2012 New Dream Network, LLC (DreamHost)
# Copyright 2014 Intel Corporation
# All Rights Reserved.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

Fenix project uses Alembic to handle database migrations. A migration occurs
by executing a script that details the changes needed to upgrade/downgrade
the database. The migration scripts are ordered so that multiple scripts
can run sequentially to update the database.

You can then upgrade to the latest database version via:
$ fenix-db-manage --config-file /path/to/fenix.conf upgrade head

To check the current database version:
$ fenix-db-manage --config-file /path/to/fenix.conf current

To create a script to run the migration offline:
$ fenix-db-manage --config-file /path/to/fenix.conf upgrade head --sql

To run the offline migration between specific migration versions:
$ fenix-db-manage --config-file /path/to/fenix.conf upgrade \
<start version>:<end version> --sql

Upgrade the database incrementally:
$ fenix-db-manage --config-file /path/to/fenix.conf \
upgrade --delta <# of revs>

Downgrade the database by a certain number of revisions:
$ fenix-db-manage --config-file /path/to/fenix.conf downgrade \
--delta <# of revs>


DEVELOPERS:
A database migration script is required when you submit a change to Fenix
that alters the database model definition. The migration script is a special
python file that includes code to update/downgrade the database to match the
changes in the model definition. Alembic will execute these scripts in order to
provide a linear migration path between revision. The fenix-db-manage command
can be used to generate migration template for you to complete. The operations
in the template are those supported by the Alembic migration library.
After you modified the Fenix models accordingly, you can create the revision.

$ fenix-db-manage --config-file /path/to/fenix.conf revision \
-m "description of revision" \
--autogenerate

This generates a prepopulated template with the changes needed to match the
database state with the models. You should inspect the autogenerated template
to ensure that the proper models have been altered.

In rare circumstances, you may want to start with an empty migration template
and manually author the changes necessary for an upgrade/downgrade. You can
create a blank file via:

$ fenix-db-manage --config-file /path/to/fenix.conf revision \
-m "description of revision"

The migration timeline should remain linear so that there is a clear path when
upgrading/downgrading. To verify that the timeline does branch, you can run
this command:
$ fenix-db-manage --config-file /path/to/fenix.conf check_migration

If the migration path does branch, you can find the branch point via:
$ fenix-db-manage --config-file /path/to/fenix.conf history