Skip to content

Commit c43b020

Browse files
committed
Merge branch 'develop'
2 parents 71fc037 + a3ff6ca commit c43b020

File tree

1 file changed

+192
-130
lines changed

1 file changed

+192
-130
lines changed

build.sh

Lines changed: 192 additions & 130 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"
@@ -562,166 +564,226 @@ function write_install_schemas(){
562564
timelog ""
563565

564566
# write some infos
565-
echo "set define '^'" > "${target_install_file}"
566-
echo "set concat on" >> "${target_install_file}"
567-
echo "set concat ." >> "${target_install_file}"
568-
echo "set verify off" >> "${target_install_file}"
569-
echo "WHENEVER SQLERROR EXIT SQL.SQLCODE" >> "${target_install_file}"
570-
571-
echo "" >> "${target_install_file}"
572-
573-
echo "define VERSION = '^1'" >> "${target_install_file}"
574-
echo "define MODE = '^2'" >> "${target_install_file}"
575-
576-
echo "set timing on" >> "${target_install_file}"
577-
echo "set trim on" >> "${target_install_file}"
578-
echo "set linesize 2000" >> "${target_install_file}"
579-
echo "set sqlblanklines on" >> "${target_install_file}"
580-
echo "set tab off" >> "${target_install_file}"
581-
echo "set pagesize 9999" >> "${target_install_file}"
582-
echo "set trimspool on" >> "${target_install_file}"
583-
echo "" >> "${target_install_file}"
584-
585-
echo "Prompt .............................................................................. " >> "${target_install_file}"
586-
echo "Prompt .............................................................................. " >> "${target_install_file}"
587-
echo "Prompt .. Start Installation for schema: ${schema} " >> "${target_install_file}"
588-
echo "Prompt .. Version: $mode $version " >> "${target_install_file}"
589-
echo "Prompt .............................................................................. " >> "${target_install_file}"
590-
echo "set serveroutput on" >> "${target_install_file}"
591-
echo "set scan off" >> "${target_install_file}"
592-
echo "" >> "${target_install_file}"
593-
594-
if [[ "${mode}" == "patch" ]]; then
595-
echo "Prompt .. Commit-History to install: " >> "${target_install_file}"
596-
git log --pretty=format:'Prompt .. %h %s <%an>' "${from_commit}"..."${until_commit}" -- "db/${schema}" >> "${target_install_file}"
597-
echo " " >> "${target_install_file}"
598-
echo "Prompt .. " >> "${target_install_file}"
599-
# echo "Prompt " >> "${target_install_file}"
600-
echo "Prompt .............................................................................. " >> "${target_install_file}"
601-
602-
echo "Prompt " >> "${target_install_file}"
603-
echo "Prompt " >> "${target_install_file}"
604-
fi
605-
567+
{
568+
echo "set define '^'"
569+
echo "set concat on"
570+
echo "set concat ."
571+
echo "set verify off"
572+
echo "WHENEVER SQLERROR EXIT SQL.SQLCODE"
573+
574+
echo ""
575+
576+
echo "define VERSION = '^1'"
577+
echo "define MODE = '^2'"
578+
579+
echo "set timing on"
580+
echo "set trim on"
581+
echo "set linesize 2000"
582+
echo "set sqlblanklines on"
583+
echo "set tab off"
584+
echo "set pagesize 9999"
585+
echo "set trimspool on"
586+
echo ""
587+
588+
echo "Prompt .............................................................................. "
589+
echo "Prompt .............................................................................. "
590+
echo "Prompt .. Start Installation for schema: ${schema} "
591+
echo "Prompt .. Version: $mode $version "
592+
echo "Prompt .............................................................................. "
593+
echo "set serveroutput on"
594+
echo "set scan off"
595+
echo ""
596+
597+
if [[ "${mode}" == "patch" ]]; then
598+
echo "Prompt .. Commit-History to install: "
599+
git log --pretty=format:'Prompt .. %h %s <%an>' "${from_commit}"..."${until_commit}" -- "db/${schema}"
600+
echo " "
601+
echo "Prompt .. "
602+
# echo "Prompt "
603+
echo "Prompt .............................................................................. "
604+
605+
echo "Prompt "
606+
echo "Prompt "
607+
fi
608+
} > "${target_install_file}"
606609

607610
# check every path in given order
608611
for path in "${SCAN_PATHES[@]}"
609612
do
610613
if [[ -d "${targetpath}"/db/${schema}/${path} ]]; then
611614
timelog "Writing calls for ${path}"
612-
echo "Prompt Installing ${path} ..." >> "${target_install_file}"
615+
{
616+
echo "Prompt Installing ${path} ..."
613617

614-
# set scan to on, to make use of vars inside main schema-hooks
615-
if [[ "${path}" == ".hooks/pre" ]] || [[ "${path}" == ".hooks/post" ]]; then
616-
echo "set scan on" >> "${target_install_file}"
617-
fi
618+
# set scan to on, to make use of vars inside main schema-hooks
619+
if [[ "${path}" == ".hooks/pre" ]] || [[ "${path}" == ".hooks/post" ]]; then
620+
echo "set scan on"
621+
fi
618622

619-
# pre folder-hooks (something like db/schema/.hooks/pre/tables)
620-
entries=("${targetpath}/db/${schema}/.hooks/pre/${path}"/*.*)
621-
for entry in "${entries[@]}"; do
622-
file=$(basename "${entry}")
623+
# pre folder-hooks (something like db/schema/.hooks/pre/tables)
624+
entries=("${targetpath}/db/${schema}/.hooks/pre/${path}"/*.*)
625+
for entry in "${entries[@]}"; do
626+
file=$(basename "${entry}")
627+
file_ext=${file#*.}
628+
629+
if [[ "${file_ext}" == "tables.sql" ]]; then
630+
631+
if [ ${#table_set[@]} -gt 0 ]; then
632+
echo "Prompt running .hooks/pre/${path}/${file} with table set"
633+
for table_item in "${table_set[@]}"
634+
do
635+
echo "Prompt >>> db/${schema}/.hooks/pre/${path}/${file} ${version} ${mode} ${table_item}.sql"
636+
echo "@@.hooks/pre/${path}/${file} ${version} ${mode} ${table_item}.sql"
637+
echo "Prompt <<< db/${schema}/.hooks/pre/${path}/${file} ${version} ${mode} ${table_item}.sql"
638+
done
639+
echo "Prompt"
640+
echo ""
641+
fi
623642

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}"
643+
else
644+
echo "Prompt >>> db/${schema}/.hooks/pre/${path}/${file}"
645+
echo "@@.hooks/pre/${path}/${file}"
646+
echo "Prompt <<< db/${schema}/.hooks/pre/${path}/${file}"
647+
fi
648+
done
629649

630-
done
650+
echo "Prompt"
651+
if [[ "${path}" == "ddl/patch/pre" ]] || [[ "${path}" == "ddl/patch/pre_tst" ]] || [[ "${path}" == "ddl/patch/pre_uat" ]] || [[ "${path}" == "views" ]]; then
652+
echo "WHENEVER SQLERROR CONTINUE"
653+
fi
631654

632-
echo "Prompt" >> "${target_install_file}"
633-
if [[ "${path}" == "ddl/patch/pre" ]] || [[ "${path}" == "ddl/patch/pre_tst" ]] || [[ "${path}" == "ddl/patch/pre_uat" ]] || [[ "${path}" == "views" ]]; then
634-
echo "WHENEVER SQLERROR CONTINUE" >> "${target_install_file}"
635-
fi
655+
# read files from folder
656+
entries=("${targetpath}/db/${schema}/${path}"/*.*)
636657

637-
# read files from folder
638-
entries=("${targetpath}/db/${schema}/${path}"/*.*)
658+
# if packages then sort descending
659+
if [[ "${path}" == "sources/packages" ]] || [[ "${path}" == "tests/packages" ]]; then
660+
IFS=$'\n' sorted=($(sort -r <<<"${entries[*]}")); unset IFS
661+
else
662+
sorted=("${entries[@]}")
663+
fi
639664

640-
# if packages then sort descending
641-
if [[ "${path}" == "sources/packages" ]] || [[ "${path}" == "tests/packages" ]]; then
642-
IFS=$'\n' sorted=($(sort -r <<<"${entries[*]}")); unset IFS
643-
else
644-
sorted=("${entries[@]}")
645-
fi
646665

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

648-
for entry in "${sorted[@]}"; do
649-
file=$(basename "${entry}")
670+
if [[ "${path}" == "tables" ]]; then
671+
skipfile="FALSE"
672+
table_changes="TRUE"
650673

651-
if [[ "${path}" == "tables" ]]; then
652-
skipfile="FALSE"
653-
table_changes="TRUE"
654-
655-
if [[ "${mode}" == "patch" ]]; then
656-
if [[ -d "${targetpath}/db/${schema}/tables/tables_ddl" ]]; then
657-
for f in "${targetpath}/db/${schema}/tables/tables_ddl"/${file%%.*}.*; do
658-
if [[ -e "$f" ]]; then
659-
skipfile="TRUE"
660-
fi
661-
done
674+
# store tablename in array
675+
table_name="${file%%.*}"
676+
table_array+=( ${table_name} )
677+
678+
if [[ "${mode}" == "patch" ]]; then
679+
if [[ -d "${targetpath}/db/${schema}/tables/tables_ddl" ]]; then
680+
for f in "${targetpath}/db/${schema}/tables/tables_ddl"/${file%%.*}.*; do
681+
if [[ -e "$f" ]]; then
682+
skipfile="TRUE"
683+
fi
684+
done
685+
fi
662686
fi
663-
fi
664687

665-
if [[ "$skipfile" == "TRUE" ]]; then
666-
echo "Prompt ... skipped ${file}" >> "${target_install_file}"
667-
else
668-
echo "Prompt >>> db/${schema}/${path}/${file}" >> "${target_install_file}"
669-
echo "@@${path}/${file}" >> "${target_install_file}"
670-
echo "Prompt <<< db/${schema}/${path}/${file}" >> "${target_install_file}"
671-
fi
672-
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}"
688+
if [[ "$skipfile" == "TRUE" ]]; then
689+
echo "Prompt ... skipped ${file}"
690+
else
691+
echo "Prompt >>> db/${schema}/${path}/${file}"
692+
echo "@@${path}/${file}"
693+
echo "Prompt <<< db/${schema}/${path}/${file}"
694+
fi
678695
else
679-
echo "@@${path}/${file}" >> "${target_install_file}"
680-
echo "Prompt <<< db/${schema}/${path}/${file}" >> "${target_install_file}"
681-
fi
682-
fi
683-
done
684696

685-
if [[ "${path}" == "ddl/patch/pre" ]] || [[ "${path}" == "ddl/patch/pre_tst" ]] || [[ "${path}" == "ddl/patch/pre_uat" ]]|| [[ "${path}" == "views" ]]
686-
then
687-
echo "WHENEVER SQLERROR EXIT SQL.SQLCODE" >> "${target_install_file}"
688-
fi
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"
701+
for table_item in "${table_set[@]}"
702+
do
703+
echo "Prompt >>> db/${schema}/${path}/${file} ${version} ${mode} ${table_item}.sql"
704+
echo "@@${path}/${file} ${version} ${mode} ${table_item}.sql"
705+
echo "Prompt <<< db/${schema}/${path}/${file} ${version} ${mode} ${table_item}.sql"
706+
done
707+
echo "Prompt"
708+
echo ""
709+
fi
710+
else
711+
712+
echo "Prompt >>> db/${schema}/${path}/${file}"
713+
if [[ "${path}" == "ddl/pre_tst" ]] && [[ "${mode}" == "patch" ]]; then
714+
echo "--tst@@${path}/${file}"
715+
elif [[ "${path}" == "ddl/pre_uat" ]] && [[ "${mode}" == "patch" ]]; then
716+
echo "--uat@@${path}/${file}"
717+
else
718+
echo "@@${path}/${file}"
719+
echo "Prompt <<< db/${schema}/${path}/${file}"
720+
fi
689721

722+
fi
723+
fi
724+
done #files in folder (sorted)
690725

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
691731

692-
# post folder hooks
693-
echo "Prompt" >> "${target_install_file}"
694-
entries=("${targetpath}/db/${schema}/.hooks/post/${path}"/*.*)
695-
for entry in "${entries[@]}"; do
696-
file=$(basename "${entry}")
732+
if [[ "${path}" == "ddl/patch/pre" ]] || [[ "${path}" == "ddl/patch/pre_tst" ]] || [[ "${path}" == "ddl/patch/pre_uat" ]]|| [[ "${path}" == "views" ]]
733+
then
734+
echo "WHENEVER SQLERROR EXIT SQL.SQLCODE"
735+
fi
697736

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}"
703737

704-
done
738+
# post folder hooks
739+
echo "Prompt"
740+
entries=("${targetpath}/db/${schema}/.hooks/post/${path}"/*.*)
741+
for entry in "${entries[@]}"; do
742+
file=$(basename "${entry}")
743+
file_ext=${file#*.}
705744

706-
# set scan to off, to make use of vars inside main schema-hooks
707-
if [[ "${path}" == ".hooks/pre" ]] || [[ "${path}" == ".hooks/post" ]]; then
708-
echo "set scan off" >> "${target_install_file}"
709-
fi
745+
if [[ "${file_ext}" == "tables.sql" ]]; then
710746

711-
echo "Prompt" >> "${target_install_file}"
712-
echo "Prompt" >> "${target_install_file}"
713-
echo "" >> "${target_install_file}"
714-
fi
715-
done #path
747+
if [ ${#table_set[@]} -gt 0 ]; then
748+
echo "Prompt running .hooks/post/${path}/${file} with table set"
749+
for table_item in "${table_set[@]}"
750+
do
751+
echo "Prompt >>> db/${schema}/.hooks/post/${path}/${file} ${version} ${mode} ${table_item}.sql"
752+
echo "@@.hooks/post/${path}/${file} ${version} ${mode} ${table_item}.sql"
753+
echo "Prompt <<< db/${schema}/.hooks/post/${path}/${file} ${version} ${mode} ${table_item}.sql"
754+
done
755+
echo "Prompt"
756+
echo ""
757+
fi
716758

717-
echo "prompt compiling schema" >> "${target_install_file}"
718-
echo "exec dbms_utility.compile_schema(schema => user, compile_all => false);" >> "${target_install_file}"
719-
echo "exec dbms_session.reset_package" >> "${target_install_file}"
759+
else
760+
echo "Prompt >>> db/${schema}/.hooks/post/${path}/${file}"
761+
echo "@@.hooks/post/${path}/${file}"
762+
echo "Prompt <<< db/${schema}/.hooks/post/${path}/${file}"
763+
fi
764+
done
720765

721-
echo "Prompt" >> "${target_install_file}"
722-
echo "Prompt" >> "${target_install_file}"
723-
echo "exit" >> "${target_install_file}"
766+
# set scan to off, to make use of vars inside main schema-hooks
767+
if [[ "${path}" == ".hooks/pre" ]] || [[ "${path}" == ".hooks/post" ]]; then
768+
echo "set scan off"
769+
fi
724770

771+
echo "Prompt"
772+
echo "Prompt"
773+
echo ""
774+
} >> "${target_install_file}"
775+
fi #path exists
776+
done #paths
777+
778+
{
779+
echo "prompt compiling schema"
780+
echo "exec dbms_utility.compile_schema(schema => user, compile_all => false);"
781+
echo "exec dbms_session.reset_package"
782+
783+
echo "Prompt"
784+
echo "Prompt"
785+
echo "exit"
786+
} >> "${target_install_file}"
725787
else
726788
echo " .. db/${schema} does not exist in ${targetpath}"
727789
fi

0 commit comments

Comments
 (0)