Skip to content

Commit f7c1165

Browse files
Copilotswissspidy
andcommitted
Add SQLite test scenarios and documentation
Co-authored-by: swissspidy <[email protected]>
1 parent 711e37b commit f7c1165

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,44 @@ Performs basic database operations using credentials stored in wp-config.php.
77

88
Quick links: [Using](#using) | [Installing](#installing) | [Contributing](#contributing) | [Support](#support)
99

10+
## SQLite Support
11+
12+
This package now supports SQLite databases in addition to MySQL/MariaDB. When using the [SQLite Database Integration plugin](https://github.com/WordPress/sqlite-database-integration/), most `wp db` commands will automatically detect and work with SQLite databases.
13+
14+
**Supported commands with SQLite:**
15+
- `wp db create` - Creates the SQLite database file
16+
- `wp db drop` - Deletes the SQLite database file
17+
- `wp db reset` - Recreates the SQLite database file
18+
- `wp db query` - Executes SQL queries via PDO
19+
- `wp db export` - Exports the SQLite database to SQL
20+
- `wp db import` - Imports SQL into the SQLite database
21+
- `wp db tables` - Lists tables (via $wpdb)
22+
- `wp db size` - Shows database file size
23+
- `wp db prefix` - Shows table prefix (via $wpdb)
24+
- `wp db columns` - Shows column information (via $wpdb)
25+
- `wp db search` - Searches database content (via $wpdb)
26+
- `wp db clean` - Removes tables with prefix (via $wpdb)
27+
28+
**Commands not applicable to SQLite:**
29+
- `wp db check` - Shows a warning (SQLite doesn't require manual checking)
30+
- `wp db optimize` - Shows a warning (SQLite auto-optimizes with VACUUM)
31+
- `wp db repair` - Shows a warning (SQLite doesn't require manual repair)
32+
- `wp db cli` - Shows a warning (use `wp db query` instead)
33+
34+
**SQLite Detection:**
35+
36+
The command automatically detects SQLite databases when:
37+
1. The `DB_ENGINE` constant is set to `'sqlite'` in wp-config.php
38+
2. The `SQLITE_DB_DROPIN_VERSION` constant is defined (plugin loaded)
39+
3. A `db.php` drop-in exists with SQLite integration
40+
41+
**Database File Location:**
42+
43+
By default, the SQLite database is expected at `wp-content/database/.ht.sqlite`. You can customize this location using:
44+
- `FQDB` constant - Full path to the database file
45+
- `FQDBDIR` constant - Directory containing the database
46+
- `DB_FILE` constant - Database filename (used with FQDBDIR)
47+
1048
## Using
1149

1250
This package implements the following commands:

features/db-sqlite.feature

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
Feature: Perform database operations with SQLite
2+
3+
@require-sqlite
4+
Scenario: SQLite DB CRUD operations
5+
Given a WP install with SQLite
6+
And a session_yes file:
7+
"""
8+
y
9+
"""
10+
11+
When I run `wp db create`
12+
Then the return code should be 1
13+
And STDERR should contain:
14+
"""
15+
Database already exists
16+
"""
17+
18+
When I run `wp db size`
19+
Then STDOUT should contain:
20+
"""
21+
.ht.sqlite
22+
"""
23+
24+
When I run `wp db tables`
25+
Then STDOUT should contain:
26+
"""
27+
wp_posts
28+
"""
29+
30+
@require-sqlite
31+
Scenario: SQLite DB query
32+
Given a WP install with SQLite
33+
34+
When I run `wp db query 'SELECT COUNT(*) as total FROM wp_posts'`
35+
Then STDOUT should contain:
36+
"""
37+
total
38+
"""
39+
40+
@require-sqlite
41+
Scenario: SQLite DB export/import
42+
Given a WP install with SQLite
43+
44+
When I run `wp post list --format=count`
45+
Then STDOUT should contain:
46+
"""
47+
1
48+
"""
49+
50+
When I run `wp db export /tmp/wp-cli-sqlite-behat.sql`
51+
Then STDOUT should contain:
52+
"""
53+
Success: Exported
54+
"""
55+
56+
When I run `wp db reset < session_yes`
57+
Then STDOUT should contain:
58+
"""
59+
Success: Database reset
60+
"""
61+
62+
When I run `wp db import /tmp/wp-cli-sqlite-behat.sql`
63+
Then STDOUT should contain:
64+
"""
65+
Success: Imported
66+
"""
67+
68+
When I run `wp post list --format=count`
69+
Then STDOUT should contain:
70+
"""
71+
1
72+
"""
73+
74+
@require-sqlite
75+
Scenario: SQLite commands that show warnings
76+
Given a WP install with SQLite
77+
78+
When I run `wp db check`
79+
Then STDOUT should contain:
80+
"""
81+
Warning: Database check is not supported for SQLite databases
82+
"""
83+
84+
When I run `wp db optimize`
85+
Then STDOUT should contain:
86+
"""
87+
Warning: Database optimization is not supported for SQLite databases
88+
"""
89+
90+
When I run `wp db repair`
91+
Then STDOUT should contain:
92+
"""
93+
Warning: Database repair is not supported for SQLite databases
94+
"""
95+
96+
When I run `wp db cli`
97+
Then STDOUT should contain:
98+
"""
99+
Warning: Interactive console (cli) is not supported for SQLite databases
100+
"""

0 commit comments

Comments
 (0)