summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--support/schema/aur-schema.sql2
-rwxr-xr-xsupport/schema/gendummydata.py24
-rwxr-xr-xsupport/schema/reloadtestdb.sh28
3 files changed, 33 insertions, 21 deletions
diff --git a/support/schema/aur-schema.sql b/support/schema/aur-schema.sql
index 1649055e..44501b6b 100644
--- a/support/schema/aur-schema.sql
+++ b/support/schema/aur-schema.sql
@@ -1,7 +1,7 @@
-- The MySQL database layout for the AUR. Certain data
-- is also included such as AccountTypes, etc.
--
-DROP DATABASE AUR;
+DROP DATABASE IF EXISTS AUR;
CREATE DATABASE AUR DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE AUR;
diff --git a/support/schema/gendummydata.py b/support/schema/gendummydata.py
index d51b16c8..cdf365bc 100755
--- a/support/schema/gendummydata.py
+++ b/support/schema/gendummydata.py
@@ -9,13 +9,20 @@ usage: gendummydata.py outputfilename.sql
# package names. It generates the SQL statements to
# insert these users/packages into the AUR database.
#
+import random
+import time
+import os
+import sys
+import cStringIO
+import commands
+
DBUG = 1
SEED_FILE = "/usr/share/dict/words"
-DB_HOST = "localhost"
-DB_NAME = "AUR"
-DB_USER = "aur"
-DB_PASS = "aur"
+DB_HOST = os.getenv("DB_HOST", "localhost")
+DB_NAME = os.getenv("DB_NAME", "AUR")
+DB_USER = os.getenv("DB_USER", "aur")
+DB_PASS = os.getenv("DB_PASS", "aur")
USER_ID = 5 # Users.ID of first bogus user
PKG_ID = 1 # Packages.ID of first package
MAX_USERS = 300 # how many users to 'register'
@@ -39,14 +46,6 @@ RANDOM_LOCS = ("pub", "release", "files", "downloads", "src")
FORTUNE_CMD = "/usr/bin/fortune -l"
-import random
-import time
-import os
-import sys
-import cStringIO
-import commands
-
-
if len(sys.argv) != 2:
sys.stderr.write("Missing output filename argument");
raise SystemExit
@@ -60,6 +59,7 @@ out.write("BEGIN;\n")
#
if not os.path.exists(SEED_FILE):
sys.stderr.write("Please install the 'words' Arch package\n");
+ raise SystemExit
# Make sure database access will be available
#
diff --git a/support/schema/reloadtestdb.sh b/support/schema/reloadtestdb.sh
index 1cf392a2..5f26023c 100755
--- a/support/schema/reloadtestdb.sh
+++ b/support/schema/reloadtestdb.sh
@@ -1,17 +1,29 @@
-#!/bin/sh
+#!/bin/bash -e
-mydir=`pwd`
-if [ `basename $mydir` != "schema" ]; then
+DB_NAME=${DB_NAME:-AUR}
+DB_USER=${DB_USER:-aur}
+# Password should allow empty definition
+DB_PASS=${DB_PASS-aur}
+DB_HOST=${DB_HOST:-localhost}
+DATA_FILE=${DATA_FILE:-dummy-data.sql}
+
+echo "Using database $DB_NAME, user $DB_USER, host $DB_HOST"
+
+mydir=$(pwd)
+if [ $(basename $mydir) != "schema" ]; then
echo "you must be in the aur/support/schema directory to run this script"
- exit
+ exit 1
fi
echo "recreating database..."
-mysql -uaur -paur AUR < ./aur-schema.sql
+mysql -h $DB_HOST -u $DB_USER -p$DB_PASS < aur-schema.sql
+
+if [ ! -f $DATA_FILE ]; then
+ echo "creating dumy-data..."
+ python2 gendummydata.py $DATA_FILE
+fi
echo "loading dummy-data..."
-bzcat ./dummy-data.sql.bz2 | mysql -uaur -paur AUR
+mysql -h $DB_HOST -u $DB_USER -p$DB_PASS $DB_NAME < $DATA_FILE
echo "done."
-exit
-