-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #92 from mrysav/db-structure-files
Add V2 Lab Backup Management Interface for cloud
- Loading branch information
Showing
67 changed files
with
38,932 additions
and
1,886 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 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,16 @@ | ||
#!/bin/bash | ||
|
||
ROOT="$(dirname "$0")" | ||
|
||
set -a | ||
source "$ROOT/env" | ||
set +a | ||
|
||
create_database blis_revamp | ||
execute_sql blis_revamp "$ROOT/../structure/blis_revamp.sql" | ||
|
||
create_database "blis_12" | ||
execute_sql blis_12 "$ROOT/../structure/blis_12.sql" | ||
|
||
create_database blis_127 | ||
execute_sql blis_127 "$ROOT/../structure/blis_127.sql" |
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,35 @@ | ||
#!/bin/bash | ||
|
||
set -euo pipefail | ||
|
||
ROOT="$(dirname "$0")" | ||
|
||
set -a | ||
source "$ROOT/env" | ||
set +a | ||
|
||
function escape_string() | ||
{ | ||
printf '%s' "$1" | sed -e 's/[][\\^*+.$-%]//g' | sed -e 's/ /_/g' | ||
} | ||
|
||
type="${1,,}" | ||
|
||
if ! { [[ "$type" = "lab" ]] || [[ "$type" = "revamp" ]] ;}; then | ||
echo "The first parameter must be either 'lab' or 'revamp'." | ||
exit 1 | ||
fi | ||
|
||
if [[ -z "$2" ]]; then | ||
echo "Must provide a migration name." | ||
exit 1 | ||
fi | ||
|
||
migration_name="$(escape_string "${2,,}")" | ||
|
||
filename="$(date -u +"%Y%m%d%H%M%S")_$migration_name.sql" | ||
fullpath="$ROOT/../migrations/$type/$filename" | ||
|
||
touch "$fullpath" | ||
|
||
echo -e "Created $(realpath "$fullpath")" |
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,11 @@ | ||
#!/bin/bash | ||
|
||
ROOT="$(dirname "$0")" | ||
|
||
set -a | ||
source "$ROOT/env" | ||
set +a | ||
|
||
drop_database blis_revamp | ||
drop_database blis_12 | ||
drop_database blis_127 |
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,12 @@ | ||
#!/bin/bash | ||
|
||
ROOT="$(dirname "$0")" | ||
|
||
set -a | ||
source "$ROOT/env" | ||
set +a | ||
|
||
# blis_12 is not dumped here since it is a database used for testing upgrades | ||
# in other words, we want the structure file to be outdated | ||
dump_database blis_revamp | ||
dump_database blis_127 |
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,39 @@ | ||
#shellcheck shell=bash | ||
|
||
export DB_HOST="${DB_HOST:-db}" | ||
export DB_PORT="${DB_PORT:-3306}" | ||
export DB_USER="${DB_USER:-root}" | ||
export DB_PASS="${DB_PASS:-blis123}" | ||
|
||
function create_database { | ||
local DATABASE_NAME="$1" | ||
mysql -h"$DB_HOST" --port "$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -e "CREATE DATABASE $DATABASE_NAME CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" | ||
} | ||
export create_database | ||
|
||
function drop_database { | ||
local DATABASE_NAME="$1" | ||
mysql -h"$DB_HOST" --port "$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -e "SET FOREIGN_KEY_CHECKS=0; DROP DATABASE $DATABASE_NAME; SET FOREIGN_KEY_CHECKS=1;" | ||
echo -e "Dropped $DATABASE_NAME" | ||
} | ||
export drop_database | ||
|
||
function execute_sql { | ||
local DATABASE_NAME="$1" | ||
local SQL_FILE="$2" | ||
|
||
mysql -h"$DB_HOST" --port "$DB_PORT" -u"$DB_USER" -p"$DB_PASS" "$DATABASE_NAME" < "$SQL_FILE" | ||
} | ||
export execute_sql | ||
|
||
function dump_database { | ||
local DATABASE_NAME="$1" | ||
local ROOT | ||
ROOT="$(dirname "$0")" | ||
|
||
mysqldump -h"$DB_HOST" --port "$DB_PORT" -u"$DB_USER" -p"$DB_PASS" --no-data --no-create-db --skip-add-drop-table "$DATABASE_NAME" | sed 's/ AUTO_INCREMENT=[0-9]*//g' > "$ROOT/../structure/$DATABASE_NAME.sql" | ||
sed -i "s/CREATE TABLE \`/CREATE TABLE IF NOT EXISTS \`/g" "$ROOT/../structure/$DATABASE_NAME.sql" | ||
|
||
mysqldump -h"$DB_HOST" --port "$DB_PORT" -u"$DB_USER" -p"$DB_PASS" --no-create-info --skip-add-drop-table --skip-extended-insert --compact "$DATABASE_NAME" > "$ROOT/../seed/$DATABASE_NAME.sql" | ||
} | ||
export dump_database |
Oops, something went wrong.