Skip to content

Commit 358e2a0

Browse files
CopilotswissspidyCopilot
authored
Add SQLite compatibility to wp db commands (#299)
Co-authored-by: swissspidy <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Pascal Birchler <[email protected]>
1 parent 089afe8 commit 358e2a0

17 files changed

+1240
-38
lines changed

features/db-check.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Feature: Check the database
22

3+
@require-mysql-or-mariadb
34
Scenario: Run db check to check the database
45
Given a WP install
56

@@ -13,12 +14,14 @@ Feature: Check the database
1314
Success: Database checked.
1415
"""
1516

17+
@require-mysql-or-mariadb
1618
Scenario: db check with --quiet flag should only show errors
1719
Given a WP install
1820

1921
When I run `wp db check --quiet`
2022
Then STDOUT should be empty
2123

24+
@require-mysql-or-mariadb
2225
Scenario: db check can explicitly pass --silent to mysqlcheck
2326
Given a WP install
2427

@@ -32,6 +35,7 @@ Feature: Check the database
3235
Success: Database checked.
3336
"""
3437

38+
@require-mysql-or-mariadb
3539
Scenario: Run db check with MySQL defaults to check the database
3640
Given a WP install
3741

@@ -45,6 +49,7 @@ Feature: Check the database
4549
Success: Database checked.
4650
"""
4751

52+
@require-mysql-or-mariadb
4853
Scenario: Run db check with --no-defaults to check the database
4954
Given a WP install
5055

@@ -58,6 +63,7 @@ Feature: Check the database
5863
Success: Database checked.
5964
"""
6065

66+
@require-mysql-or-mariadb
6167
Scenario: Run db check with passed-in options
6268
Given a WP install
6369

@@ -143,6 +149,7 @@ Feature: Check the database
143149
"""
144150
And STDOUT should be empty
145151

152+
@require-mysql-or-mariadb
146153
Scenario: MySQL defaults are available as appropriate with --defaults flag
147154
Given a WP install
148155

@@ -155,3 +162,12 @@ Feature: Check the database
155162
When I try `wp db check --no-defaults --debug`
156163
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#
157164

165+
@require-sqlite
166+
Scenario: SQLite commands that show warnings
167+
Given a WP install
168+
169+
When I try `wp db check`
170+
Then STDERR should contain:
171+
"""
172+
Warning: Database check is not supported for SQLite databases
173+
"""

features/db-cli.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: Open a MySQL console
2+
3+
@require-sqlite
4+
Scenario: SQLite commands that show warnings for cli
5+
Given a WP install
6+
7+
When I try `wp db cli`
8+
Then STDERR should contain:
9+
"""
10+
Warning: Interactive console (cli) is not supported for SQLite databases
11+
"""

features/db-columns.feature

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: Display information about a given table.
22

33
# This requires conditional tags to target different DB versions, as bigint(20) is only bigint on MySQL 8.
4-
@require-wp-4.2 @broken
4+
@broken
55
Scenario: Display information about the wp_posts table
66
Given a WP install
77

@@ -41,6 +41,7 @@ Feature: Display information about a given table.
4141
Couldn't find any tables matching: wp_foobar
4242
"""
4343

44+
@require-mysql-or-mariadb
4445
Scenario: Display information about a non default WordPress table
4546
Given a WP install
4647
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
@@ -50,3 +51,14 @@ Feature: Display information about a given table.
5051
| Field | Type | Null | Key | Default | Extra |
5152
| date | date | NO | PRI | | |
5253
| awesome_stuff | text | YES | | | |
54+
55+
@require-sqlite
56+
Scenario: Display information about a non default WordPress table
57+
Given a WP install
58+
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
59+
60+
When I try `wp db columns not_wp`
61+
Then STDOUT should be a table containing rows:
62+
| Field | Type | Null | Key | Default |
63+
| date | TEXT | NO | PRI | '' |
64+
| awesome_stuff | TEXT | YES | | |

features/db-create.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Feature: Create a new database
2+
3+
@require-mysql-or-mariadb
4+
Scenario: Create a new database
5+
Given an empty directory
6+
And WP files
7+
And wp-config.php
8+
9+
When I run `wp db create`
10+
Then STDOUT should contain:
11+
"""
12+
Success: Database created.
13+
"""
14+
15+
@require-sqlite
16+
Scenario: SQLite DB create operation should fail if already existing
17+
Given a WP install
18+
19+
When I try `wp db create`
20+
Then the return code should be 1
21+
And STDERR should contain:
22+
"""
23+
Database already exists
24+
"""

features/db-export.feature

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,57 @@ Feature: Export a WordPress database
2020
"""
2121
And the wp_cli_test.sql file should exist
2222

23+
@skip-sqlite
2324
Scenario: Exclude tables when exporting the database
2425
Given a WP install
2526

26-
When I run `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
27+
When I try `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
2728
Then the wp_cli_test.sql file should exist
28-
And the wp_cli_test.sql file should not contain:
29-
"""
30-
wp_users
31-
"""
32-
And the wp_cli_test.sql file should contain:
29+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_users["`]?/
30+
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_options["`]?/
31+
32+
@skip-sqlite
33+
Scenario: Include only specific tables when exporting the database
34+
Given a WP install
35+
36+
When I try `wp db export wp_cli_test.sql --tables=wp_users --porcelain`
37+
Then the wp_cli_test.sql file should exist
38+
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_users["`]?/
39+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_posts["`]?/
40+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_options["`]?/
41+
42+
@require-sqlite
43+
Scenario: Exclude tables when exporting the database
44+
Given a WP install
45+
46+
When I try `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
47+
Then the wp_cli_test.sql file should exist
48+
And the contents of the wp_cli_test.sql file should not match /_mysql_data_types_cache/
49+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_users["`]?/
50+
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_options["`]?/
51+
52+
@require-sqlite
53+
Scenario: Include only specific tables when exporting the database
54+
Given a WP install
55+
56+
When I try `wp db export wp_cli_test.sql --tables=wp_users --porcelain`
57+
Then the wp_cli_test.sql file should exist
58+
And the contents of the wp_cli_test.sql file should not match /_mysql_data_types_cache/
59+
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_users["`]?/
60+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_posts["`]?/
61+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_options["`]?/
62+
63+
@require-sqlite
64+
Scenario: Export database to STDOUT
65+
Given a WP install
66+
67+
When I run `wp db export -`
68+
Then STDOUT should contain:
3369
"""
34-
wp_options
70+
PRAGMA foreign_keys=OFF
3571
"""
3672

73+
@skip-sqlite
3774
Scenario: Export database to STDOUT
3875
Given a WP install
3976

@@ -42,7 +79,7 @@ Feature: Export a WordPress database
4279
"""
4380
-- Dump completed on
4481
"""
45-
82+
@skip-sqlite
4683
Scenario: Export database with mysql defaults to STDOUT
4784
Given a WP install
4885

@@ -52,6 +89,7 @@ Feature: Export a WordPress database
5289
-- Dump completed on
5390
"""
5491

92+
@skip-sqlite
5593
Scenario: Export database with mysql --no-defaults to STDOUT
5694
Given a WP install
5795

@@ -61,6 +99,7 @@ Feature: Export a WordPress database
6199
-- Dump completed on
62100
"""
63101

102+
@skip-sqlite
64103
Scenario: Export database with passed-in options
65104
Given a WP install
66105

@@ -78,6 +117,25 @@ Feature: Export a WordPress database
78117
"""
79118
And STDOUT should be empty
80119

120+
@require-sqlite
121+
Scenario: Export database with passed-in options
122+
Given a WP install
123+
124+
When I run `wp db export - --skip-comments`
125+
Then STDOUT should not contain:
126+
"""
127+
-- Table structure
128+
"""
129+
130+
# dbpass has no effect on SQLite
131+
When I try `wp db export - --dbpass=no_such_pass`
132+
Then the return code should be 0
133+
And STDERR should not contain:
134+
"""
135+
Access denied
136+
"""
137+
138+
@skip-sqlite
81139
Scenario: MySQL defaults are available as appropriate with --defaults flag
82140
Given a WP install
83141

features/db-import.feature

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Feature: Import a WordPress database
3636
Success: Imported from 'wp_cli_test.sql'.
3737
"""
3838

39+
@require-mysql-or-mariadb
3940
Scenario: Import from STDIN
4041
Given a WP install
4142

@@ -45,6 +46,17 @@ Feature: Import a WordPress database
4546
Success: Imported from 'STDIN'.
4647
"""
4748

49+
# TODO: Debug the difference here.
50+
@require-sqlite
51+
Scenario: Import from STDIN
52+
Given a WP install
53+
54+
When I run `echo "" | wp db import -`
55+
Then STDOUT should be:
56+
"""
57+
Success: Imported from 'STDIN'.
58+
"""
59+
4860
Scenario: Import from database name path by default and skip speed optimization
4961
Given a WP install
5062

@@ -57,6 +69,8 @@ Feature: Import a WordPress database
5769
Success: Imported from 'wp_cli_test.sql'.
5870
"""
5971

72+
# SQLite doesn't support the --dbuser flag.
73+
@require-mysql-or-mariadb
6074
Scenario: Import from database name path by default with passed-in dbuser/dbpass
6175
Given a WP install
6276

@@ -77,6 +91,8 @@ Feature: Import a WordPress database
7791
"""
7892
And STDOUT should be empty
7993

94+
# SQLite doesn't support the --force flag.
95+
@require-mysql-or-mariadb
8096
Scenario: Import database with passed-in options
8197
Given a WP install
8298
And a debug.sql file:
@@ -90,6 +106,9 @@ Feature: Import a WordPress database
90106
Success: Imported from 'debug.sql'.
91107
"""
92108

109+
# For SQLite this would fail at the `wp db create` step
110+
# because of the missing plugin/drop-in.
111+
@require-mysql-or-mariadb
93112
Scenario: Help runs properly at various points of a functional WP install
94113
Given an empty directory
95114

@@ -127,6 +146,8 @@ Feature: Import a WordPress database
127146
"""
128147
wp db import
129148
"""
149+
150+
@require-mysql-or-mariadb
130151
Scenario: MySQL defaults are available as appropriate with --defaults flag
131152
Given a WP install
132153

@@ -142,7 +163,7 @@ Feature: Import a WordPress database
142163
When I try `wp db import --no-defaults --debug`
143164
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysql|mariadb) --no-defaults --no-auto-rehash#
144165

145-
@require-wp-4.2
166+
@require-mysql-or-mariadb
146167
Scenario: Import db that has emoji in post
147168
Given a WP install
148169

@@ -178,3 +199,32 @@ Feature: Import a WordPress database
178199
"""
179200
🍣
180201
"""
202+
203+
@require-sqlite
204+
Scenario: Import db that has emoji in post
205+
Given a WP install
206+
207+
When I run `wp post create --post_title="🍣"`
208+
And I run `wp post list`
209+
Then the return code should be 0
210+
And STDOUT should contain:
211+
"""
212+
🍣
213+
"""
214+
215+
When I try `wp db export wp_cli_test.sql --debug`
216+
Then the return code should be 0
217+
And the wp_cli_test.sql file should exist
218+
219+
When I run `wp db import --dbuser=wp_cli_test --dbpass=password1`
220+
Then STDOUT should be:
221+
"""
222+
Success: Imported from 'wp_cli_test.sql'.
223+
"""
224+
225+
When I run `wp post list`
226+
Then the return code should be 0
227+
And STDOUT should contain:
228+
"""
229+
🍣
230+
"""

features/db-optimize.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: Optimize the database
2+
3+
@require-mysql-or-mariadb
4+
Scenario: Run db optimize to optimize the database
5+
Given a WP install
6+
7+
When I run `wp db optimize`
8+
Then STDOUT should contain:
9+
"""
10+
Success: Database optimized.
11+
"""
12+
13+
@require-sqlite
14+
Scenario: SQLite commands that show warnings for optimize
15+
Given a WP install
16+
17+
When I try `wp db optimize`
18+
Then STDERR should contain:
19+
"""
20+
Warning: Database optimization is not supported for SQLite databases
21+
"""

0 commit comments

Comments
 (0)