Skip to content
Snippets Groups Projects
Commit 6f9189a6 authored by tpylak's avatar tpylak
Browse files

screening: scripts to create a new db version

SVN: 17085
parent 0b95d0e3
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# Author: Tomasz Pylak
# Scripts to create new database version, common to all projects.
SQL_DIR=../../source/sql/
PREV_NUM=`ls -1 $SQL_DIR/postgresql | grep 0 | sort | tail -n 1 | sed /0/s///`
PREV_VER=`printf "%03d" $PREV_NUM`
CUR_VER=`printf "%03d" $(( $PREV_NUM+1 ))`
function get_db_dir {
local db_engine=$1
local ver=$2
echo $SQL_DIR/$db_engine/$ver
}
function copy_db_folder {
local db_engine=$1
local cur_dir=`get_db_dir $db_engine $CUR_VER`
local prev_dir=`get_db_dir $db_engine $PREV_VER`
mkdir $cur_dir
for file in $prev_dir/*; do
org_name=`basename $file`
new_name=${org_name/$PREV_VER/$CUR_VER}
cp $file $cur_dir/$new_name
done
}
function copy_migration_file {
local dir=$SQL_DIR/postgresql/migration
echo "-- Migration from $PREV_VER to $CUR_VER" > $dir/migration-$PREV_VER-$CUR_VER.sql
}
function print_finish_message {
echo "Sql files for the $CUR_VER version have been copied from the previous version $PREV_VER."
echo "Create a new test database after writing the migration script."
}
......@@ -3,38 +3,9 @@
# Creates new database version (all sql files) which is identical to the previous version.
# Assumes that it is called from the directory where it is located.
SQL_DIR=../../source/sql/
PREV_NUM=`ls -1 $SQL_DIR/postgresql | grep 0 | sort | tail -n 1 | sed /0/s///`
PREV_VER=0$PREV_NUM
CUR_VER=0$(( $PREV_NUM+1 ))
function get_db_dir {
local db_engine=$1
local ver=$2
echo $SQL_DIR/$db_engine/$ver
}
function copy_db_folder {
local db_engine=$1
local cur_dir=`get_db_dir $db_engine $CUR_VER`
local prev_dir=`get_db_dir $db_engine $PREV_VER`
mkdir $cur_dir
for file in $prev_dir/*; do
org_name=`basename $file`
new_name=${org_name/$PREV_VER/$CUR_VER}
cp $file $cur_dir/$new_name
done
}
function copy_migration_file {
local dir=$SQL_DIR/postgresql/migration
echo "-- Migration from $PREV_VER to $CUR_VER" > $dir/migration-$PREV_VER-$CUR_VER.sql
}
source common.sh
copy_db_folder generic
copy_db_folder postgresql
copy_migration_file
echo "Sql files for the $CUR_VER version have been copied from the previous version $PREV_VER."
echo "Create a new test database after writing the migration script."
print_finish_message
\ No newline at end of file
#!/bin/bash
# Author: Tomasz Pylak
# Creates new database version (all sql files) which is identical to the previous version.
# Assumes that it is called from the directory where it is located.
source ../../../openbis/resource/scripts/common.sh
copy_db_folder postgresql
copy_migration_file
print_finish_message
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment