Skip to content

Commit df2f71a

Browse files
authored
lando/mysql#53: Address db-import error by quoting database name. Add 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.
1 parent 99c0e04 commit df2f71a

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## {{ UNRELEASED_VERSION }} - [{{ UNRELEASED_DATE }}]({{ UNRELEASED_LINK }})
22

3+
### Bug Fixes
4+
5+
* Fixed issue with importing databases to a service with the "default" `database` named database. [lando/mysql#53](https://github.com/lando/mysql/issues/53)
6+
37
## v3.21.0 - [May 25, 2024](https://github.com/lando/core/releases/tag/v3.21.0)
48

59
### Bug Fixes

examples/sql-helpers/.lando.sqlhelpers.yml

+50
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,19 @@ services:
1313
MYSQL_DATABASE: lando_test
1414
MARIADB_USER: test
1515
MARIADB_PASSWORD: test
16+
mariadb-default:
17+
api: 3
18+
type: lando
19+
healthcheck: mysqladmin ping -h mariadb-default -u test -ptest
20+
services:
21+
image: bitnami/mariadb:10.4
22+
command: /opt/bitnami/scripts/mariadb/entrypoint.sh /opt/bitnami/scripts/mariadb/run.sh
23+
environment:
24+
ALLOW_EMPTY_PASSWORD: yes
25+
MARIADB_DATABASE: database
26+
MYSQL_DATABASE: database
27+
MARIADB_USER: test
28+
MARIADB_PASSWORD: test
1629

1730
mysql57:
1831
api: 3
@@ -27,6 +40,19 @@ services:
2740
MYSQL_DATABASE: lando_test
2841
MYSQL_PASSWORD: test
2942
MYSQL_USER: test
43+
mysql57-default:
44+
api: 3
45+
type: lando
46+
healthcheck: mysqladmin ping -h mysql57-default -u test -ptest
47+
services:
48+
image: bitnami/mysql:5.7
49+
command: /opt/bitnami/scripts/mysql/entrypoint.sh /opt/bitnami/scripts/mysql/run.sh
50+
environment:
51+
ALLOW_EMPTY_PASSWORD: yes
52+
MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
53+
MYSQL_DATABASE: database
54+
MYSQL_PASSWORD: test
55+
MYSQL_USER: test
3056

3157
mysql80:
3258
api: 3
@@ -41,6 +67,19 @@ services:
4167
MYSQL_DATABASE: lando_test
4268
MYSQL_PASSWORD: test
4369
MYSQL_USER: test
70+
mysql80-default:
71+
api: 3
72+
type: lando
73+
healthcheck: mysqladmin ping -h mysql80-default -u test -ptest
74+
services:
75+
image: bitnami/mysql:8.0
76+
command: /opt/bitnami/scripts/mysql/entrypoint.sh /opt/bitnami/scripts/mysql/run.sh
77+
environment:
78+
ALLOW_EMPTY_PASSWORD: yes
79+
MYSQL_AUTHENTICATION_PLUGIN: caching_sha2_password
80+
MYSQL_DATABASE: database
81+
MYSQL_PASSWORD: test
82+
MYSQL_USER: test
4483

4584
postgres16:
4685
api: 3
@@ -53,6 +92,17 @@ services:
5392
ALLOW_EMPTY_PASSWORD: yes
5493
POSTGRESQL_DATABASE: lando_test
5594
POSTGRES_DB: lando_test
95+
postgres16-default:
96+
api: 3
97+
type: lando
98+
healthcheck: pg_isready -h postgres16-default -U postgres
99+
services:
100+
image: bitnami/postgresql:16
101+
command: /opt/bitnami/scripts/postgresql/entrypoint.sh /opt/bitnami/scripts/postgresql/run.sh
102+
environment:
103+
ALLOW_EMPTY_PASSWORD: yes
104+
POSTGRESQL_DATABASE: database
105+
POSTGRES_DB: database
56106

57107
plugins:
58108
"@lando/core": "../../.."

examples/sql-helpers/README.md

+20
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,41 @@ cd sqlhelpers
2626
lando ssh -s mariadb -c "/helpers/sql-import.sh testdata1.sql"
2727
lando ssh -s mariadb -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original"
2828

29+
# Should import test data into mariadb-default
30+
cd sqlhelpers
31+
lando ssh -s mariadb-default -c "/helpers/sql-import.sh testdata1.sql"
32+
lando ssh -s mariadb-default -c "mysql -utest -ptest database -e 'select * from lando_test'" | grep "lando_original"
33+
2934
# Should import test data into mysql57
3035
cd sqlhelpers
3136
lando ssh -s mysql57 -c "/helpers/sql-import.sh testdata1.sql"
3237
lando ssh -s mysql57 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original"
3338

39+
# Should import test data into mysql57-default
40+
cd sqlhelpers
41+
lando ssh -s mysql57-default -c "/helpers/sql-import.sh testdata1.sql"
42+
lando ssh -s mysql57-default -c "mysql -utest -ptest database -e 'select * from lando_test'" | grep "lando_original"
43+
3444
# Should import test data into mysql80
3545
cd sqlhelpers
3646
lando ssh -s mysql80 -c "/helpers/sql-import.sh testdata1.sql"
3747
lando ssh -s mysql80 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original"
3848

49+
# Should import test data into mysql80-default
50+
cd sqlhelpers
51+
lando ssh -s mysql80-default -c "/helpers/sql-import.sh testdata1.sql"
52+
lando ssh -s mysql80-default -c "mysql -utest -ptest database -e 'select * from lando_test'" | grep "lando_original"
53+
3954
# Should import test data into postgres16
4055
cd sqlhelpers
4156
lando ssh -s postgres16 -c "/helpers/sql-import.sh testdata1.sql"
4257
lando ssh -s postgres16 -c "psql -U postgres -d lando_test -c 'select * from lando_test'" | grep "lando_original"
4358

59+
# Should import test data into postgres16-default
60+
cd sqlhelpers
61+
lando ssh -s postgres16-default -c "/helpers/sql-import.sh testdata1.sql"
62+
lando ssh -s postgres16-default -c "psql -U postgres -d database -c 'select * from lando_test'" | grep "lando_original"
63+
4464
# Should export gzipped files from mariadb
4565
cd sqlhelpers
4666
lando ssh -s mariadb -c "/helpers/sql-export.sh mariadb_dump.sql" -u root

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/sql-import.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ if [ "$WIPE" == "true" ]; then
108108
SQLSTART="mysql -h $HOST -P $PORT -u $USER ${LANDO_EXTRA_DB_IMPORT_ARGS}"
109109

110110
# Drop and recreate database
111-
$SQLSTART -e "DROP DATABASE IF EXISTS ${DATABASE}"
112-
$SQLSTART -e "CREATE DATABASE ${DATABASE}"
111+
$SQLSTART -e "DROP DATABASE IF EXISTS \`${DATABASE}\`"
112+
$SQLSTART -e "CREATE DATABASE \`${DATABASE}\`"
113113
fi
114114
fi
115115

0 commit comments

Comments
 (0)