# shell snippet which extracts all available MINERVA versions from
# subdirectories available in DB_SCHEMA_DIR (typically
# `persist/src/db`) and generates database upgrade scripts (diff
# files)
# Precondition: the following variables have to be correctly initialised
# * DB_SCHEMA_DIR set to the directory containing database initialisation and upgrade sql commands
# * DBSCRIPT_DEST_DIR set to the directory that will be populated with database upgrade scripts
# * MAX_DB_VERSION_FOR_MIGRTION set to the max version number that should be used for generating migration scripts; further version will be managed by flyway
# Postcondition:
# * versions is set to the available MINERVA versions (bash array)
# * DBSCRIPT_DEST_DIR contains script to initialise the database from any version to the current version
#this variable will contain all available versions of the package
versions=();
#find all available versions
versionCompLte(){
["$1"="`echo-e"$1\n$2" | sort-V | head-n1`"]
}
versionCompLt(){
["$1"="$2"]&&return 1 || versionCompLte $1$2
}
for version in`ls"$DB_SCHEMA_DIR" | sort-V`;
do
if[-d"$DB_SCHEMA_DIR/$version"]
then
if versionCompLt $version$MAX_DB_VERSION_FOR_MIGRTION
echo"If no params are set then script restores minerva framework from the data put manually in the \$RESTORE_DIR directory. To run script properly following environment variables must be set: ";