2019-08-25 23:02:49 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
sqlite_return=$(sqlite3 core.sqlite "SELECT version_num FROM meta LIMIT 1;" 2>/dev/null);
|
|
|
|
|
|
|
|
if ! [[ $sqlite_return =~ ^-?[0-9]+$ ]]
|
|
|
|
then
|
|
|
|
echo "No version number found. Initiating database."
|
|
|
|
sqlite_return=0;
|
|
|
|
fi;
|
|
|
|
|
|
|
|
version_num=$sqlite_return;
|
|
|
|
|
|
|
|
while [ -f sql/migration_$version_num.sql ]
|
|
|
|
do
|
2019-09-08 12:28:50 +00:00
|
|
|
echo "sql/migration_$version_num.sql";
|
2019-08-25 23:02:49 +00:00
|
|
|
sqlite3 core.sqlite < sql/migration_$version_num.sql;
|
|
|
|
((version_num++));
|
|
|
|
done;
|
|
|
|
|
2019-09-08 12:28:50 +00:00
|
|
|
echo "New Schemaversion: $version_num";
|
|
|
|
|
2019-08-25 23:02:49 +00:00
|
|
|
if [ $sqlite_return -eq 0 ]
|
|
|
|
then
|
|
|
|
sqlite3 core.sqlite "INSERT INTO meta (version_num) VALUES ($version_num); ";
|
|
|
|
else
|
|
|
|
sqlite3 core.sqlite "UPDATE meta SET version_num=$version_num;";
|
|
|
|
fi
|