Rewrite electricity-logger to use an sqlite3 database
This commit is contained in:
32
script/electricity/createdb.sh
Executable file
32
script/electricity/createdb.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 [/path/to/db/database].db";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
echo "Creating database file $1...";
|
||||
touch "$1";
|
||||
if ! [ -f "$1" ]; then
|
||||
echo "Cannot open or create database file $1, aborting.";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
TABLE_NAME="ElectricityLog";
|
||||
|
||||
echo "Creating table $TABLE_NAME...";
|
||||
sqlite3 $1 "CREATE TABLE IF NOT EXISTS $TABLE_NAME (\
|
||||
Date TEXT NOT NULL,\
|
||||
TimeUtc TEXT NOT NULL,\
|
||||
CurrentPowerUsage REAL NOT NULL,\
|
||||
TotalPowerConsumptionDay REAL NOT NULL,\
|
||||
TotalPowerConsumptionNight REAL NOT NULL,\
|
||||
CurrentPowerReturn REAL NOT NULL,\
|
||||
TotalPowerReturnDay REAL NOT NULL,\
|
||||
TotalPowerReturnNight REAL NOT NULL,\
|
||||
DayTarifEnabled INTEGER NOT NULL,\
|
||||
GasConsumptionInCubicMeters REAL NOT NULL);";
|
||||
|
||||
echo "Creating indexes on table $TABLE_NAME...";
|
||||
sqlite3 $1 "CREATE INDEX IF NOT EXISTS idx_Date ON $TABLE_NAME (Date);"
|
||||
sqlite3 $1 "CREATE INDEX IF NOT EXISTS idx_TimeUtc ON $TABLE_NAME (TimeUtc);"
|
||||
Reference in New Issue
Block a user