Skip to content

Commit

Permalink
Merge pull request #92 from mrysav/db-structure-files
Browse files Browse the repository at this point in the history
Add V2 Lab Backup Management Interface for cloud
  • Loading branch information
mrysav authored Aug 30, 2024
2 parents 8e72a92 + 1be800f commit 0194a82
Show file tree
Hide file tree
Showing 67 changed files with 38,932 additions and 1,886 deletions.
3 changes: 3 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ FROM ubuntu:focal
# See the documentation here to see why devcontainers are awesome:
# https://code.visualstudio.com/docs/remote/containers

# Set environment variables here that will only be seen in development
ENV BLIS_LAB_BACKUPS_V2_ENABLED=1

# Install a bunch of stuff from the standard repositories and a custom PHP repository
# Namely, PHP 5.6
RUN apt-get update && apt-get install -y software-properties-common && \
Expand Down
6 changes: 1 addition & 5 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,5 @@
"service": "app",
"workspaceFolder": "/workspace",
"postCreateCommand": ".devcontainer/post-create-command.sh",
"postAttachCommand": "start-blis.sh",
"containerEnv": {
// These environment variables will only be set in development!
"BLIS_LAB_BACKUPS_V2_ENABLED": "1"
}
"postAttachCommand": "start-blis.sh"
}
159 changes: 0 additions & 159 deletions bin/backup-tool.php

This file was deleted.

16 changes: 16 additions & 0 deletions db/bin/create_all
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"
35 changes: 35 additions & 0 deletions db/bin/create_migration
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")"
11 changes: 11 additions & 0 deletions db/bin/drop_all
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
12 changes: 12 additions & 0 deletions db/bin/dump_all
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
39 changes: 39 additions & 0 deletions db/bin/env
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
Loading

0 comments on commit 0194a82

Please sign in to comment.