|
| 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 test data into mariadb |
| 25 | +cd sqlhelpers |
| 26 | +lando ssh -s mariadb -c "/helpers/sql-import.sh testdata1.sql" |
| 27 | +lando ssh -s mariadb -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original" |
| 28 | + |
| 29 | +# Should import test data into mysql57 |
| 30 | +cd sqlhelpers |
| 31 | +lando ssh -s mysql57 -c "/helpers/sql-import.sh testdata1.sql" |
| 32 | +lando ssh -s mysql57 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original" |
| 33 | + |
| 34 | +# Should import test data into mysql80 |
| 35 | +cd sqlhelpers |
| 36 | +lando ssh -s mysql80 -c "/helpers/sql-import.sh testdata1.sql" |
| 37 | +lando ssh -s mysql80 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original" |
| 38 | + |
| 39 | +# Should import test data into postgres16 |
| 40 | +cd sqlhelpers |
| 41 | +lando ssh -s postgres16 -c "/helpers/sql-import.sh testdata1.sql" |
| 42 | +lando ssh -s postgres16 -c "psql -U postgres -d lando_test -c 'select * from lando_test'" | grep "lando_original" |
| 43 | + |
| 44 | +# Should export gzipped files from mariadb |
| 45 | +cd sqlhelpers |
| 46 | +lando ssh -s mariadb -c "/helpers/sql-export.sh mariadb_dump.sql" -u root |
| 47 | +gzip -d mariadb_dump.sql.gz |
| 48 | + |
| 49 | +# Should export gzipped files from mysql57 |
| 50 | +cd sqlhelpers |
| 51 | +lando ssh -s mysql57 -c "/helpers/sql-export.sh mysql57_dump.sql" -u root |
| 52 | +gzip -d mysql57_dump.sql.gz |
| 53 | + |
| 54 | +# Should export gzipped files from mysql80 |
| 55 | +cd sqlhelpers |
| 56 | +lando ssh -s mysql80 -c "/helpers/sql-export.sh mysql80_dump.sql" -u root |
| 57 | +gzip -d mysql80_dump.sql.gz |
| 58 | + |
| 59 | +# Should export gzipped files from postgres16 |
| 60 | +cd sqlhelpers |
| 61 | +lando ssh -s postgres16 -c "/helpers/sql-export.sh postgres16_dump.sql" -u root |
| 62 | +gzip -d postgres16_dump.sql.gz |
| 63 | + |
| 64 | +# Should have the correct data in all exported files |
| 65 | +cd sqlhelpers |
| 66 | +grep "lando_original" mariadb_dump.sql |
| 67 | +grep "lando_original" mysql57_dump.sql |
| 68 | +grep "lando_original" mysql80_dump.sql |
| 69 | +grep "lando_original" postgres16_dump.sql |
| 70 | + |
| 71 | +# Should be able to replace data with testdata2 in mariadb |
| 72 | +cd sqlhelpers |
| 73 | +lando ssh -s mariadb -c "/helpers/sql-import.sh testdata2.sql" |
| 74 | +lando ssh -s mariadb -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated" |
| 75 | + |
| 76 | +# Should be able to replace data with testdata2 in mysql57 |
| 77 | +cd sqlhelpers |
| 78 | +lando ssh -s mysql57 -c "/helpers/sql-import.sh testdata2.sql" |
| 79 | +lando ssh -s mysql57 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated" |
| 80 | + |
| 81 | +# Should be able to replace data with testdata2 in mysql80 |
| 82 | +cd sqlhelpers |
| 83 | +lando ssh -s mysql80 -c "/helpers/sql-import.sh testdata2.sql" |
| 84 | +lando ssh -s mysql80 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated" |
| 85 | + |
| 86 | +# Should be able to replace data with testdata2 in postgres16 |
| 87 | +cd sqlhelpers |
| 88 | +lando ssh -s postgres16 -c "/helpers/sql-import.sh testdata2.sql" |
| 89 | +lando ssh -s postgres16 -c "psql -U postgres -d lando_test -c 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated" |
| 90 | +``` |
| 91 | + |
| 92 | +Destroy tests |
| 93 | +------------- |
| 94 | + |
| 95 | +```bash |
| 96 | +# Should destroy sqlhelpers successfully |
| 97 | +cd sqlhelpers && lando destroy -y |
| 98 | + |
| 99 | +# Should poweroff |
| 100 | +lando poweroff |
| 101 | +``` |
0 commit comments