2 # Copyright (C) 2005-2018 by the Quassel Project - devel@quassel-irc.org
3 # Licensed under GNU General Public License version 2, or (at your option)
6 # Call this script whenever you need to add a new database schema version.
7 # You can also simply create a new folder in '[SQLite/PostgreSQL]/version/##',
8 # where '##' represents your new version number, incremented by one from
9 # whatever the current latest version is (e.g. 21 -> 22).
11 # NOTE: If you upgrade the database schema version, you must add upgrade
12 # scripts and modify the existing setup queries, then regenerate sql.qrc with
13 # 'updateSQLResource'. See 'README.md' for details.
16 # If not specified, assume current directory
17 if [ ! "$TARGET_DIR" ]; then
21 if [[ ! -d "$TARGET_DIR" ]]; then
22 echo "No such directory '$TARGET_DIR'" >&2
26 # Find out the name of the target directory to offer some guidance later.
27 TARGET_DB_NAME=$(basename "$TARGET_DIR")
29 # Upgrade scripts are stored in the 'version' subdirectory, e.g.
30 # 'SQL/[database]/version/##'.
31 cd "$TARGET_DIR/version"
33 # Grab the current schema version
34 CURRENT_VERSION=$(ls | sort -n | tail -n1)
36 if [ ! $CURRENT_VERSION ]; then
37 echo "No previous schema found to upgrade from" >&2
42 ((NEW_VERSION=$CURRENT_VERSION + 1))
44 # Create the new schema directory.
46 # Git doesn't track empty folders, no need for 'git add "$NEW_VERSION"'.
48 echo "New schema version '$TARGET_DB_NAME/version/$NEW_VERSION' created." >&2
49 echo "Create any needed 'upgrade_[...].sql' scripts in this folder." >&2
51 # Don't move any files over. Schema version upgrade scripts are now stored
52 # independently of the main SQL files in order to make the repository history
53 # more useful and easier to work with.
55 # Granted, this script doesn't do anything one couldn't easily manually do.
56 # I'd argue that's a good thing. Though as this script offers documentation
57 # and guidance for contributors new to the database schema system as well as
58 # helping migrate those used to the older method, it seems worthwhile keeping.