Skip to content

Commit

Permalink
Migration scripts infrastructure.
Browse files Browse the repository at this point in the history
Some changes require manual action, like those affecting what is run
only during installation. It'd be nice if we had something for that
similar to what flyway does for the DB changes.
  • Loading branch information
lonemadmax committed Jul 31, 2018
1 parent 05ee06a commit a5fbfff
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ if [ ! -f "${basedir}"/publite2/settings.ini ]; then
cp "${basedir}"/publite2/settings.ini{.dist,}
fi

cd "${basedir}"/scripts/migration
mig_scripts=([0-9]*)
echo "${mig_scripts[-1]}" > checkpoint

cd "${basedir}"/scripts && ./sync-js-hand.sh
cd "${basedir}"/freeciv-web && ./build.sh

Expand Down
1 change: 1 addition & 0 deletions scripts/migration/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
checkpoint
Empty file added scripts/migration/0000-dummy
Empty file.
14 changes: 14 additions & 0 deletions scripts/migration/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Migration scripts
-----------------

When changes in Freeciv-web may make current installations stop working, a
migration script should be provided to help users find and understand the
changeset, and hopefully migrate their installation with no issues if it's
a default setup.

The filenames start with a sequential four-digit number. When `migrate.sh`
is executed it runs each of them in order, following from where it stopped
in its last execution.

The scripts may still fail on purpose if manual action is required (or safer
than trying to script it).
55 changes: 55 additions & 0 deletions scripts/migration/migrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Copyright (C) 2018 The Freeciv-web project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# Runs new migration scripts.
# migrate.sh [migration_dir]
#
# Every file in migration_dir starting with a number is run in lexicographical
# order, except the ones lower than or equal to the saved checkpoint.

set -e

if [ -z "$1" ]; then
BASEDIR=${BASH_SOURCE%/*}
else
BASEDIR=$1
fi

if [ -z "${BASEDIR}" ]; then
echo >&2 "Please pass the directory with the migration scripts"
exit 1
fi

if [ "${BASEDIR:0:1}" = - ]; then
BASEDIR=./"${BASEDIR}"
fi

cd "${BASEDIR}"

if [ -f checkpoint ]; then
read LAST < checkpoint
fi

for f in [0-9]*; do
if [ "$f" \> "${LAST}" ]; then
echo "Running $f"
./"$f"
echo "$f" > checkpoint
fi
done

echo "Migration finished"

0 comments on commit a5fbfff

Please sign in to comment.