Minor alterations to ddevcontainer.

This commit is contained in:
Adam Outler
2025-10-16 00:09:07 +00:00
parent de92c9563e
commit f57ec74cc1
9 changed files with 121 additions and 80 deletions

View File

@@ -1,9 +1,14 @@
#!/bin/sh
# This script checks if the database file exists, and if not, creates it with the initial schema.
# It is intended to be run at the first start of the application.
test -f "${NETALERTX_DB}/app.db" && exit 0
# if the db exists, exit
test -f "${NETALERTX_DB_FILE}" && exit 0
echo "First run detected, creating initial database schema in ${NETALERTX_DB}/app.db"
echo "First run detected, creating initial database schema in ${NETALERTX_DB_FILE}"
cat << end-of-database > ${NETALERTX_DB}/db.sql
# Write all text to db file until we see "end-of-database-schema"
cat << end-of-database-schema > ${NETALERTX_DB_FILE}
CREATE TABLE sqlite_stat1(tbl,idx,stat);
CREATE TABLE Events (eve_MAC STRING (50) NOT NULL COLLATE NOCASE, eve_IP STRING (50) NOT NULL COLLATE NOCASE, eve_DateTime DATETIME NOT NULL, eve_EventType STRING (30) NOT NULL COLLATE NOCASE, eve_AdditionalInfo STRING (250) DEFAULT (''), eve_PendingAlertEmail BOOLEAN NOT NULL CHECK (eve_PendingAlertEmail IN (0, 1)) DEFAULT (1), eve_PairEventRowid INTEGER);
CREATE TABLE Sessions (ses_MAC STRING (50) COLLATE NOCASE, ses_IP STRING (50) COLLATE NOCASE, ses_EventTypeConnection STRING (30) COLLATE NOCASE, ses_DateTimeConnection DATETIME, ses_EventTypeDisconnection STRING (30) COLLATE NOCASE, ses_DateTimeDisconnection DATETIME, ses_StillConnected BOOLEAN, ses_AdditionalInfo STRING (250));
@@ -415,6 +420,7 @@ CREATE TRIGGER "trg_delete_devices"
'delete'
);
END;
end-of-database
end-of-database-schema
sqlite3 ${NETALERTX_DB}/app.db < ${NETALERTX_DB}/db.sql
# Import the database schema into the new database file
sqlite3 ${NETALERTX_DB_FILE} < ${NETALERTX_DB}/db.sql