2
0
Эх сурвалжийг харах

Add bin/dbdump and improve bin/mysql

Ranger Chan 5 жил өмнө
parent
commit
2b87db8e94

+ 15 - 8
README.md

@@ -213,7 +213,7 @@ bin/composer install
 bin/copyfromcontainer vendor
 
 # Import existing database:
-bin/clinotty mysql -hdb -umagento -pmagento magento < existing/magento.sql
+bin/mysql < existing/magento.sql
 
 # Update database connection details to use the above Docker MySQL credentials:
 # Also note: creds for the MySQL server are defined at startup from env/db.env
@@ -223,8 +223,8 @@ bin/clinotty mysql -hdb -umagento -pmagento magento < existing/magento.sql
 bin/magento app:config:import
 
 # Set base URLs to local environment URL (if not defined in env.php file):
-bin/magento config:set web/secure/base_url https://yoursite.test/
-bin/magento config:set web/unsecure/base_url https://yoursite.test/
+bin/magento setup:store-config:set web/secure/base_url https://yoursite.test/
+bin/magento setup:store-config:set web/unsecure/base_url https://yoursite.test/
 
 bin/restart
 
@@ -263,6 +263,7 @@ You'll now have an updated `bin/update` helper script, and can run it to update
 - `bin/composer`: Run the composer binary. Ex. `bin/composer install`
 - `bin/copyfromcontainer`: Copy folders or files from container to host. Ex. `bin/copyfromcontainer vendor`
 - `bin/copytocontainer`: Copy folders or files from host to container. Ex. `bin/copytocontainer --all`
+- `bin/dbdump`: Dump configured Magento database with `mysqldump`. Ex. `bin/dbdump > dbdump.sql`
 - `bin/dev-urn-catalog-generate`: Generate URN's for PHPStorm and remap paths to local host. Restart PHPStorm after running this command.
 - `bin/devconsole`: Alias for `bin/n98-magerun2 dev:console`
 - `bin/download`: Download & extract specific Magento version to the `src` directory. Ex. `bin/download 2.3.3`
@@ -270,7 +271,7 @@ You'll now have an updated `bin/update` helper script, and can run it to update
 - `bin/fixperms`: This will fix filesystem permissions within the container.
 - `bin/grunt`: Run the grunt binary. Ex. `bin/grunt exec`
 - `bin/magento`: Run the Magento CLI. Ex: `bin/magento cache:flush`
-- `bin/mysql`: Run the MySQL CLI with database config from env/db.env. Ex `bin/mysql -e "EXPLAIN core_config_data"`
+- `bin/mysql`: Run the MySQL CLI with database config from `env/db.env`. Ex. `bin/mysql -e "EXPLAIN core_config_data"` and `bin/mysql < dbdump.sql`
 - `bin/n98-magerun2`: Access the n98 magerun CLI. Ex: `bin/n98-magerun2 dev:console`
 - `bin/node`: Run the node binary. Ex. `bin/node --version`
 - `bin/npm`: Run the npm binary. Ex. `bin/npm install`
@@ -299,16 +300,22 @@ You'll now have an updated `bin/update` helper script, and can run it to update
 
 The hostname of each service is the name of the service within the `docker-compose.yml` file. So for example, MySQL's hostname is `db` (not `localhost`) when accessing it from within a Docker container. Elasticsearch's hostname is `elasticsearch`.
 
-Here's an example of how to connect to the MySQL cli tool of the Docker instance:
+Here's an example of how to connect to the MySQL CLI tool of the Docker instance:
 
 ```
-bin/cli mysql -h db -umagento -pmagento magento
+bin/mysql
 ```
 
-You can use the `bin/clinotty` helper script to import a database. This example uses the root MySQL user, and looks for the `dbdump.sql` file in your local host directory:
+You can use the `bin/mysql` script to import a database. The `dbdump.sql` file is in your local host directory:
 
 ```
-bin/clinotty mysql -h db -u root -pmagento magento < dbdump.sql
+bin/mysql < dbdump.sql
+```
+
+You also can use `bin/dbdump` to export a database from magento in Docker container. The `dbdump.sql` file will appear in your local host directory:
+
+```
+bin/dbdump > dbdump.sql
 ```
 
 ### Composer Authentication

+ 2 - 0
compose/bin/dbdump

@@ -0,0 +1,2 @@
+#!/bin/bash
+bin/n98-magerun2 db:dump --stdout "$@"

+ 7 - 1
compose/bin/mysql

@@ -1,3 +1,9 @@
 #!/bin/bash
 source env/db.env
-bin/cli mysql -hdb -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
+if [ -t 0 ]; then
+  # Need tty to run mysql shell
+  bin/cli mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
+else
+  # Read from stdin, ex: bin/mysql < dbdump.sql
+  bin/clinotty mysql -h${MYSQL_HOST} -u${MYSQL_USER} -p${MYSQL_PASSWORD} ${MYSQL_DATABASE} "$@"
+fi

+ 3 - 4
compose/bin/n98-magerun2

@@ -1,8 +1,7 @@
 #!/bin/bash
 if ! bin/clinotty ls bin/n98-magerun2.phar 1> /dev/null 2>&1; then
-    bin/clinotty curl -O https://files.magerun.net/n98-magerun2.phar
-    bin/clinotty chmod +x n98-magerun2.phar
-    bin/clinotty mkdir -p bin
-    bin/clinotty mv n98-magerun2.phar bin/n98-magerun2.phar
+  bin/clinotty mkdir -p bin
+  bin/clinotty curl https://files.magerun.net/n98-magerun2.phar -o bin/n98-magerun2.phar
+  bin/clinotty chmod +x bin/n98-magerun2.phar
 fi
 bin/cli bin/n98-magerun2.phar "$@"

+ 1 - 0
compose/env/db.env

@@ -1,3 +1,4 @@
+MYSQL_HOST=db
 MYSQL_ROOT_PASSWORD=magento
 MYSQL_DATABASE=magento
 MYSQL_USER=magento