|
| 1 | +SQL Import/Export Example |
| 2 | +============ |
| 3 | + |
| 4 | +This example exists primarily to test the `sql-import.sh` and `sql-export.sh` helper scripts. |
| 5 | + |
| 6 | +Start up tests |
| 7 | +-------------- |
| 8 | + |
| 9 | +```bash |
| 10 | +# Should init and start a lando app |
| 11 | +rm -rf sqlhelpers && mkdir -p sqlhelpers |
| 12 | +cp -rf .lando.sqlhelpers.yml sqlhelpers/.lando.yml |
| 13 | +cp -rf testdata1.sql sqlhelpers/testdata1.sql |
| 14 | +cp -rf testdata2.sql sqlhelpers/testdata2.sql |
| 15 | +cd sqlhelpers && lando start |
| 16 | +``` |
| 17 | + |
| 18 | +Verification commands |
| 19 | +--------------------- |
| 20 | + |
| 21 | +Run the following commands to verify things work as expected |
| 22 | + |
| 23 | +```bash |
| 24 | +# Should import testdata1.sql into all databases |
| 25 | +cd sqlhelpers |
| 26 | +lando ssh -s mariadb -c "/helpers/sql-import.sh testdata1.sql" |
| 27 | +lando ssh -s mysql57 -c "/helpers/sql-import.sh testdata1.sql" |
| 28 | +lando ssh -s mysql80 -c "/helpers/sql-import.sh testdata1.sql" |
| 29 | +lando ssh -s postgres16 -c "/helpers/sql-import.sh testdata1.sql" |
| 30 | +lando ssh -s mariadb -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original" |
| 31 | +lando ssh -s mysql57 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original" |
| 32 | +lando ssh -s mysql80 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original" |
| 33 | +lando ssh -s postgres16 -c "psql -U postgres -d lando_test -c 'select * from lando_test'" | grep "lando_original" |
| 34 | + |
| 35 | +# Should export gzipped files from all databases |
| 36 | +cd sqlhelpers |
| 37 | +lando ssh -s mariadb -c "/helpers/sql-export.sh mariadb_dump.sql" -u root |
| 38 | +lando ssh -s mysql57 -c "/helpers/sql-export.sh mysql57_dump.sql" -u root |
| 39 | +lando ssh -s mysql80 -c "/helpers/sql-export.sh mysql80_dump.sql" -u root |
| 40 | +lando ssh -s postgres16 -c "/helpers/sql-export.sh postgres16_dump.sql" -u root |
| 41 | +gzip -d mariadb_dump.sql.gz |
| 42 | +gzip -d mysql57_dump.sql.gz |
| 43 | +gzip -d mysql80_dump.sql.gz |
| 44 | +gzip -d postgres16_dump.sql.gz |
| 45 | + |
| 46 | +# Should have the correct data in the exported files |
| 47 | +cd sqlhelpers |
| 48 | +grep "lando_original" mariadb_dump.sql |
| 49 | +grep "lando_original" mysql57_dump.sql |
| 50 | +grep "lando_original" mysql80_dump.sql |
| 51 | +grep "lando_original" postgres16_dump.sql |
| 52 | + |
| 53 | +# Should be able to replace data with testdata2.sql |
| 54 | +cd sqlhelpers |
| 55 | +lando ssh -s mariadb -c "/helpers/sql-import.sh testdata2.sql" |
| 56 | +lando ssh -s mariadb -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated" |
| 57 | +lando ssh -s mysql57 -c "/helpers/sql-import.sh testdata2.sql" |
| 58 | +lando ssh -s mysql57 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated" |
| 59 | +lando ssh -s mysql80 -c "/helpers/sql-import.sh testdata2.sql" |
| 60 | +lando ssh -s mysql80 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated" |
| 61 | +lando ssh -s postgres16 -c "/helpers/sql-import.sh testdata2.sql" |
| 62 | +lando ssh -s postgres16 -c "psql -U postgres -d lando_test -c 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated" |
| 63 | +``` |
| 64 | + |
| 65 | +Destroy tests |
| 66 | +------------- |
| 67 | + |
| 68 | +```bash |
| 69 | +# Should destroy sqlhelpers successfully |
| 70 | +cd sqlhelpers && lando destroy -y |
| 71 | + |
| 72 | +# Should poweroff |
| 73 | +lando poweroff |
| 74 | +``` |
0 commit comments