From: Benjamin Diaz Date: Mon, 8 Oct 2018 19:34:17 +0000 (-0300) Subject: Adds use of OSMPOL_SQL_DATABASE_URI config param to connect to DB X-Git-Tag: v5.0.0~9 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F54%2F6654%2F4;p=osm%2FPOL.git Adds use of OSMPOL_SQL_DATABASE_URI config param to connect to DB The OSMPOL_SQL_DATABASE_URI was not being used by POL to connect to the database. There was a hardcoded sqlite database name. This change should now provide capability to the user to use any SQL database engine supported by the peewee ORM (mysql/mariadb, postgres, sqlite). Signed-off-by: Benjamin Diaz Change-Id: Iff406862fb3dfeb4453fb3213c94db6d62385d96 --- diff --git a/docker/Dockerfile b/docker/Dockerfile index ab5b411..5953489 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -44,7 +44,7 @@ ENV OSMPOL_DATABASE_DRIVER mongo ENV OSMPOL_DATABASE_HOST mongo ENV OSMPOL_DATABASE_PORT 27017 -ENV OSMPOL_SQL_DATABASE_URI sqlite:///mon_sqlite.db +ENV OSMPOL_SQL_DATABASE_URI sqlite:///policy_module.db ENV OSMPOL_LOG_LEVEL INFO ENV OSMPOL_KAFKA_LOG_LEVEL WARN diff --git a/osm_policy_module/core/config.py b/osm_policy_module/core/config.py index 84a1f57..94dec98 100644 --- a/osm_policy_module/core/config.py +++ b/osm_policy_module/core/config.py @@ -65,7 +65,7 @@ class Config(object): CfgParam('OSMPOL_DATABASE_DRIVER', "mongo", six.text_type), CfgParam('OSMPOL_DATABASE_HOST', "mongo", six.text_type), CfgParam('OSMPOL_DATABASE_PORT', 27017, int), - CfgParam('OSMPOL_SQL_DATABASE_URI', "sqlite:///mon_sqlite.db", six.text_type), + CfgParam('OSMPOL_SQL_DATABASE_URI', "sqlite:///policy_module.db", six.text_type), CfgParam('OSMPOL_LOG_LEVEL', "INFO", six.text_type), CfgParam('OSMPOL_KAFKA_LOG_LEVEL', "WARN", six.text_type), ] diff --git a/osm_policy_module/core/database.py b/osm_policy_module/core/database.py index 8ad19f2..e522b8d 100644 --- a/osm_policy_module/core/database.py +++ b/osm_policy_module/core/database.py @@ -25,14 +25,14 @@ import datetime import logging from peewee import CharField, IntegerField, ForeignKeyField, Model, TextField, AutoField, DateTimeField -from playhouse.sqlite_ext import SqliteExtDatabase +from playhouse.db_url import connect from osm_policy_module.core.config import Config log = logging.getLogger(__name__) cfg = Config.instance() -db = SqliteExtDatabase('policy_module.db') +db = connect(cfg.OSMPOL_SQL_DATABASE_URI) class BaseModel(Model):