From 17e99d87254e74fe15c45d51148775c1759cc472 Mon Sep 17 00:00:00 2001
From: David Trattnig <david@subsquare.at>
Date: Fri, 21 Jan 2022 12:27:09 +0100
Subject: [PATCH] Ability to configure SQLite. #89

---
 .gitignore                           | 1 +
 config/sample-development.engine.ini | 2 +-
 config/sample-docker.engine.ini      | 2 +-
 config/sample-production.engine.ini  | 2 +-
 docs/bare-metal-installation.md      | 6 +++---
 src/base/config.py                   | 2 +-
 6 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4c721691..b9050fe8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,3 +12,4 @@ audio
 python
 __pycache__
 config/docker.engine.ini
+*.db
\ No newline at end of file
diff --git a/config/sample-development.engine.ini b/config/sample-development.engine.ini
index 61472191..7cdbdd43 100644
--- a/config/sample-development.engine.ini
+++ b/config/sample-development.engine.ini
@@ -66,7 +66,7 @@ api_engine_store_clock="http://localhost:8008/api/v1/clock"
 api_engine_store_health="http://localhost:8008/api/v1/source/health/${ENGINE_NUMBER}"
 
 [scheduler]
-# Database settings: Use 'postgresql' or 'mysql'
+# Database settings: Use 'postgresql', 'sqlite' or 'mysql'. In case of SQLite the "db_name" is the name of the file.
 db_type="postgresql"
 db_name="aura_engine"
 db_user="aura_engine"
diff --git a/config/sample-docker.engine.ini b/config/sample-docker.engine.ini
index 23e4aae4..734dcfae 100644
--- a/config/sample-docker.engine.ini
+++ b/config/sample-docker.engine.ini
@@ -66,7 +66,7 @@ api_engine_store_clock="http://127.0.0.1:8008/api/v1/clock"
 api_engine_store_health="http://127.0.0.1:8008/api/v1/source/health/${ENGINE_NUMBER}"
 
 [scheduler]
-# Database settings: Use 'postgresql' or 'mysql'
+# Database settings: Use 'postgresql', 'sqlite' or 'mysql'. In case of SQLite the "db_name" is the name of the file.
 db_type="postgresql"
 db_name="aura_engine"
 db_user="aura_engine"
diff --git a/config/sample-production.engine.ini b/config/sample-production.engine.ini
index bf7653b0..36bbd9a1 100644
--- a/config/sample-production.engine.ini
+++ b/config/sample-production.engine.ini
@@ -66,7 +66,7 @@ api_engine_store_clock="http://localhost:8008/api/v1/clock"
 api_engine_store_health="http://localhost:8008/api/v1/source/health/${ENGINE_NUMBER}"
 
 [scheduler]
-# Database settings: Use 'postgresql' or 'mysql'
+# Database settings: Use 'postgresql', 'sqlite' or 'mysql'. In case of SQLite the "db_name" is the name of the file.
 db_type="postgresql"
 db_name="aura_engine"
 db_user="aura_engine"
diff --git a/docs/bare-metal-installation.md b/docs/bare-metal-installation.md
index c3a13ddd..79de41b8 100644
--- a/docs/bare-metal-installation.md
+++ b/docs/bare-metal-installation.md
@@ -54,7 +54,8 @@ apt install \
     python3-psycopg2 \
     python3-requests \
     python3-sqlalchemy \
-    python3-validators
+    python3-validators \
+    sqlite3
 ```
 
 Create your base configuration from the sample configuration
@@ -68,10 +69,9 @@ cp config/sample-production.engine.ini config/engine.ini
 
 ### Setting up the database
 
-Engine requires a PorstgreSQL database to cache any programme info locally:
+Engine requires a PostgreSQL database to cache any programme info locally.
 
 ```bash
-# Create database and user (change password in script)
 sudo -u postgres psql -f contrib/postgresql-create-database.sql
 ```
 
diff --git a/src/base/config.py b/src/base/config.py
index cace94ba..6ce3438b 100644
--- a/src/base/config.py
+++ b/src/base/config.py
@@ -120,7 +120,7 @@ class AuraConfig:
                 return f"postgresql+psycopg2://{db_user}:{db_pass}@{db_host}/{db_name}?client_encoding={db_charset}"
         elif db_type == "sqlite":
             # "db_name" is expected to be either a relative or an absolute path to the sqlite file
-            return f"sqlite:///{db_name}"
+            return f"sqlite:///{db_name}.db"
         else:
             return f"Error: invalid database type '{db_type}'"
 
-- 
GitLab