Migration routine
=================

Surroundings
------------

If you use Luna Platform Docker deployment, skip this step (all the required dependencies are already installed in the Streams service image).
Otherwise you need to:

* replace all the Streams project files with the files of the current version

* install python dependencies:

.. warning::

    It is strongly recommended to create virtual surroundings for python dependencies installation.

.. code-block:: bash

    pip install -r requirements.txt

Service settings migration
--------------------------

If you don't use Configurator service, all you need is to set up your Streams configuration file *luna_streams/configs/config.conf*.
Otherwise, you need to execute settings migration.

If your previous Luna Platform version was used with non-default service settings, backup the service settings dump-file.
To create a dump-file, use the following options (may be executed from anywhere on your server):

.. code-block:: bash

    wget -O settings_dump_backup.json 127.0.0.1:5070/1/dump

To perform the migration, set up your migration configuration file in the following format:

.. code-block:: bash

    [LUNA_CONFIGURATOR_DB]

    #: [string] database type - "postgres" or "oracle"
    DB_TYPE = postgres
    #: [string] database host
    DB_HOST = 127.0.0.1
    #: [integer] database port; 5432 - default for "postgres" type, 1521 - default for "oracle" type
    DB_PORT = 5432
    #: [string] database username
    DB_USER = luna
    #: [string] database password
    DB_PASSWORD = luna
    #: [string] database name for "postgres" type, SID name for "oracle" type
    DB_NAME = luna_configurator

and execute the command:

.. code-block:: bash

    (cd luna_streams/configs/configs && python -m streams_configs.migrate head --config_db_url postgres://luna:luna@127.0.0.1:5432/luna_configurator)

If you use Luna Platform Docker deployment, use the following options:

.. code-block:: bash

    docker run \
        -v /etc/localtime:/etc/localtime:ro \
        -v <YOUR_CONFIG_PATH>:/srv/luna_streams/configs/configs/migration/config.conf \
        --rm \
        --network=host \
        --entrypoint=/bin/bash \
        dockerhub.visionlabs.ru/luna/luna-streams:<streams_tag> \
        -c "python3 -m streams_configs.migrate head --config_db_url postgres://luna:luna@127.0.0.1:5432/luna_configurator;"

Make sure your non-default service settings are up-to-date with your backup settings dump-file.



Database migration
------------------

You need to execute migration scripts to update your Streams database structure.

.. warning::

    It is highly recommended to create a backup of your database before applying any changes.

If you don't use the Configurator service, you need to set up your Streams configuration file and run migration with the following options:

.. code-block:: bash

    alembic -x config=luna_streams/configs/config.conf upgrade head

If you use the Configurator service, use the *luna-config* option with Configurator service origin:

.. code-block:: bash

    alembic -x luna-config=http://127.0.0.1:5070/1 upgrade head

If you use Luna Platform Docker deployment, use the following options:

.. code-block:: bash

    docker run \
    -v /etc/localtime:/etc/localtime:ro \
    --rm \
    --network=host \
    --entrypoint=/bin/bash \
    dockerhub.visionlabs.ru/luna/luna-streams:<streams_tag> \
    -c "alembic -x luna-config=http://127.0.0.1:5070/1 upgrade head"



Compatibility
-------------

Before starting the Streams service, make sure other services are migrated to compatible versions (i.e. belong to the current release).
