-
-
Notifications
You must be signed in to change notification settings - Fork 586
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
324 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
version: '3' | ||
services: | ||
boulder: | ||
environment: | ||
FAKE_DNS: 10.77.77.77 | ||
BOULDER_CONFIG_DIR: test/config-next | ||
GOFLAGS: -mod=vendor | ||
# This is required so Python doesn't throw an error when printing | ||
# non-ASCII to stdout. | ||
PYTHONIOENCODING: utf-8 | ||
# These are variables you can set to affect what tests get run or | ||
# how they are run. Including them here with no value means they are | ||
# passed through from the environment. | ||
RUN: "" | ||
INT_FILTER: "" | ||
RACE: "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../_db/dbconf.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../_db/migrations/19700101000000_CombinedSchema.sql |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
#!/usr/bin/env bash | ||
|
||
# -e Stops execution in the instance of a command or pipeline error | ||
# -u Treat unset variables as an error and exit immediately | ||
set -eu | ||
|
||
# Run all tests and coverage checks. Called from Travis automatically, also | ||
# suitable to run manually. See list of prerequisite packages in .travis.yml | ||
if type realpath >/dev/null 2>&1 ; then | ||
cd "$(realpath -- $(dirname -- "$0"))" | ||
fi | ||
|
||
# | ||
# Defaults | ||
# | ||
DB_NEXT_PATH="_db-next/migrations" | ||
esc=$'\033' | ||
aesc="${esc}[" # posix compliant escape sequence | ||
OUTCOME="ERROR" | ||
PROMOTE=() | ||
RUN=() | ||
|
||
# | ||
# Print Functions | ||
# | ||
function print_outcome() { | ||
if [ "$OUTCOME" == OK ] | ||
then | ||
echo -e "${aesc}0;32m""$OUTCOME""${aesc}0m" | ||
else | ||
echo -e "${aesc}0;31m""$OUTCOME""${aesc}0m" | ||
fi | ||
} | ||
|
||
function print_usage_exit() { | ||
echo "$USAGE" | ||
exit 0 | ||
} | ||
|
||
function print_heading() { | ||
echo | ||
echo -e "${aesc}0;34m"$1"${aesc}0m" | ||
} | ||
|
||
function print_from() { | ||
echo -e "from: ${aesc}0;36m"$1"${aesc}0m" | ||
} | ||
|
||
function print_to() { | ||
echo -e "to: ${aesc}0;32m"$1"${aesc}0m" | ||
} | ||
|
||
# | ||
# CLI Helper Functions | ||
# | ||
function check_arg() { | ||
if [ -z "$OPTARG" ] | ||
then | ||
exit_msg "No arg for --$OPT option, use: -h for help">&2 | ||
fi | ||
} | ||
|
||
function exit_msg() { | ||
# complain to STDERR and exit with error | ||
echo "$*" >&2 | ||
exit 2 | ||
} | ||
|
||
# | ||
# Utility Functions | ||
# | ||
function get_migrations() { | ||
migrations=( $(find $DB_NEXT_PATH -mindepth 1 -maxdepth 1 -not -path '*/\.*' -type "$1" 2> /dev/null | sort) ) | ||
if [ -z "${migrations[@]+x}" ] | ||
then | ||
echo "There are no migrations at path: "\"$DB_NEXT_PATH\""" | ||
exit 1 | ||
fi | ||
} | ||
|
||
function list_next() { | ||
print_heading "Next Schemas" | ||
get_migrations "f" | ||
iter=1 | ||
migopts=() | ||
for mig_file in "${migrations[@]}" | ||
do | ||
echo ""$iter") $(basename -- "${mig_file}")" | ||
migopts+=("$iter") | ||
iter=$(expr "$iter" + 1) | ||
done | ||
} | ||
|
||
function list_current() { | ||
print_heading "Current Schemas" | ||
get_migrations "l" | ||
iter=0 | ||
for mig_file in "${migrations[@]}" | ||
do | ||
echo "[$iter] $(basename -- "${mig_file}")" | ||
iter=$(expr $iter + 1) | ||
done | ||
} | ||
|
||
function promote_schema() { | ||
print_heading "Promote Schema" | ||
get_migrations "f" | ||
declare -a mig_index=() | ||
declare -A mig_file=() | ||
for i in "${!migrations[@]}"; do | ||
mig_index[$i]="${migrations[$i]%% *}" | ||
mig_file[${mig_index[$i]}]="${migrations[$i]#* }" | ||
done | ||
|
||
promote="" | ||
PS3='Which schema would you like to promote? (q to cancel): ' | ||
select opt in "${mig_index[@]}"; do | ||
case "$opt" in | ||
"") echo "Invalid option or cancelled, exiting..." ; break ;; | ||
*) promote="${mig_file[$opt]}" ; break ;; | ||
esac | ||
done | ||
if [ ! -z "$promote" ] | ||
then | ||
schema_name="$(basename -- "$promote")" | ||
promoted_path="_db/migrations/"$schema_name"" | ||
|
||
print_heading "Promoting Schema" | ||
print_from "$promote" | ||
print_to "$promoted_path" | ||
mv "$promote" "$promoted_path" | ||
ln -s "$(realpath "$promoted_path")" "$DB_NEXT_PATH" | ||
fi | ||
} | ||
|
||
function demote_schema() { | ||
print_heading "Demote Schema" | ||
get_migrations "l" | ||
declare -a mig_index=() | ||
declare -A mig_file=() | ||
for i in "${!migrations[@]}"; do | ||
mig_index[$i]="${migrations[$i]%% *}" | ||
mig_file[${mig_index[$i]}]="${migrations[$i]#* }" | ||
done | ||
|
||
demote="" | ||
PS3='Which schema would you like to demote? (q to cancel): ' | ||
select opt in "${mig_index[@]}"; do | ||
case "$opt" in | ||
"") echo "Invalid option or cancelled, exiting..." ; break ;; | ||
*) demote="${mig_file[$opt]}" ; break ;; | ||
esac | ||
done | ||
if [ ! -z "$demote" ] | ||
then | ||
schema_name="$(basename -- "$demote")" | ||
promoted_path="_db/migrations/"$schema_name"" | ||
|
||
print_heading "Demoting Schema" | ||
print_from "_db/migrations/"$schema_name"" | ||
print_to "$demote" | ||
rm "$demote" | ||
mv "$promoted_path" "$demote" | ||
fi | ||
} | ||
|
||
# | ||
# Main CLI Parser | ||
# | ||
USAGE="$(cat -- <<-EOM | ||
Usage: | ||
Boulder DB Migrations CLI: | ||
Helper for listing, promoting, and demoting Boulder schema files | ||
./$(basename "${0}") [OPTION]... | ||
-l, --list-next Lists schemas exclusively present in sa/db-next | ||
-c, --list-current Lists schemas exclusively present in sa/db | ||
-p, --promote Promotes a given schema from sa/db-next to sa/db | ||
-d, --demote Demotes a given schema from sa/db to sa/db-next | ||
-h, --help Shows this help message | ||
EOM | ||
)" | ||
|
||
while getopts nchpd-: OPT; do | ||
if [ "$OPT" = - ]; then # long option: reformulate OPT and OPTARG | ||
OPT="${OPTARG%%=*}" # extract long option name | ||
OPTARG="${OPTARG#$OPT}" # extract long option argument (may be empty) | ||
OPTARG="${OPTARG#=}" # if long option argument, remove assigning `=` | ||
fi | ||
case "$OPT" in | ||
n | list-next ) RUN+=("list_next") ;; | ||
c | list-current ) RUN+=("list_current") ;; | ||
p | promote ) RUN+=("promote") ;; | ||
d | demote ) RUN+=("demote") ;; | ||
h | help ) print_usage_exit ;; | ||
??* ) exit_msg "Illegal option --$OPT" ;; # bad long option | ||
? ) exit 2 ;; # bad short option (error reported via getopts) | ||
esac | ||
done | ||
shift $((OPTIND-1)) # remove parsed migrations and args from $@ list | ||
|
||
# On EXIT, trap and print outcome | ||
trap "print_outcome" EXIT | ||
|
||
STEP="list_next" | ||
if [[ "${RUN[@]}" =~ "$STEP" ]] ; then | ||
list_next | ||
fi | ||
|
||
STEP="list_current" | ||
if [[ "${RUN[@]}" =~ "$STEP" ]] ; then | ||
list_current | ||
fi | ||
|
||
STEP="promote" | ||
if [[ "${RUN[@]}" =~ "$STEP" ]] ; then | ||
promote_schema | ||
fi | ||
|
||
STEP="demote" | ||
if [[ "${RUN[@]}" =~ "$STEP" ]] ; then | ||
demote_schema | ||
fi | ||
|
||
|
||
# Because set -e stops execution in the instance of a command or pipeline | ||
# error; if we got here we assume success | ||
OUTCOME="OK" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.