Skip to content

Commit

Permalink
lando/mysql#53: Address db-import error by quoting database name. Add…
Browse files Browse the repository at this point in the history
… tests.
  • Loading branch information
reynoldsalec committed Jun 5, 2024
1 parent 99c0e04 commit 92e7261
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
49 changes: 49 additions & 0 deletions examples/sql-helpers/.lando.sqlhelpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ services:
MYSQL_DATABASE: lando_test
MARIADB_USER: test
MARIADB_PASSWORD: test
mariadb-default:
api: 3
type: lando
healthcheck: mysqladmin ping -h mariadb-default -u test -ptest
services:
image: bitnami/mariadb:10.4
command: /opt/bitnami/scripts/mariadb/entrypoint.sh /opt/bitnami/scripts/mariadb/run.sh
environment:
ALLOW_EMPTY_PASSWORD: yes
MYSQL_DATABASE: database
MYSQL_USER: test
MYSQL_PASSWORD: test

mysql57:
api: 3
Expand All @@ -27,6 +39,19 @@ services:
MYSQL_DATABASE: lando_test
MYSQL_PASSWORD: test
MYSQL_USER: test
mysql57-default:
api: 3
type: lando
healthcheck: mysqladmin ping -h mysql57 -u test -ptest
services:
image: bitnami/mysql:5.7
command: /opt/bitnami/scripts/mysql/entrypoint.sh /opt/bitnami/scripts/mysql/run.sh
environment:
ALLOW_EMPTY_PASSWORD: yes
MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
MYSQL_DATABASE: database
MYSQL_PASSWORD: test
MYSQL_USER: test

mysql80:
api: 3
Expand All @@ -41,6 +66,19 @@ services:
MYSQL_DATABASE: lando_test
MYSQL_PASSWORD: test
MYSQL_USER: test
mysql80-default:
api: 3
type: lando
healthcheck: mysqladmin ping -h mysql80 -u test -ptest
services:
image: bitnami/mysql:8.0
command: /opt/bitnami/scripts/mysql/entrypoint.sh /opt/bitnami/scripts/mysql/run.sh
environment:
ALLOW_EMPTY_PASSWORD: yes
MYSQL_AUTHENTICATION_PLUGIN: caching_sha2_password
MYSQL_DATABASE: database
MYSQL_PASSWORD: test
MYSQL_USER: test

postgres16:
api: 3
Expand All @@ -53,6 +91,17 @@ services:
ALLOW_EMPTY_PASSWORD: yes
POSTGRESQL_DATABASE: lando_test
POSTGRES_DB: lando_test
postgres16-default:
api: 3
type: lando
healthcheck: pg_isready -h postgres16 -U postgres
services:
image: bitnami/postgresql:16
command: /opt/bitnami/scripts/postgresql/entrypoint.sh /opt/bitnami/scripts/postgresql/run.sh
environment:
ALLOW_EMPTY_PASSWORD: yes
POSTGRESQL_DATABASE: database
POSTGRES_DB: database

plugins:
"@lando/core": "../../.."
20 changes: 20 additions & 0 deletions examples/sql-helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,41 @@ cd sqlhelpers
lando ssh -s mariadb -c "/helpers/sql-import.sh testdata1.sql"
lando ssh -s mariadb -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original"

# Should import test data into mariadb-default
cd sqlhelpers
lando ssh -s mariadb-default -c "/helpers/sql-import.sh testdata1.sql"
lando ssh -s mariadb-default -c "mysql -utest -ptest \`database\` -e 'select * from lando_test'" | grep "lando_original"

# Should import test data into mysql57
cd sqlhelpers
lando ssh -s mysql57 -c "/helpers/sql-import.sh testdata1.sql"
lando ssh -s mysql57 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original"

# Should import test data into mysql57-default
cd sqlhelpers
lando ssh -s mysql57-default -c "/helpers/sql-import.sh testdata1.sql"
lando ssh -s mysql57-default -c "mysql -utest -ptest \`database\` -e 'select * from lando_test'" | grep "lando_original"

# Should import test data into mysql80
cd sqlhelpers
lando ssh -s mysql80 -c "/helpers/sql-import.sh testdata1.sql"
lando ssh -s mysql80 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original"

# Should import test data into mysql80-default
cd sqlhelpers
lando ssh -s mysql80-default -c "/helpers/sql-import.sh testdata1.sql"
lando ssh -s mysql80-default -c "mysql -utest -ptest \`database\` -e 'select * from lando_test'" | grep "lando_original"

# Should import test data into postgres16
cd sqlhelpers
lando ssh -s postgres16 -c "/helpers/sql-import.sh testdata1.sql"
lando ssh -s postgres16 -c "psql -U postgres -d lando_test -c 'select * from lando_test'" | grep "lando_original"

# Should import test data into postgres16-default
cd sqlhelpers
lando ssh -s postgres16-default -c "/helpers/sql-import.sh testdata1.sql"
lando ssh -s postgres16-default -c "psql -U postgres -d database -c 'select * from lando_test'" | grep "lando_original"

# Should export gzipped files from mariadb
cd sqlhelpers
lando ssh -s mariadb -c "/helpers/sql-export.sh mariadb_dump.sql" -u root
Expand Down
5 changes: 3 additions & 2 deletions scripts/sql-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ if [ "$WIPE" == "true" ]; then
SQLSTART="mysql -h $HOST -P $PORT -u $USER ${LANDO_EXTRA_DB_IMPORT_ARGS}"

# Drop and recreate database
$SQLSTART -e "DROP DATABASE IF EXISTS ${DATABASE}"
$SQLSTART -e "CREATE DATABASE ${DATABASE}"
echo ${SQLSTART} ${DATABASE}
$SQLSTART -e "DROP DATABASE IF EXISTS \`${DATABASE}\`"
$SQLSTART -e "CREATE DATABASE \`${DATABASE}\`"
fi
fi

Expand Down

0 comments on commit 92e7261

Please sign in to comment.