|
Pierre-Yves Chibon |
651b34 |
Upgrade a database
|
|
Pierre-Yves Chibon |
651b34 |
==================
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
cdb855 |
For changes to the database schema, we rely on `Alembic <http: alembic.readthedocs.org="">`_.</http:>
|
|
Pierre-Yves Chibon |
651b34 |
This allows us to do upgrade and downgrade of schema migration, kind of like
|
|
Pierre-Yves Chibon |
651b34 |
one would do commits in a system like git.
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
To upgrade the database to the latest version simply run:
|
|
Pierre-Yves Chibon |
651b34 |
::
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
alembic upgrade head
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
cdb855 |
.. note:: if pagure's configuration file isn't in ``/etc/pagure/pagure.cfg``
|
|
Pierre-Yves Chibon |
cdb855 |
you will have to specify it to alembic using the command: ::
|
|
Pierre-Yves Chibon |
cdb855 |
|
|
Pierre-Yves Chibon |
cdb855 |
PAGURE_CONFIG=/path/to/pagure.cfg alembic upgrade head
|
|
Pierre-Yves Chibon |
cdb855 |
|
|
Pierre-Yves Chibon |
cdb855 |
This allow applies for the command specified below.
|
|
Pierre-Yves Chibon |
cdb855 |
|
|
Pierre-Yves Chibon |
cdb855 |
|
|
Pierre-Yves Chibon |
651b34 |
This may fail for different reasons:
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
* The change was already made in the database
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
This can be because the version of the database schema saved is incorrect.
|
|
Pierre-Yves Chibon |
651b34 |
It can be debugged using the following commands:
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
cdb855 |
* Find the current revision: ::
|
|
Pierre-Yves Chibon |
cdb855 |
|
|
Pierre-Yves Chibon |
cdb855 |
alembic current
|
|
Pierre-Yves Chibon |
cdb855 |
|
|
Pierre-Yves Chibon |
cdb855 |
* See the entire history: ::
|
|
Pierre-Yves Chibon |
cdb855 |
|
|
Pierre-Yves Chibon |
cdb855 |
alembic history
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
Once the revision at which your database should be is found (in the history)
|
|
Pierre-Yves Chibon |
cdb855 |
you can declare that your database is at this given revision using: ::
|
|
Pierre-Yves Chibon |
cdb855 |
|
|
Pierre-Yves Chibon |
cdb855 |
alembic stamp <revision id=""></revision>
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
Eventually, if you do not know where your database is or should be, you can
|
|
Pierre-Yves Chibon |
651b34 |
do an iterative process stamping the database for every revision, one by one
|
|
René Genz |
520020 |
trying every time to ``alembic upgrade`` until it works.
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
* The database used does not support some of the changes
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
SQLite is handy for development but does not support all the features of a
|
|
Pierre-Yves Chibon |
651b34 |
real database server. Upgrading a SQLite database might therefore not work,
|
|
Pierre-Yves Chibon |
651b34 |
depending on the changes done.
|
|
Pierre-Yves Chibon |
651b34 |
|
|
Pierre-Yves Chibon |
651b34 |
In some cases, if you are using a SQLite database, you will have to destroy
|
|
Pierre-Yves Chibon |
651b34 |
it and create a new one.
|