// vim: ts=4 sw=4 et ft=asciidoc

=== Alembic

As mentioned in a previous section, you can use https://alembic.sqlalchemy.org/[Alembic] to create or upgrade your database.
You need to start your first run using an empty database for this to work, because Alembic stores versioning information in said database.
Database upgrades are based on this information.
Follow the steps shown below, setting the `RELEASE` variable to the GitHub tag or release number of your choice.

[source,bash]
----
export RELEASE="2021.6"
wget https://github.com/rseichter/automx2/archive/refs/tags/$RELEASE.zip
unzip $RELEASE.zip
cd automx2-$RELEASE/alembic
----
Next, change the value for _sqlalchemy.url_ in `alembic.ini` to match your automx2 configuration.
Create an empty database unless you are using SQLite, in which case Alembic will create the database for you.
The final steps are activating the automx2 virtual Python environment and invoke _make_.

[source,bash]
----
source /path/to/automx2/.venv/bin/activate
make upgrade
----
You should see output similar to the following:

[source]
[.small]
----
PYTHONPATH=.. FLASK_APP=automx2.server:app flask db upgrade -d .
Running automx2 version 2021.6
INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade  -> f62e64b43d2f, DB schema for automx2 version 2020.0
Created: 2020-01-17 22:30:05.748651
INFO  [alembic.runtime.migration] Running upgrade f62e64b43d2f -> 5334f8a8282c, Add "prio" column to "server" table.
Created: 2020-12-15 15:04:49.371802
INFO  [alembic.runtime.migration] Running upgrade 5334f8a8282c -> 43ebb40d0578, DAV server support
----
