Browse code

fixed to use also xx_data.sql scripts

Karel Kozlik authored on 20/07/2006 12:59:43
Showing 2 changed files
... ...
@@ -22,6 +22,7 @@ DEFAULT_MYSQL="mysql"
22 22
 DEFAULT_MYSQLDUMP="mysqldump"
23 23
 
24 24
 DEFAULT_CREATE_SCRIPT="my_create.sql"
25
+DEFAULT_DATA_SCRIPT="my_data.sql"
25 26
 DEFAULT_DROP_SCRIPT="my_drop.sql"
26 27
 
27 28
 CMD="$MYSQL -f -h$DBHOST -u$SQLUSER"
... ...
@@ -37,6 +38,7 @@ SYNOPSIS
37 38
   $COMMAND [options] drop
38 39
   $COMMAND [options] backup [filename] 
39 40
   $COMMAND [options] restore [filename]
41
+  $COMMAND [options] update-data
40 42
 
41 43
 DESCRIPTION
42 44
   This tool is a simple shell wrapper over mysql client utility that can
... ...
@@ -89,6 +91,11 @@ COMMANDS
89 91
     without create table statements (i.e. created with -t command line option) 
90 92
     and that the tables are empty.
91 93
 
94
+  update-data
95
+    Update initial data in database. This command delete vendor-controled
96
+    rows from databaze and replace them with new ones.
97
+    
98
+    
92 99
 OPTIONS
93 100
   -h, --help
94 101
       Display this help text.
... ...
@@ -155,6 +162,7 @@ COPYRIGHT
155 162
 
156 163
 FILES
157 164
   $CREATE_SCRIPT
165
+  $DATA_SCRIPT
158 166
   $DROP_SCRIPT
159 167
     
160 168
 REPORTING BUGS
... ...
@@ -252,9 +260,18 @@ create_db ()
252 260
 
253 261
     # Load table definitions
254 262
     sql_query $DBNAME < $CREATE_SCRIPT
263
+
264
+    # Load initial data
265
+    sql_query $DBNAME < $DATA_SCRIPT
255 266
 } # create_db
256 267
 
257 268
 
269
+# Update initial data
270
+update_db_data ()
271
+{
272
+    sql_query $DBNAME < $DATA_SCRIPT
273
+} # update_db_data
274
+
258 275
 
259 276
 # Main program
260 277
 COMMAND=`basename $0`
... ...
@@ -270,6 +287,7 @@ if [ -z "$MYSQL" ] ; then MYSQL=$DEFAULT_MYSQL; fi
270 287
 if [ -z "$MYSQLDUMP" ] ; then MYSQLDUMP=$DEFAULT_MYSQLDUMP; fi
271 288
 if [ -z "$DUMP_OPTS" ] ; then DUMP_OPTS=$DEFAULT_DUMP_OPTS; fi 
272 289
 if [ -z "$CREATE_SCRIPT" ] ; then CREATE_SCRIPT=`dirname $0`"/"$DEFAULT_CREATE_SCRIPT; fi
290
+if [ -z "$DATA_SCRIPT" ] ; then DATA_SCRIPT=`dirname $0`"/"$DEFAULT_DATA_SCRIPT; fi
273 291
 if [ -z "$DROP_SCRIPT" ] ; then DROP_SCRIPT=`dirname $0`"/"$DEFAULT_DROP_SCRIPT; fi
274 292
 
275 293
 TEMP=`getopt -o hn:r:w:p:P:ts:u:vkq:: --long help,name:,ro-username:,rw-username:,\
... ...
@@ -339,6 +357,12 @@ case $1 in
339 357
 	exit $?
340 358
 	;;
341 359
 
360
+    update-data) # Update initial data
361
+	prompt_pw
362
+	update_db_data
363
+	exit $?
364
+	;;
365
+    
342 366
     backup) # backup SER database
343 367
 	shift
344 368
 	if [ $# -eq 1 ] ; then
... ...
@@ -15,6 +15,7 @@ DEFAULT_PSQL="/usr/bin/psql"
15 15
 DEFAULT_PG_DUMP="/usr/bin/pg_dump"
16 16
 
17 17
 DEFAULT_CREATE_SCRIPT="pg_create.sql"
18
+DEFAULT_DATA_SCRIPT="pg_data.sql"
18 19
 DEFAULT_DROP_SCRIPT="pg_drop.sql"
19 20
 
20 21
 #DBHOST="localhost"
... ...
@@ -96,6 +97,7 @@ db_create ()
96 97
     echo "Creating database $1"
97 98
     echo "CREATE DATABASE $1" | $CMD "template1"
98 99
     $CMD $1 < $CREATE_SCRIPT
100
+    $CMD $1 < $DATA_SCRIPT
99 101
 }
100 102
 
101 103
 
... ...
@@ -128,6 +130,10 @@ if [ -z "$CREATE_SCRIPT" ]; then
128 130
     CREATE_SCRIPT=$DEFAULT_CREATE_SCRIPT;
129 131
 fi
130 132
 
133
+if [ -z "$DATA_SCRIPT" ]; then
134
+    DATA_SCRIPT=$DEFAULT_DATA_SCRIPT;
135
+fi
136
+
131 137
 if [ -z "$DROP_SCRIPT" ]; then
132 138
     DROP_SCRIPT=$DEFAULT_DROP_SCRIPT;
133 139
 fi