~jcsackett/charmworld/bac-tag-constraints

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
Migrating data in Charmworld
----------------------------

Charmworld uses MongoDB for its data storage. In order to facilitate changes
to the design of the data in Mongo a migration tool is provided in
`migrations/migrate.py`.

The migration tool stores the current version in the collection `version`.

Commands
~~~~~~~~~

The `migrate` command is created when charmworld `setup.py` is processed.

In the order of typical usage:


Check the current version of the data store
............................................

::

    $ bin/migrations current
    0

Add a new migration script to be run.
............................................

::

    $ bin/migrations new -d "add new data to mongo"
    Created new migration: 001_add_new_data_to_mongo.py


Check the latest migration available.
............................................

::

    $ bin/migrations latest
    1

Run any migrations not in Mongo
............................................

::

    # Perform any long-running migrations in temp storage
    $ bin/migrations prepare-upgrade
    # Swap temp storage into place and run short-running migrations
    $ bin/migrations upgrade
    Updated the datastore to version: 1

Initial Upgrade requires --init
.................................
Initially the datastore is not tracked. The first upgrade done needs to
include `--init` to version the datastore and then process upgrades.

::

    $ bin/migrations prepare-upgrade --init
    Updated the datastore to version: 1


Deleting migrations
~~~~~~~~~~~~~~~~~~~
The most recent migration must not be deleted, because it also serves to identify the current migration version for up-to-date instances.  All other migrations can safely be deleted if they are no longer needed.  So if all production instances have had the migration applied, it is safe to simply delete it.

Avoid performing an es-update in migrations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The charm and Makefile ensure that es-update is run before running the code, so it is unnecessary to run es-update in a migration.