core-jgi/migration/migrate_postgresql.sh

59 lines
1.6 KiB
Bash
Raw Normal View History

2008-02-20 05:09:01 +07:00
#!/bin/sh
# This formats all the SQL files in the specified directory so that
# they can be executed by psql. There are two modes -- a 'testing'
# mode (the default mode -- this strips out all the "commit" statements)
# and a commit mode for deployment. You need to pipe the output of this
# script into sqlplus, for example:
# ./migrate.sh 313-314 commit | psql -U adempiere -d adempiere > 313-314.lst
# Original contribution by by Chris Farley - northernbrewer
# Adapted to postgresql by Carlos Ruiz - globalqss
# CarlosRuiz - added multidirectory management 2008/02/20
2008-02-20 05:09:01 +07:00
if [ -z "$1" ]; then
echo "Usage: $0 [DIRECTORY ... DIRECTORY] [commit]"
2008-02-20 05:09:01 +07:00
exit 0
fi
DIRINI=$1
COMMIT=0
while [ $# -gt 0 ]
do
DIR=$1
shift
if [ "$DIR" = "commit" ]; then
COMMIT=1
else
for file in $DIR/postgresql/*.sql; do
echo "SELECT '`basename $file`' AS Filename;"
cat $file | dos2unix | sed 's/commit[ ]*;//I'
echo
done
fi
2008-02-20 05:09:01 +07:00
done
if [ -d $DIRINI/../processes_post_migration/postgresql ]
2008-02-20 05:09:01 +07:00
then
for file in $DIRINI/../processes_post_migration/postgresql/*.sql; do
2008-02-20 05:09:01 +07:00
echo "SELECT '`basename $file`' AS Filename;"
cat $file | dos2unix | sed 's/commit[ ]*;//I'
echo
done
fi
if [ -d $DIRINI/../my_processes_post_migration/postgresql ]
then
for file in $DIRINI/../my_processes_post_migration/postgresql/*.sql; do
echo "SELECT '`basename $file`' AS Filename;"
cat $file | dos2unix | sed 's/commit[ ]*;//I'
echo
done
fi
if [ $COMMIT -eq 1 ]
then
echo "COMMIT;"
2008-02-20 05:09:01 +07:00
else
echo "ROLLBACK;"
2008-02-20 05:09:01 +07:00
fi
echo
echo "\quit"