enhanced apply-sql-patch it can print sql statements to initialize the database
[slim.amamou.scripts.git] / apply-sql-patch
blobdf4a8ef0738d1a407f9c24a6b9546817197f523d
1 #!/bin/sh
3 # applies SQL patch to a database and inserts a revision control entry in the
4 # database.
5 # usage :
6 # apply-sql-patch (without arguments)
7 # prints sql statements to initialise the datbase
8 # apply-sql-patch <patch-file>
9 # applies the patch to the database
11 if [ $? -eq 0 ]
12 then cat<<EOF
13 create table ctrl_patch (id integer auto_increment primary key, time timestamp, name varchar(128) unique);
14 insert into ctrl_patch values (NULL,NULL, 'patch-create-ctrl_patch.sql');
15 EOF
16 exit
19 patch=$1
20 db=markkit
21 db_user=root
23 ctrl_patch_query="insert into ctrl_patch values (NULL,NULL, '$patch')"
25 cat $patch
26 mysql -u $db_user $db < $patch
27 echo $ctrl_patch_query
28 echo $ctrl_patch_query | mysql -u $db_user $db