Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case for mysqldump deprecation #54

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions examples/tooling/.lando.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: lando-mariadb-tooling
services:
database:
type: mariadb:11.3
tooling:
'db-export-test [file]':
service: :host
cmd: bash ./scripts/sql-export.sh
user: 'root'
options:
host:
description: The database service to use
default: database
alias:
- h
stdout:
description: Dump database to stdout

# This is important because it lets lando know to test against the plugin in this repo
# DO NOT REMOVE THIS!
plugins:
"@lando/mariadb": ../..
38 changes: 38 additions & 0 deletions examples/tooling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
MariaDB Example
reynoldsalec marked this conversation as resolved.
Show resolved Hide resolved
===============

This example exists primarily to test the following documentation:

* [MariaDB Service](https://docs.devwithlando.io/tutorials/mariadb.html)

Start up tests
--------------

Run the following commands to get up and running with this example.

```bash
# Should start up successfully
lando poweroff
lando start
```

Verification commands
---------------------

Run the following commands to validate things are rolling as they should.

```bash
# Should not see deprecation warning on db-export
lando db-export-test --stdout | grep -vz "Deprecated"
```

Destroy tests
-------------

Run the following commands to trash this app like nothing ever happened.

```bash
# Should be destroyed with success
lando destroy -y
lando poweroff
```
93 changes: 93 additions & 0 deletions examples/tooling/scripts/sql-export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/bin/bash
set -e

# Get the lando logger
. /helpers/log.sh

# Set the module
LANDO_MODULE="sqlexport"

# Set generic things
HOST=localhost
SERVICE=$LANDO_SERVICE_NAME
STDOUT=false

# Get type-specific config
if [[ ${POSTGRES_DB} != '' ]]; then
DATABASE=${POSTGRES_DB:-database}
PORT=${LANDO_DB_EXPORT_PORT:-5432}
USER=${LANDO_DB_EXPORT_USER:-postgres}
else
DATABASE=${MYSQL_DATABASE:-database}
PORT=${LANDO_DB_EXPORT_PORT:-3306}
USER=${LANDO_DB_EXPORT_USER:-root}
fi

# Set the default filename
FILE=${DATABASE}.`date +"%Y-%m-%d-%s"`.sql

# PARSE THE ARGZZ
# TODO: compress the mostly duplicate code below?
while (( "$#" )); do
case "$1" in
# This doesn't do anything anymore
# we just keep it around for option validation
-h|--host|--host=*)
if [ "${1##--host=}" != "$1" ]; then
shift
else
shift 2
fi
;;
--stdout)
STDOUT=true
shift
;;
--)
shift
break
;;
-*|--*=)
shift
;;
*)
if [[ "$1" = /* ]]; then
FILE="${1//\\//}"
else
FILE="$(pwd)/${1//\\//}"
fi
shift
;;
esac
done

# Get type-specific dump cpmmand
reynoldsalec marked this conversation as resolved.
Show resolved Hide resolved
if [[ ${POSTGRES_DB} != '' ]]; then
DUMPER="pg_dump postgresql://$USER@localhost:$PORT/$DATABASE"
elif [[ ${MARIADB_DATABASE} != '' && -x $(command -v mariadb-dump) ]]; then
DUMPER="mariadb-dump --opt --user=${USER} --host=${HOST} --port=${PORT} ${LANDO_EXTRA_DB_EXPORT_ARGS} ${DATABASE}"
else
DUMPER="mysqldump --opt --user=${USER} --host=${HOST} --port=${PORT} ${LANDO_EXTRA_DB_EXPORT_ARGS} ${DATABASE}"
fi

# Do the dump to stdout
if [ "$STDOUT" == "true" ]; then
$DUMPER
else
# Inform the user of things
echo "Preparing to export $FILE from database '$DATABASE' on service '$SERVICE' as user $USER..."

# Clean up last dump before we dump again
unalias rm 2> /dev/null || true
rm -f ${FILE} 2> /dev/null
$DUMPER > ${FILE} || { rm -f ${FILE}; lando_red "Failed to create file: ${FILE}"; exit 1; }

# Gzip the mysql database dump file
gzip $FILE
# Reset perms on linux
if [ "$LANDO_HOST_OS" = "linux" ] && [ $(id -u) = 0 ]; then
chown $LANDO_HOST_UID:$LANDO_HOST_GID "${FILE}.gz"
fi
# Report
lando_green "Success ${FILE}.gz was created!"
fi
Loading