Database
Foundation Database provides three focused capabilities for WordPress applications: versioned schema migrations, a small inspectable query API, and a database-backed implementation of the Foundation Lock contract. It intentionally builds on wpdb, dbDelta(), and WordPress table prefixes instead of acting as a generic database abstraction.
Installation
Section titled “Installation”Install the runtime package in the application:
Foundation Database installs its Container, Lock, and WP-CLI runtime dependencies automatically. Install stellarwp/foundation-cli separately with --dev only when the project uses its migration and table generators.
Prepare the application
Section titled “Prepare the application”Database services use the application’s existing container, provider graph, Foundation prefix, and WP-CLI command prefix:
Configuration
Section titled “Configuration”Scope database resources
Section titled “Scope database resources”Set a stable application prefix in the root config.php for a standalone plugin:
With this prefix, Foundation uses these resources by default:
| Resource | Default |
|---|---|
| Migration table | <wp_prefix>your_plugin_foundation_migrations |
| Lock table | <wp_prefix>your_plugin_foundation_locks |
| Migration lock | your-plugin-foundation-database-migrations |
| WP-CLI command | wp your-plugin migrate |
Complete WordPress applications that own the entire installation can keep the zero-configuration nx prefix. Standalone plugins should not share the default because another Foundation consumer could otherwise read the same migration ledger or contend for the same lock.
Keep the prefix stable after migrations have run. Changing it points the application at a different ledger and lock table, making every configured migration appear pending.
Override individual resources
Section titled “Override individual resources”Package-specific settings in the root config.php override values derived from foundation.prefix:
Leave table names empty to use the scoped defaults. An overridden table name is the complete physical name and must include the WordPress table prefix itself. All physical table names must fit MySQL’s 64-character identifier limit.
The migration lock settings coordinate migration execution only. Applications selecting DatabaseLock for their own work choose each lock name and TTL when calling acquire().
Set database.lock_ttl longer than the longest uninterrupted operation between renewals. Foundation renews the migration lock immediately before and after every up() and down() call, but it cannot renew the lease while a blocking migration method or ledger update is still running. Split unusually long work into separate migrations or increase FOUNDATION_DATABASE_LOCK_TTL before deployment.
Register the providers
Section titled “Register the providers”In src/App.php, register WPCliProvider before DatabaseProvider, then register application providers that contribute migrations or select the database lock:
DatabaseProvider configures wpdb, schema services, migration storage, the migration lock, and the migrate command. It does not create tables, run migrations, or select DatabaseLock as the application’s general Lock implementation during WordPress bootstrap.