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. (#173)

* lando/mysql#53: Address db-import error by quoting database name. Add tests.

* lando/mysql#53: Update the tests with correct hostnames/envvars.

* lando/mysql#53: Fix core test issue. Remove debugging code.

* Update changelog.
  • Loading branch information
reynoldsalec authored and pirog committed Oct 10, 2024
1 parent cdcb6f1 commit 9f1005f
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
50 changes: 50 additions & 0 deletions examples/sql-helpers/.lando.sqlhelpers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ 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
MARIADB_DATABASE: database
MYSQL_DATABASE: database
MARIADB_USER: test
MARIADB_PASSWORD: test

mysql57:
api: 3
Expand All @@ -27,6 +40,19 @@ services:
MYSQL_DATABASE: lando_test
MYSQL_PASSWORD: test
MYSQL_USER: test
mysql57-default:
api: 3
type: lando
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
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 +67,19 @@ services:
MYSQL_DATABASE: lando_test
MYSQL_PASSWORD: test
MYSQL_USER: test
mysql80-default:
api: 3
type: lando
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
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 +92,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-default -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
4 changes: 2 additions & 2 deletions scripts/sql-import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ 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}"
$SQLSTART -e "DROP DATABASE IF EXISTS \`${DATABASE}\`"
$SQLSTART -e "CREATE DATABASE \`${DATABASE}\`"
fi
fi

Expand Down

0 comments on commit 9f1005f

Please sign in to comment.