#!/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 echo "sql/migration_$version_num.sql"; sqlite3 core.sqlite < sql/migration_$version_num.sql; ((version_num++)); done; echo "New Schemaversion: $version_num"; 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