Add MySQL support to Lib\Db via multiple simultaneous named connections
Redesigns Lib\Db from a single global connection to a config-driven map
of named connections (config['db_connections']), each independently
lazy-connected, each with its own optional migrations_dir and its own
schema_migrations table. A sidecar can use more than one connection in
the same request (e.g. Db::query(...) against SQLite alongside
Db::query(..., 'legacy') against MySQL) — sidecars have full access to
any Lib\ class, so nothing stops a request from needing two databases
at once, which the original single-driver spec didn't account for.
Db::query()/Db::connection() both default to the 'default' connection
name so the common single-database case is unchanged at the call site.
Supersedes the flat db_driver/db_path/db_migrations_dir keys shipped in
the SQLite groundwork commit (a3b9967) — no downstream consumers yet,
so no migration path needed.
db_connections needed one deliberate exception to the project's usual
shallow config-merge rule: merged one level deeper, by connection name,
so App/config.php adding a connection doesn't delete 'default'. Verified
end-to-end against a real local MariaDB instance running alongside the
existing SQLite connection, which caught a real ordering bug in the
initial merge implementation (capturing defaults after they'd already
been overwritten) before it shipped.
Closes the "MySQL support" backlog item in novaconium/ISSUES.md.
This commit is contained in:
+16
-4
@@ -21,8 +21,20 @@ return [
|
||||
// 'admin_username' => 'admin',
|
||||
// 'admin_password_hash' => '$2y$10$...',
|
||||
|
||||
// Docs: /admin/docs/database
|
||||
// 'db_driver' => 'sqlite',
|
||||
// 'db_path' => __DIR__ . '/../data/novaconium.sqlite',
|
||||
// 'db_migrations_dir' => __DIR__ . '/migrations',
|
||||
// Docs: /admin/docs/database — adds (or overrides) named Lib\Db
|
||||
// connections. This merges into db_connections by name rather than
|
||||
// replacing the whole map, so adding 'legacy' here doesn't require
|
||||
// repeating 'default' — see Lib\Db::config().
|
||||
// 'db_connections' => [
|
||||
// 'legacy' => [
|
||||
// 'driver' => 'mysql',
|
||||
// 'host' => 'localhost',
|
||||
// 'port' => 3306,
|
||||
// 'database' => 'legacy_app',
|
||||
// 'username' => 'root',
|
||||
// 'password' => '...',
|
||||
// 'charset' => 'utf8mb4', // optional, defaults to utf8mb4
|
||||
// 'migrations_dir' => __DIR__ . '/migrations/legacy', // optional
|
||||
// ],
|
||||
// ],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user