Skip to content

Commit 719cb77

Browse files
committed
Merge branch 'main' into copilot/add-wp-db-users-command
2 parents 6bfaf43 + 36f3ce4 commit 719cb77

6 files changed

Lines changed: 142 additions & 62 deletions

File tree

README.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ To confirm the ID for the site you want to query, you can use the `wp site list`
431431
Exports the database to a file or to STDOUT.
432432

433433
~~~
434-
wp db export [<file>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--tables=<tables>] [--exclude_tables=<tables>] [--include-tablespaces] [--porcelain] [--add-drop-table] [--defaults]
434+
wp db export [<file>] [--dbuser=<value>] [--dbpass=<value>] [--<field>=<value>] [--tables=<tables>] [--exclude_tables=<tables>] [--include-tablespaces] [--porcelain] [--defaults]
435435
~~~
436436

437437
**Alias:** `dump`
@@ -466,16 +466,13 @@ Runs `mysqldump` utility using `DB_HOST`, `DB_NAME`, `DB_USER` and
466466
[--porcelain]
467467
Output filename for the exported database.
468468

469-
[--add-drop-table]
470-
Include a `DROP TABLE IF EXISTS` statement before each `CREATE TABLE` statement.
471-
472469
[--defaults]
473470
Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
474471

475472
**EXAMPLES**
476473

477-
# Export database with drop query included
478-
$ wp db export --add-drop-table
474+
# Export database with `--skip-opt` and `--add-drop-table` mysqldump flags
475+
$ wp db export --skip-opt --add-drop-table
479476
Success: Exported to 'wordpress_dbase-db72bb5.sql'.
480477

481478
# Export certain tables
@@ -759,7 +756,22 @@ Defaults to all tables registered to the $wpdb database handler.
759756
List tables based on wildcard search, e.g. 'wp_*_options' or 'wp_post?'.
760757

761758
[--scope=<scope>]
762-
Can be all, global, ms_global, blog, or old tables. Defaults to all.
759+
List tables based on the scope.
760+
761+
- all: returns 'all' and 'global' tables. No old tables are returned.
762+
- blog: returns the blog-level tables for the queried blog.
763+
- global: returns the global tables for the installation, returning multisite tables only on multisite.
764+
- ms_global: returns the multisite global tables, regardless if current installation is multisite.
765+
- old: returns tables which are deprecated.
766+
---
767+
default: all
768+
options:
769+
- all
770+
- blog
771+
- global
772+
- ms_global
773+
- old
774+
---
763775

764776
[--network]
765777
List all the tables in a multisite install.

features/db-search.feature

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -679,19 +679,19 @@ Feature: Search through the database
679679
:あいうえおかきくけこさしすせとたちつてと
680680
"""
681681

682-
When I run `wp db search 'ppppp' --before_context=3 --after_context=4`
682+
When I run `wp db search "ppppp" --before_context=3 --after_context=4`
683683
Then STDOUT should contain:
684684
"""
685685
:ムnöppppp
686686
"""
687687

688-
When I run `wp db search 'ppppp' --before_context=1 --after_context=1`
688+
When I run `wp db search "ppppp" --before_context=1 --after_context=1`
689689
Then STDOUT should contain:
690690
"""
691691
:öppppp
692692
"""
693693

694-
When I run `wp db search 'ムn' --before_context=2 --after_context=1`
694+
When I run `wp db search "ムn" --before_context=2 --after_context=1`
695695
Then STDOUT should contain:
696696
"""
697697
:llムnö
@@ -701,7 +701,7 @@ Feature: Search through the database
701701
:llムnöp
702702
"""
703703

704-
When I run `wp db search 'ムn' --before_context=2 --after_context=2`
704+
When I run `wp db search "ムn" --before_context=2 --after_context=2`
705705
Then STDOUT should contain:
706706
"""
707707
:llムnöp
@@ -720,7 +720,7 @@ Feature: Search through the database
720720
# Note ö is o with combining umlaut.
721721
And I run `wp option update regextst_combining 'lllllムnöppppp'`
722722

723-
When I run `wp db search 'https?:\/\/example.c.m' --regex`
723+
When I run `wp db search "https?:\/\/example.c.m" --regex`
724724
Then STDOUT should contain:
725725
"""
726726
wp_options:option_value
@@ -731,10 +731,10 @@ Feature: Search through the database
731731
[...]
732732
"""
733733

734-
When I run `wp db search 'unfindable' --regex`
734+
When I run `wp db search "unfindable" --regex`
735735
Then STDOUT should be empty
736736

737-
When I try `wp db search 'unfindable' --regex --regex-flags='abcd'`
737+
When I try `wp db search "unfindable" --regex --regex-flags="abcd"`
738738
Then STDERR should contain:
739739
"""
740740
unfindable
@@ -745,42 +745,42 @@ Feature: Search through the database
745745
"""
746746
And the return code should be 1
747747

748-
When I try `wp db search 'unfindable' --regex --regex-delimiter='1'`
748+
When I try `wp db search "unfindable" --regex --regex-delimiter="1"`
749749
Then STDERR should be:
750750
"""
751751
Error: The regex '1unfindable1' fails.
752752
"""
753753
And the return code should be 1
754754

755-
When I try `wp db search 'regex error)' --regex`
755+
When I try `wp db search "regex error)" --regex`
756756
Then STDERR should be:
757757
"""
758758
Error: The regex pattern 'regex error)' with default delimiter 'chr(1)' and no flags fails.
759759
"""
760760
And the return code should be 1
761761

762-
When I try `wp db search 'regex error)' --regex --regex-flags=u`
762+
When I try `wp db search "regex error)" --regex --regex-flags=u`
763763
Then STDERR should be:
764764
"""
765765
Error: The regex pattern 'regex error)' with default delimiter 'chr(1)' and flags 'u' fails.
766766
"""
767767
And the return code should be 1
768768

769-
When I try `wp db search 'regex error)' --regex --regex-delimiter=/`
769+
When I try `wp db search "regex error)" --regex --regex-delimiter=#`
770770
Then STDERR should be:
771771
"""
772-
Error: The regex '/regex error)/' fails.
772+
Error: The regex '#regex error)#' fails.
773773
"""
774774
And the return code should be 1
775775

776-
When I try `wp db search 'regex error)' --regex --regex-delimiter=/ --regex-flags=u`
776+
When I try `wp db search "regex error)" --regex --regex-delimiter=# --regex-flags=u`
777777
Then STDERR should be:
778778
"""
779-
Error: The regex '/regex error)/u' fails.
779+
Error: The regex '#regex error)#u' fails.
780780
"""
781781
And the return code should be 1
782782

783-
When I run `wp db search '[0-9é]+?https:' --regex --regex-flags=u --before_context=0 --after_context=0`
783+
When I run `wp db search "[0-9é]+?https:" --regex --regex-flags=u --before_context=0 --after_context=0`
784784
Then STDOUT should contain:
785785
"""
786786
:1234567890123456789éhttps:
@@ -794,7 +794,7 @@ Feature: Search through the database
794794
[...]
795795
"""
796796

797-
When I run `wp db search 'htt(p(s):)\/\/' --regex --before_context=1 --after_context=3`
797+
When I run `wp db search "htt(p(s):)\/\/" --regex --before_context=1 --after_context=3`
798798
Then STDOUT should contain:
799799
"""
800800
:あhttps://reg [...] éhttps://reg
@@ -804,7 +804,7 @@ Feature: Search through the database
804804
rege
805805
"""
806806

807-
When I run `wp db search 'https://' --regex --regex-delimiter=# --before_context=9 --after_context=11`
807+
When I run `wp db search "https://" --regex --regex-delimiter=# --before_context=9 --after_context=11`
808808
Then STDOUT should contain:
809809
"""
810810
:2345é789あhttps://regextst.co [...] 23456789éhttps://regextst.co
@@ -814,10 +814,10 @@ Feature: Search through the database
814814
regextst.com
815815
"""
816816

817-
When I run `wp db search 'httPs://' --regex --regex-delimiter=# --before_context=3 --after_context=0`
817+
When I run `wp db search "httPs://" --regex --regex-delimiter=# --before_context=3 --after_context=0`
818818
Then STDOUT should be empty
819819

820-
When I run `wp db search 'httPs://' --regex --regex-flags=i --regex-delimiter=# --before_context=3 --after_context=0`
820+
When I run `wp db search "httPs://" --regex --regex-flags=i --regex-delimiter=# --before_context=3 --after_context=0`
821821
Then STDOUT should contain:
822822
"""
823823
:89あhttps:// [...] 89éhttps://
@@ -827,19 +827,19 @@ Feature: Search through the database
827827
https://r
828828
"""
829829

830-
When I run `wp db search 'ppppp' --regex --before_context=3 --after_context=4`
830+
When I run `wp db search "ppppp" --regex --before_context=3 --after_context=4`
831831
Then STDOUT should contain:
832832
"""
833833
:ムnöppppp
834834
"""
835835

836-
When I run `wp db search 'ppppp' --regex --before_context=1 --after_context=1`
836+
When I run `wp db search "ppppp" --regex --before_context=1 --after_context=1`
837837
Then STDOUT should contain:
838838
"""
839839
:öppppp
840840
"""
841841

842-
When I run `wp db search 'ムn' --before_context=2 --after_context=1`
842+
When I run `wp db search "ムn" --before_context=2 --after_context=1`
843843
Then STDOUT should contain:
844844
"""
845845
:llムnö
@@ -849,7 +849,7 @@ Feature: Search through the database
849849
:llムnöp
850850
"""
851851

852-
When I run `wp db search 'ムn' --regex --before_context=2 --after_context=2`
852+
When I run `wp db search "ムn" --regex --before_context=2 --after_context=2`
853853
Then STDOUT should contain:
854854
"""
855855
:llムnöp
@@ -859,7 +859,7 @@ Feature: Search through the database
859859
:llムnöpp
860860
"""
861861

862-
When I run `wp db search 't\.c' --regex --before_context=1 --after_context=1`
862+
When I run `wp db search "t\.c" --regex --before_context=1 --after_context=1`
863863
Then STDOUT should contain:
864864
"""
865865
:st.co [...] st.co [...] st.co [...] 0t.co
@@ -869,7 +869,7 @@ Feature: Search through the database
869869
st.com
870870
"""
871871

872-
When I run `wp db search 'https://' --regex`
872+
When I run `wp db search "https://" --regex`
873873
Then the return code should be 0
874874

875875
Scenario: Search with output options
@@ -982,6 +982,7 @@ Feature: Search through the database
982982
And STDOUT should match /\d tables? skipped:.*wp_term_relationships/
983983
And STDERR should be empty
984984

985+
@skip-windows
985986
Scenario: Search with custom colors
986987
Given a WP install
987988

@@ -1060,7 +1061,7 @@ Feature: Search through the database
10601061
When I run `wp db query "SOURCE esc_sql_ident.sql;"`
10611062
Then STDERR should be empty
10621063

1063-
When I run `wp db search 'v_v' TABLE --all-tables`
1064+
When I run `wp db search "v_v" TABLE --all-tables`
10641065
Then STDOUT should be:
10651066
"""
10661067
TABLE:VALUES

features/db-size.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Feature: Display database size
3232
B
3333
"""
3434

35+
# On CI, SQLite on Windows is missing the dbstat extension.
36+
@skip-windows
3537
Scenario: Display only table sizes for a WordPress install
3638
Given a WP install
3739

@@ -81,6 +83,8 @@ Feature: Display database size
8183
KB
8284
"""
8385

86+
# On CI, SQLite on Windows is missing the dbstat extension.
87+
@skip-windows
8488
Scenario: Display only table sizes in a human readable format for a WordPress install
8589
Given a WP install
8690

@@ -222,6 +226,8 @@ Feature: Display database size
222226

223227
But STDOUT should not be a number
224228

229+
# On CI, SQLite on Windows is missing the dbstat extension.
230+
@skip-windows
225231
Scenario: Display all table sizes for a WordPress install
226232
Given a WP install
227233

@@ -282,6 +288,8 @@ Feature: Display database size
282288
[{"Name":"wp_posts",
283289
"""
284290

291+
# On CI, SQLite on Windows is missing the dbstat extension.
292+
@skip-windows
285293
Scenario: Display ordered table sizes for a WordPress install
286294
Given a WP install
287295

features/db.feature

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ Feature: Perform database operations
256256
1
257257
"""
258258
259-
When I run `wp db export /tmp/wp-cli-behat.sql`
259+
When I run `wp db export wp-cli-behat.sql`
260260
Then STDOUT should contain:
261261
"""
262262
Success: Exported
@@ -283,7 +283,7 @@ Feature: Perform database operations
283283
When I try `wp post list --format=count`
284284
Then STDERR should not be empty
285285
286-
When I run `wp db import /tmp/wp-cli-behat.sql`
286+
When I run `wp db import wp-cli-behat.sql`
287287
Then STDOUT should contain:
288288
"""
289289
Success: Imported
@@ -312,7 +312,7 @@ Feature: Perform database operations
312312
When I run `wp db create`
313313
Then STDOUT should not be empty
314314
315-
When I run `wp db export /tmp/wp-cli-behat.sql`
315+
When I run `wp db export wp-cli-behat.sql`
316316
Then STDOUT should contain:
317317
"""
318318
Success: Exported
@@ -383,7 +383,8 @@ Feature: Perform database operations
383383
Query succeeded. Rows affected: 1
384384
"""
385385
386-
@require-sqlite
386+
@require-sqlite @skip-windows
387+
# Skipped on Windows due to persistent file locking issues when run via Behat.
387388
Scenario: SQLite DB CRUD operations
388389
Given a WP install
389390
And a session_yes file:
@@ -420,7 +421,8 @@ Feature: Perform database operations
420421
total
421422
"""
422423
423-
@require-sqlite
424+
@require-sqlite @skip-windows
425+
# Skipped on Windows due to persistent file locking issues when run via Behat.
424426
Scenario: SQLite DB export/import
425427
Given a WP install
426428
And a session_yes file:
@@ -434,7 +436,7 @@ Feature: Perform database operations
434436
1
435437
"""
436438
437-
When I run `wp db export /tmp/wp-cli-sqlite-behat.sql`
439+
When I run `wp db export wp-cli-sqlite-behat.sql`
438440
Then STDOUT should contain:
439441
"""
440442
Success: Exported
@@ -446,7 +448,7 @@ Feature: Perform database operations
446448
Success: Database reset
447449
"""
448450
449-
When I run `wp db import /tmp/wp-cli-sqlite-behat.sql`
451+
When I run `wp db import wp-cli-sqlite-behat.sql`
450452
Then STDOUT should contain:
451453
"""
452454
Success: Imported

src/DB_Command.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -664,16 +664,13 @@ public function query( $args, $assoc_args ) {
664664
* [--porcelain]
665665
* : Output filename for the exported database.
666666
*
667-
* [--add-drop-table]
668-
* : Include a `DROP TABLE IF EXISTS` statement before each `CREATE TABLE` statement.
669-
*
670667
* [--defaults]
671668
* : Loads the environment's MySQL option files. Default behavior is to skip loading them to avoid failures due to misconfiguration.
672669
*
673670
* ## EXAMPLES
674671
*
675-
* # Export database with drop query included
676-
* $ wp db export --add-drop-table
672+
* # Export database with `--skip-opt` and `--add-drop-table` mysqldump flags
673+
* $ wp db export --skip-opt --add-drop-table
677674
* Success: Exported to 'wordpress_dbase-db72bb5.sql'.
678675
*
679676
* # Export certain tables
@@ -957,7 +954,22 @@ public function import( $args, $assoc_args ) {
957954
* : List tables based on wildcard search, e.g. 'wp_*_options' or 'wp_post?'.
958955
*
959956
* [--scope=<scope>]
960-
* : Can be all, global, ms_global, blog, or old tables. Defaults to all.
957+
* : List tables based on the scope.
958+
*
959+
* - all: returns 'all' and 'global' tables. No old tables are returned.
960+
* - blog: returns the blog-level tables for the queried blog.
961+
* - global: returns the global tables for the installation, returning multisite tables only on multisite.
962+
* - ms_global: returns the multisite global tables, regardless if current installation is multisite.
963+
* - old: returns tables which are deprecated.
964+
* ---
965+
* default: all
966+
* options:
967+
* - all
968+
* - blog
969+
* - global
970+
* - ms_global
971+
* - old
972+
* ---
961973
*
962974
* [--network]
963975
* : List all the tables in a multisite install.

0 commit comments

Comments
 (0)