Fix #5391 - Alembic migrations would only work for SQLite
[larjonas-mediagoblin.git] / devtools / make_example_database.sh
blob7cca3921ef429650950986553a061ddc42a4f42b
1 #!/usr/bin/env bash
3 # GNU MediaGoblin -- federated, autonomous media hosting
4 # Copyright (C) 2011, 2012 GNU MediaGoblin Contributors. See AUTHORS.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Affero General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Affero General Public License for more details.
16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 USAGE="Usage: $0 -h | [-p PATH] -e ENVIRONMENT"
21 ENVIRONMENT="migration-18"
22 USER_DEV="user_dev_default"
23 DEV_ENV_DIRECTORY_PATH="../mg-dev-environments"
25 while getopts ":hp:e:" opt;
27 case $opt in
29 echo $USAGE
30 echo "Sets up an example mediagoblin instance for testing code."
31 echo ""
32 echo " -h Shows this help message."
33 echo " -p=PATH The path to your mg-dev-environments repository"
34 echo " -e=ENVIRONMENT The name of the environment you want to set up. Useful"
35 echo " if you want to set up a database from a past version."
36 echo " This defaults to a database from the most recent version"
37 echo " of master."
38 exit 1
41 ENVIRONMENT=$OPTARG
44 DEV_ENV_DIRECTORY_PATH=$OPTARG
46 \?)
47 echo "Invalid Option: -$OPTARG" >&2
50 echo "Option -$OPTARG requires an argument" >&2
52 esac
53 done
55 if [ ! -d $DEV_ENV_DIRECTORY_PATH ]; then
56 echo "$DEV_ENV_DIRECTORY_PATH not found. Have you downloaded the repo from \
57 git@gitorious.org:mediagoblin/mg-dev-environments.git ?" >&2
58 echo ""
59 exit 1
62 if [ ! -d "user_dev" ]; then
63 echo "ERROR: This script should be executed from within your mediagoblin \
64 instance directory" >&2
65 exit 1
68 if [ ! -e "$DEV_ENV_DIRECTORY_PATH/$ENVIRONMENT.tar.gz" ]; then
69 echo "$ENVIRONMENT.tar.gz not found in directory $DEV_ENV_DIRECTORY_PATH" >&2
70 exit 1
71 else
72 echo "***WARNING!***"
73 echo "This script will WIPE YOUR FULL CURRENT ENVIRONMENT and REPLACE IT with a test database and media!"
74 echo "Your databases and user_dev/ will all likely be wiped!"
75 echo -n "Do you want to continue? (y/n) "
76 read -n1 USER_CONFIRM
77 echo ""
78 counter=0
79 while [ "$USER_CONFIRM"=="y" ]; do
80 case $USER_CONFIRM in
82 break
85 exit 1
88 if [ $counter -lt 5 ]; then
89 echo "Invalid option. Please enter 'y' or 'n'"
90 echo "Do you want to continue? (y/n)"
91 read -n1 USER_CONFIRM
92 echo ""
93 counter+=1
94 continue
95 else
96 exit 1
99 esac
100 done
101 tar -xzf $DEV_ENV_DIRECTORY_PATH/$ENVIRONMENT.tar.gz
102 tar -xzf $DEV_ENV_DIRECTORY_PATH/$USER_DEV.tar.gz
103 echo "Completed."
104 exit 0