Installation
============
For proper installation you need to clone project from git.

.. note::
    It service installation assumes running in docker container, all commands below must be executed from `/srv` directory.


Database creation
-----------------
All databases for service must be created in accordance with *"./luna_lambda/configs/config.conf"*.

- Postgresql (require version 12.2 or higher)
- Oracle (require version Oracle Database Express Edition 21c or higher)

Create all required schemes in *postgresql*.
If database or user is not created yet, one should execute the following commands with "user name" and "database" from the config file
(for example, *config.conf* with "luna" and "luna_lambda"):

.. code-block:: bash

    psql -U postgres;

.. code-block:: sql

    create role luna;
    ALTER USER luna WITH PASSWORD 'luna';
    CREATE DATABASE luna_lambda;
    GRANT ALL PRIVILEGES ON DATABASE luna_lambda TO luna;
    ALTER ROLE luna WITH LOGIN;

Then launch *db_create.py* script for tables and primal data creation:

.. code-block:: bash

    python ./base_scripts/db_create.py

If script was executed without errors, all schemes were created successfully.
db_create also creates scripts for further database migration (db_repository folder), without these db migration execution is impossible.


First launch and testing
------------------------
If all previous actions are executed successfully, server is ready to work. To start server please launch *run.py* script.
While start you can add arguments: server message port, path to config, suffix for log files (for different workers).
By default 5210 port is used. Also it possible to run service with config from luna-configurator
(see `configurator <configurator.html>`_).

Example:

.. code-block:: bash

    ./run.py --port 5210 --config ./configs/myconfig.conf --log_suffix 1

After server is started, testing is recommended. To perform testing execute command

.. code-block:: bash

    python -m unittest tests.unittests_main

All tests should perform successfully.