Create database during setup
authorJacob Casper <dev@jacobcasper.com>
Fri, 3 Apr 2020 05:46:02 +0000 (00:46 -0500)
committerJacob Casper <dev@jacobcasper.com>
Sat, 4 Apr 2020 22:45:49 +0000 (17:45 -0500)
mercuryms.service
migrations/001-create_media.sql [new file with mode: 0644]
migrations/002-create_sent_media.sql [new file with mode: 0644]
setup.sh

index 50044a8..8fe1143 100644 (file)
@@ -7,6 +7,7 @@ Type=simple
 User=mercuryms
 Group=mercuryms
 WorkingDirectory=/usr/share/mercuryms
+StandardOutput=syslog
 ExecStart=/opt/mercuryms/bin/python /opt/mercuryms/mms-download.py
 Environment="MERCURYMS_PORT=9092"
 
diff --git a/migrations/001-create_media.sql b/migrations/001-create_media.sql
new file mode 100644 (file)
index 0000000..bb9f029
--- /dev/null
@@ -0,0 +1,5 @@
+CREATE TABLE MEDIA (
+    ID INTEGER PRIMARY KEY AUTOINCREMENT,
+    PHONE_NUMBER TEXT NOT NULL,
+    URI TEXT NOT NULL
+);
diff --git a/migrations/002-create_sent_media.sql b/migrations/002-create_sent_media.sql
new file mode 100644 (file)
index 0000000..85f81cf
--- /dev/null
@@ -0,0 +1,5 @@
+CREATE TABLE SENT_MEDIA (
+    ID INTEGER PRIMARY KEY AUTOINCREMENT,
+    MEDIA_ID INTEGER NOT NULL,
+    FOREIGN KEY(MEDIA_ID) REFERENCES MEDIA(ID)
+);
index a4698ad..f1a3474 100755 (executable)
--- a/setup.sh
+++ b/setup.sh
@@ -5,3 +5,5 @@ groupadd mercuryms
 useradd -g mercuryms -d /usr/share/mercuryms -s $(which nologin) mercuryms
 chown mercuryms:mercuryms /usr/share/mercuryms
 chmod 700 /usr/share/mercuryms
+sqlite3 /usr/share/mercuryms/mercuryms.sqlite "$(cat migrations/*)"
+chown mercuryms:mercuryms /usr/share/mercuryms/mercuryms.sqlite