Skip to content

Commit b10893e

Browse files
committed
Add additional hook-feature to call hook scripts on all changed tables
1 parent 0746fc4 commit b10893e

File tree

1 file changed

+86
-23
lines changed

1 file changed

+86
-23
lines changed

build.sh

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ function setup_env() {
282282

283283
# if table changes are inside release, we have to call special-functionalities
284284
table_changes="FALSE"
285+
table_array=()
286+
table_set=()
285287

286288
# folder outside git repo
287289
depotpath="$(pwd)/$DEPOT_PATH/$branch"
@@ -620,13 +622,29 @@ function write_install_schemas(){
620622
entries=("${targetpath}/db/${schema}/.hooks/pre/${path}"/*.*)
621623
for entry in "${entries[@]}"; do
622624
file=$(basename "${entry}")
625+
file_ext=${file#*.}
626+
627+
if [[ "${file_ext}" == "tables.sql" ]]; then
628+
629+
if [ ${#table_set[@]} -gt 0 ]; then
630+
echo "Prompt running .hooks/pre/${path}/${file} with table set" >> "${target_install_file}"
631+
for table_item in "${table_set[@]}"
632+
do
633+
echo "Prompt >>> db/${schema}/.hooks/pre/${path}/${file} ${version} ${mode} ${table_item}.sql" >> "${target_install_file}"
634+
echo "@@.hooks/pre/${path}/${file} ${version} ${mode} ${table_item}.sql" >> "${target_install_file}"
635+
echo "Prompt <<< db/${schema}/.hooks/pre/${path}/${file} ${version} ${mode} ${table_item}.sql" >> "${target_install_file}"
636+
done
637+
echo "Prompt" >> "${target_install_file}"
638+
echo "" >> "${target_install_file}"
639+
fi
623640

624-
{
625-
echo "Prompt >>> db/${schema}/.hooks/pre/${path}/${file}"
626-
echo "@@.hooks/pre/${path}/${file}"
627-
echo "Prompt <<< db/${schema}/.hooks/pre/${path}/${file}"
628-
} >> "${target_install_file}"
629-
641+
else
642+
{
643+
echo "Prompt >>> db/${schema}/.hooks/pre/${path}/${file}"
644+
echo "@@.hooks/pre/${path}/${file}"
645+
echo "Prompt <<< db/${schema}/.hooks/pre/${path}/${file}"
646+
} >> "${target_install_file}"
647+
fi
630648
done
631649

632650
echo "Prompt" >> "${target_install_file}"
@@ -647,11 +665,16 @@ function write_install_schemas(){
647665

648666
for entry in "${sorted[@]}"; do
649667
file=$(basename "${entry}")
668+
file_ext=${file#*.}
650669

651670
if [[ "${path}" == "tables" ]]; then
652671
skipfile="FALSE"
653672
table_changes="TRUE"
654673

674+
# store tablename in array
675+
table_name="${file%%.*}"
676+
table_array+=( ${table_name} )
677+
655678
if [[ "${mode}" == "patch" ]]; then
656679
if [[ -d "${targetpath}/db/${schema}/tables/tables_ddl" ]]; then
657680
for f in "${targetpath}/db/${schema}/tables/tables_ddl"/${file%%.*}.*; do
@@ -670,37 +693,76 @@ function write_install_schemas(){
670693
echo "Prompt <<< db/${schema}/${path}/${file}" >> "${target_install_file}"
671694
fi
672695
else
673-
echo "Prompt >>> db/${schema}/${path}/${file}" >> "${target_install_file}"
674-
if [[ "${path}" == "ddl/pre_tst" ]] && [[ "${mode}" == "patch" ]]; then
675-
echo "--tst@@${path}/${file}" >> "${target_install_file}"
676-
elif [[ "${path}" == "ddl/pre_uat" ]] && [[ "${mode}" == "patch" ]]; then
677-
echo "--uat@@${path}/${file}" >> "${target_install_file}"
696+
697+
if ([[ "${path}" == ".hooks/pre" ]] || [[ "${path}" == ".hooks/post" ]]) && [[ "${file_ext}" == "tables.sql" ]]; then
698+
699+
if [ ${#table_set[@]} -gt 0 ]; then
700+
echo "Prompt running ${path}/${file} with table set" >> "${target_install_file}"
701+
for table_item in "${table_set[@]}"
702+
do
703+
echo "Prompt >>> db/${schema}/${path}/${file} ${version} ${mode} ${table_item}.sql" >> "${target_install_file}"
704+
echo "@@${path}/${file} ${version} ${mode} ${table_item}.sql" >> "${target_install_file}"
705+
echo "Prompt <<< db/${schema}/${path}/${file} ${version} ${mode} ${table_item}.sql" >> "${target_install_file}"
706+
done
707+
echo "Prompt" >> "${target_install_file}"
708+
echo "" >> "${target_install_file}"
709+
fi
678710
else
679-
echo "@@${path}/${file}" >> "${target_install_file}"
680-
echo "Prompt <<< db/${schema}/${path}/${file}" >> "${target_install_file}"
711+
712+
echo "Prompt >>> db/${schema}/${path}/${file}" >> "${target_install_file}"
713+
if [[ "${path}" == "ddl/pre_tst" ]] && [[ "${mode}" == "patch" ]]; then
714+
echo "--tst@@${path}/${file}" >> "${target_install_file}"
715+
elif [[ "${path}" == "ddl/pre_uat" ]] && [[ "${mode}" == "patch" ]]; then
716+
echo "--uat@@${path}/${file}" >> "${target_install_file}"
717+
else
718+
echo "@@${path}/${file}" >> "${target_install_file}"
719+
echo "Prompt <<< db/${schema}/${path}/${file}" >> "${target_install_file}"
720+
fi
721+
681722
fi
682723
fi
683-
done
724+
done #files in folder (sorted)
725+
726+
# union table names
727+
if [[ "${path}" == "tables" ]]; then
728+
# get distinct values of array
729+
table_set=($(printf "%s\n" "${table_array[@]}" | sort -u))
730+
fi
684731

685732
if [[ "${path}" == "ddl/patch/pre" ]] || [[ "${path}" == "ddl/patch/pre_tst" ]] || [[ "${path}" == "ddl/patch/pre_uat" ]]|| [[ "${path}" == "views" ]]
686733
then
687734
echo "WHENEVER SQLERROR EXIT SQL.SQLCODE" >> "${target_install_file}"
688735
fi
689736

690737

691-
692738
# post folder hooks
693739
echo "Prompt" >> "${target_install_file}"
694740
entries=("${targetpath}/db/${schema}/.hooks/post/${path}"/*.*)
695741
for entry in "${entries[@]}"; do
696742
file=$(basename "${entry}")
743+
file_ext=${file#*.}
744+
745+
if [[ "${file_ext}" == "tables.sql" ]]; then
746+
747+
if [ ${#table_set[@]} -gt 0 ]; then
748+
echo "Prompt running .hooks/post/${path}/${file} with table set" >> "${target_install_file}"
749+
for table_item in "${table_set[@]}"
750+
do
751+
echo "Prompt >>> db/${schema}/.hooks/post/${path}/${file} ${version} ${mode} ${table_item}.sql" >> "${target_install_file}"
752+
echo "@@.hooks/post/${path}/${file} ${version} ${mode} ${table_item}.sql" >> "${target_install_file}"
753+
echo "Prompt <<< db/${schema}/.hooks/post/${path}/${file} ${version} ${mode} ${table_item}.sql" >> "${target_install_file}"
754+
done
755+
echo "Prompt" >> "${target_install_file}"
756+
echo "" >> "${target_install_file}"
757+
fi
697758

698-
{
699-
echo "Prompt >>> db/${schema}/.hooks/post/${path}/${file}"
700-
echo "@@.hooks/post/${path}/${file}"
701-
echo "Prompt <<< db/${schema}/.hooks/post/${path}/${file}"
702-
} >> "${target_install_file}"
703-
759+
else
760+
{
761+
echo "Prompt >>> db/${schema}/.hooks/post/${path}/${file}"
762+
echo "@@.hooks/post/${path}/${file}"
763+
echo "Prompt <<< db/${schema}/.hooks/post/${path}/${file}"
764+
} >> "${target_install_file}"
765+
fi
704766
done
705767

706768
# set scan to off, to make use of vars inside main schema-hooks
@@ -711,8 +773,9 @@ function write_install_schemas(){
711773
echo "Prompt" >> "${target_install_file}"
712774
echo "Prompt" >> "${target_install_file}"
713775
echo "" >> "${target_install_file}"
714-
fi
715-
done #path
776+
777+
fi #path exists
778+
done #paths
716779

717780
echo "prompt compiling schema" >> "${target_install_file}"
718781
echo "exec dbms_utility.compile_schema(schema => user, compile_all => false);" >> "${target_install_file}"

0 commit comments

Comments
 (0)