From 92e726176c75fa44e9334663ca77af89014fcd5c Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Wed, 5 Jun 2024 10:56:59 -0700 Subject: [PATCH 1/4] lando/mysql#53: Address db-import error by quoting database name. Add tests. --- examples/sql-helpers/.lando.sqlhelpers.yml | 49 ++++++++++++++++++++++ examples/sql-helpers/README.md | 20 +++++++++ scripts/sql-import.sh | 5 ++- 3 files changed, 72 insertions(+), 2 deletions(-) diff --git a/examples/sql-helpers/.lando.sqlhelpers.yml b/examples/sql-helpers/.lando.sqlhelpers.yml index 42acb1eac..91c71a1e1 100644 --- a/examples/sql-helpers/.lando.sqlhelpers.yml +++ b/examples/sql-helpers/.lando.sqlhelpers.yml @@ -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 @@ -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 @@ -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 @@ -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": "../../.." diff --git a/examples/sql-helpers/README.md b/examples/sql-helpers/README.md index 8be680250..1589ca7bd 100644 --- a/examples/sql-helpers/README.md +++ b/examples/sql-helpers/README.md @@ -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 diff --git a/scripts/sql-import.sh b/scripts/sql-import.sh index 6db2c2b7f..a0192a689 100755 --- a/scripts/sql-import.sh +++ b/scripts/sql-import.sh @@ -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 From 4adac524e43bda274866db8fb3e65037817a13ec Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Wed, 5 Jun 2024 11:06:06 -0700 Subject: [PATCH 2/4] lando/mysql#53: Update the tests with correct hostnames/envvars. --- examples/sql-helpers/.lando.sqlhelpers.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/sql-helpers/.lando.sqlhelpers.yml b/examples/sql-helpers/.lando.sqlhelpers.yml index 91c71a1e1..6e9adb8f1 100644 --- a/examples/sql-helpers/.lando.sqlhelpers.yml +++ b/examples/sql-helpers/.lando.sqlhelpers.yml @@ -22,9 +22,10 @@ services: command: /opt/bitnami/scripts/mariadb/entrypoint.sh /opt/bitnami/scripts/mariadb/run.sh environment: ALLOW_EMPTY_PASSWORD: yes + MARIADB_DATABASE: database MYSQL_DATABASE: database - MYSQL_USER: test - MYSQL_PASSWORD: test + MARIADB_USER: test + MARIADB_PASSWORD: test mysql57: api: 3 @@ -42,7 +43,7 @@ services: mysql57-default: api: 3 type: lando - healthcheck: mysqladmin ping -h mysql57 -u test -ptest + healthcheck: mysqladmin ping -h mysql57-default -u test -ptest services: image: bitnami/mysql:5.7 command: /opt/bitnami/scripts/mysql/entrypoint.sh /opt/bitnami/scripts/mysql/run.sh @@ -69,7 +70,7 @@ services: mysql80-default: api: 3 type: lando - healthcheck: mysqladmin ping -h mysql80 -u test -ptest + healthcheck: mysqladmin ping -h mysql80-default -u test -ptest services: image: bitnami/mysql:8.0 command: /opt/bitnami/scripts/mysql/entrypoint.sh /opt/bitnami/scripts/mysql/run.sh @@ -94,7 +95,7 @@ services: postgres16-default: api: 3 type: lando - healthcheck: pg_isready -h postgres16 -U postgres + healthcheck: pg_isready -h postgres16-default -U postgres services: image: bitnami/postgresql:16 command: /opt/bitnami/scripts/postgresql/entrypoint.sh /opt/bitnami/scripts/postgresql/run.sh From cea92a40e8bf489260d06e206039d9bbdf49a074 Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Thu, 6 Jun 2024 10:43:28 -0700 Subject: [PATCH 3/4] lando/mysql#53: Fix core test issue. Remove debugging code. --- examples/sql-helpers/README.md | 6 +++--- package-lock.json | 2 +- scripts/sql-import.sh | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/examples/sql-helpers/README.md b/examples/sql-helpers/README.md index 1589ca7bd..ea004c0a7 100644 --- a/examples/sql-helpers/README.md +++ b/examples/sql-helpers/README.md @@ -29,7 +29,7 @@ lando ssh -s mariadb -c "mysql -utest -ptest lando_test -e 'select * from lando_ # 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" +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 @@ -39,7 +39,7 @@ lando ssh -s mysql57 -c "mysql -utest -ptest lando_test -e 'select * from lando_ # 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" +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 @@ -49,7 +49,7 @@ lando ssh -s mysql80 -c "mysql -utest -ptest lando_test -e 'select * from lando_ # 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" +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 diff --git a/package-lock.json b/package-lock.json index 670185bb2..a42088612 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "@lando/core", - "version": "3.21.0-beta.14", + "version": "3.21.0", "license": "GPL-3.0", "dependencies": { "@npmcli/arborist": "^6.2.9", diff --git a/scripts/sql-import.sh b/scripts/sql-import.sh index a0192a689..2266cb8a5 100755 --- a/scripts/sql-import.sh +++ b/scripts/sql-import.sh @@ -108,7 +108,6 @@ if [ "$WIPE" == "true" ]; then SQLSTART="mysql -h $HOST -P $PORT -u $USER ${LANDO_EXTRA_DB_IMPORT_ARGS}" # Drop and recreate database - echo ${SQLSTART} ${DATABASE} $SQLSTART -e "DROP DATABASE IF EXISTS \`${DATABASE}\`" $SQLSTART -e "CREATE DATABASE \`${DATABASE}\`" fi From f0b0d4d00df97f66c839ce38e550459d0f9ff52c Mon Sep 17 00:00:00 2001 From: Alec Reynolds Date: Thu, 6 Jun 2024 21:14:07 -0700 Subject: [PATCH 4/4] Update changelog. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 877da0853..85a3f0fc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }}) +### Bug Fixes + +* Fixed issue with importing databases to a service with the "default" `database` named database. [lando/mysql#53](https://github.com/lando/mysql/issues/53) + ## v3.21.0 - [May 25, 2024](https://github.com/lando/core/releases/tag/v3.21.0) ### Bug Fixes