Skip to content

Commit

Permalink
Merge pull request #48 from covermymeds/add_plugin_support
Browse files Browse the repository at this point in the history
added plugin support
  • Loading branch information
cjestel authored Apr 7, 2017
2 parents 217c37c + 19bbf42 commit bffdfeb
Show file tree
Hide file tree
Showing 14 changed files with 274 additions and 21 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 2016-05-18 Release 1.3.1
### Summary
Add plugin support and Git plugin

### Changes
- Added plugin functionality
- Added plugin for Git
- Adjusted the way auto deploy folders work in db_report_string dbtype functions
- Auto deploy will not redeploy a file from master automatically if it has had a checksum that has been deployed in the past (this protects a situation where an environment is ahead of master, you can force a deploy of an auto deploy file still by using the -f flag with the path to the file).

## 2016-05-18 Release 1.2.1
### Summary
Bug fix
Expand Down
12 changes: 11 additions & 1 deletion config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ db_basedir='/var/lib/dbdeployer/databases'
#them somewhere else for whatever reason, you can update the path here
fn_basedir='/usr/libexec/dbdeployer'

#this is where the modules or plugin directories should be deployed. Just
#copy any plugin directories to this location and reference them in the
#order in which they should be loaded using the -m|--module-list variable
module_basedir='/usr/libexec/dbdeployer/plugins'

#this is the variable that holds the list of plugins to load. They are loaded
#in the order specified, so the last plugin listed would win if two plugins
#override the same function
module_list=

#user to make sure the script is being run as
run_as='postgres'

Expand Down Expand Up @@ -78,7 +88,7 @@ auto_deploy_folders_enabled='false'
#folders that will include files in report when changes are found based on checksum
#Requires calculate_checksum option to be set to true. These folders are deployed
#after the list of deployment_folders.
auto_deploy_folders='sprocs:|functions:|utility'
auto_deploy_folders='sprocs:|functions:|views:|synonyms:|triggers'

#environment exclusion list (add folders inside database dir that aren't environments)
env_exclude="/:|output:|archive:|rollback:|grants:|thesaurus"
Expand Down
9 changes: 9 additions & 0 deletions dbdeployer
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ do
skip_cli='-k'
shift
;;
-m|--module-list)
shift
module_list="${1}"
module_list_cli="-m ${1}"
shift
;;
-n|--db-destination-name)
shift
db_destination_name=${1}
Expand Down Expand Up @@ -196,6 +202,9 @@ done
#autoload various files
load_functions_in_dirs "${fn_basedir}/functions|${fn_basedir}/dbtype/${dbtype}"

#load plugins/modules
setup_module_source_list

#combine complete list of folders to be excluded
env_exclude="${env_exclude}:|${deployment_folders}:|${auto_deploy_folders}"

Expand Down
9 changes: 9 additions & 0 deletions dbdeployer_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ config_base_dir='/etc' #location to insta
config_dir="${config_base_dir}/${package_name}" #full path to config dir
function_base_dir='/usr/libexec' #location to install functions dir
function_dir="${function_base_dir}/${package_name}" #full path to functions dir
plugin_dir="${function_dir}" #location for plugin/module directory
log_dir="/var/log/${package_name}" #default log location
group_name='dbdeployer' #name of the group (used for log file permission)

Expand Down Expand Up @@ -93,6 +94,14 @@ then
exit 1
fi #end error check

#copy pluginsdirectory
cp -R 'plugins' ${plugin_dir}
if [ $? -ne 0 ]
then
echo "Failed to copy plugin directory, exiting"
exit 1
fi #end error check

#copy functions directory
cp -R 'functions' ${function_dir}
if [ $? -ne 0 ]
Expand Down
2 changes: 1 addition & 1 deletion dbdeployer_release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.2.1
version=1.3.1
29 changes: 24 additions & 5 deletions dbtype/mssql/db_report_string.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
db_report_string() {
_deployment_type="$1"
_include_checksum="$2"
_deployment_type="${1}"
_include_checksum="${2}"
_is_autodeploy="${3}"

deployment_tracker_table_exists

Expand All @@ -13,14 +14,32 @@ db_report_string() {

if [ $? -eq 0 ]
then
${db_binary} -d ${deployment_db} ${server_flag}${port_flag} ${user_flag} ${password_flag} -l0 -h -1 -b -Q "

_sqlstring="
SET NOCOUNT ON;
SELECT '${db_basedir}/' + '${dbname}' + '/' + deployment_type + '/' + deployment_name${checksum_value}
FROM deployment_tracker
WHERE dbname = '${db_destination_name}'
AND isnull(is_active, 1)=1
AND deployment_type = '${_deployment_type}'
AND deployment_outcome in ('OK','SKIP');" | sort -rn
AND deployment_outcome in ('OK','SKIP')
AND (
isnull(is_active, 1)=1
"

if [[ "${auto_deploy_folders_enabled}" = 'true' && "${is_auto_deploy}" = 'true' ]]
then
_sqlstring="${_sqlstring}
OR·
deployment_type IN ('${_deployment_type}')
"
fi
_sqlstring="${_sqlstring}
);
"

${db_binary} -d ${deployment_db} ${server_flag}${port_flag} ${user_flag} ${password_flag} -l0 -h -1 -b -Q "
${_sqlstring}
" | sort -rn

if [ $? -ne 0 ]
then
Expand Down
27 changes: 22 additions & 5 deletions dbtype/mysql/db_report_string.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
db_report_string() {
_deployment_type="$1"
_include_checksum="$2"
_deployment_type="${1}"
_include_checksum="${2}"
_is_autodeploy="${3}"

deployment_tracker_table_exists

Expand All @@ -14,14 +15,30 @@ db_report_string() {

if [ $? -eq 0 ]
then
${db_binary} ${deployment_db} ${server_flag} ${user_flag} ${port_flag} -N -s --skip-pager -e "

_sqlstring="
SELECT CONCAT('${db_basedir}/','${dbname}','/',deployment_type,'/',deployment_name${checksum_value})
FROM deployment_tracker
WHERE dbname = '${db_destination_name}'
AND deployment_type = '${_deployment_type}'
AND deployment_outcome in ('OK','SKIP')
AND is_active is true;" | sort -rn
AND (
is_active is true
"

if [[ "${auto_deploy_folders_enabled}" = 'true' && "${is_auto_deploy}" = 'true' ]]
then
_sqlstring="${_sqlstring}
OR·
deployment_type IN ('${_deployment_type}')
"
fi
_sqlstring="${_sqlstring}
);
"

${db_binary} ${deployment_db} ${server_flag} ${user_flag} ${port_flag} -N -s --skip-pager -e "
${_sqlstring}" | sort -rn

if [ $? -ne 0 ]
then
Expand Down
32 changes: 25 additions & 7 deletions dbtype/postgres/db_report_string.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
db_report_string() {
_deployment_type="$1"
_include_checksum="$2"
_deployment_type="${1}"
_include_checksum="${2}"
_is_autodeploy="${3}"

deployment_tracker_table_exists

Expand All @@ -14,14 +15,30 @@ db_report_string() {

if [ $? -eq 0 ]
then

${db_binary} ${deployment_db} ${server_flag} ${user_flag} ${port_flag} -1 -X -q -A -t -c "
_sqlstring="
SELECT CONCAT('${db_basedir}/','${dbname}','/',deployment_type,'/',deployment_name${checksum_value})
FROM deployment_tracker
WHERE dbname = '${db_destination_name}'
AND deployment_type = '${_deployment_type}'
AND deployment_outcome in ('OK','SKIP')
AND is_active is true;" | sort -rn
AND deployment_outcome IN ('OK','SKIP')
AND deployment_type = '${_deployment_type}'
AND (
is_active is true
"

if [[ "${auto_deploy_folders_enabled}" = 'true' && "${is_auto_deploy}" = 'true' ]]
then
_sqlstring="${_sqlstring}
OR
deployment_type IN ('${_deployment_type}')
"
fi
_sqlstring="${_sqlstring}
);
"

${db_binary} ${deployment_db} ${server_flag} ${user_flag} ${port_flag} -1 -X -q -A -t -c "
${_sqlstring}
" | sort -rn

if [ $? -ne 0 ]
then
Expand All @@ -38,6 +55,7 @@ db_report_string() {
fi
fi

#echo ${_sqlstring}
unset _deployment_type

return ${return_val}
Expand Down
2 changes: 1 addition & 1 deletion functions/deployment_report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ deployment_report() {
if [ -d "${deploy_folder}" ]
then
echo "Differences for ${i}:"
DB=`eval "db_report_string '${i}' 'true'"`
DB=`eval "db_report_string '${i}' 'true' 'true'"`


if [ `ls "${deploy_folder}"/ | grep ".sql" | wc -l | xargs` -gt 0 ]
Expand Down
30 changes: 30 additions & 0 deletions functions/setup_module_source_list.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
function setup_module_source_list() {

old_IFS=$IFS

IFS=','
local module_dir_array=(${module_list})
local module_array_count=`echo ${#module_dir_array[@]}`

#echo "module_list: $module_list"
#echo "module_array_count: $module_array_count"

if [ ${module_array_count} -gt 0 ]
then
for ((i=0; i<${module_array_count}; i++))
do
# check if directory exists
local plugin_dir="${module_basedir}/${module_dir_array[${i}]}"
if [ -d ${plugin_dir} ]
then
load_functions_in_dirs "${plugin_dir}"
echo "Loaded Plugin ${module_dir_array[${i}]}"
else
echo "Plugin dir ${plugin_dir} was not found, skipping"
fi
done
fi
IFS=${old_IFS}

}
2 changes: 1 addition & 1 deletion functions/update_db_to_current.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function update_db_to_current() {
_dbname="$1"
_db_destination_name="$2"

report_var=`${script_name} -D ${db_basedir} -r -d "${_dbname}" -n "${_db_destination_name}" ${environment_flag} ${server_cli} ${port_cli} ${dbuser_cli} ${password_cli} ${skip_cli} ${dbtype_cli} | grep "${script_name} -f"`
report_var=`${script_name} -D ${db_basedir} -r -d "${_dbname}" -n "${_db_destination_name}" ${environment_flag} ${server_cli} ${port_cli} ${dbuser_cli} ${password_cli} ${skip_cli} ${dbtype_cli} ${module_list_cli} | grep "${script_name} -f"`
IFS=$'\n'
for j in `echo -e "${report_var}"`
do
Expand Down
4 changes: 4 additions & 0 deletions functions/usage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function usage() {
still written to deployment_tracker
(can be used if file was deployed by a
different machanism)
-m|--module-list Module or plugin directories to load. Should be a
comma seperated list. List module specified last
will be applied for functions that are redundant in
module list (example: git,report_override)
-n|--db-destination-name [name] Deploy a database (-d) to a specific destination db,
useful for when the source name does not match the
final name of the database to be created.
Expand Down
Loading

0 comments on commit bffdfeb

Please sign in to comment.