{"id":19022522,"url":"https://github.com/envor/laravel-managed-databases","last_synced_at":"2026-05-09T09:40:35.272Z","repository":{"id":221444554,"uuid":"753227600","full_name":"envor/laravel-managed-databases","owner":"envor","description":"Manage multiple databases and their connections at runtime using laravel tools","archived":false,"fork":false,"pushed_at":"2024-03-04T09:50:26.000Z","size":46,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-03-12T18:21:29.052Z","etag":null,"topics":["database","database-management","laravel"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/envor.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"envor"}},"created_at":"2024-02-05T18:01:06.000Z","updated_at":"2024-04-15T11:24:55.455Z","dependencies_parsed_at":"2024-04-15T11:24:46.976Z","dependency_job_id":null,"html_url":"https://github.com/envor/laravel-managed-databases","commit_stats":null,"previous_names":["envor/laravel-managed-databases"],"tags_count":8,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envor%2Flaravel-managed-databases","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envor%2Flaravel-managed-databases/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envor%2Flaravel-managed-databases/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/envor%2Flaravel-managed-databases/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/envor","download_url":"https://codeload.github.com/envor/laravel-managed-databases/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240072067,"owners_count":19743526,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database","database-management","laravel"],"created_at":"2024-11-08T20:26:33.074Z","updated_at":"2026-04-29T04:30:22.828Z","avatar_url":"https://github.com/envor.png","language":"PHP","funding_links":["https://github.com/sponsors/envor"],"categories":[],"sub_categories":[],"readme":"## A small package for managing multiple databases and their connections at runtime using laravel tools\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/envor/laravel-managed-databases.svg?style=flat-square)](https://packagist.org/packages/envor/laravel-managed-databases)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/envor/laravel-managed-databases/run-tests.yml?branch=main\u0026label=tests\u0026style=flat-square)](https://github.com/envor/laravel-managed-databases/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/envor/laravel-managed-databases/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style\u0026style=flat-square)](https://github.com/envor/laravel-managed-databases/actions?query=workflow%3A\"Fix+PHP+code+style+issues\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/envor/laravel-managed-databases.svg?style=flat-square)](https://packagist.org/packages/envor/laravel-managed-databases)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require envor/laravel-managed-databases\n```\n\n## Usage\n\n[createDatabase()](#manageddatabasescreatedatabase)    \n[runOnDatabase()](#manageddatabasesrunondatabase)    \n[configureDatabase()](#manageddatabasesconfiguredatabase)\n\n### #`ManagedDatabases::createDatabase()`\n\nThe `createDatabase()` method will\n\n- Cache the current default database connection config\n- Set the connection to the `$managerConnection`\n- Purge the connection and reconnect\n- Create the physical database\n- Purge the connection\n- Restore original default connection\n- Purge and reconnect\n\n\u003e [!TIP]\n\u003e The `$managerConnection` must exist and be a configured database connection.    \n\u003e This package creates a few defaults: `manager_sqlite`, `manager_mysql` and `manager_mariadb`.    \n\u003e They are bootstrapped into memory by cloning the default configs for `sqlite`, `mysql` and `mariadb`.\n\n```php\nuse Envor\\ManagedDatabases\\ManagedDatabases;\n\n$managerConnection = 'manager_sqlite';\n$name = 'database'\n\nManagedDatabases::createDatabase($name, $managerConnection);\n\n// database\n```\n\n### #`ManagedDatabases::runOnDatabase()`\n\nThe `runOnDatabase()` method will connect the given `$database` using a new connection created with the credentials and options from the given `$managerConnection`, execute the given `$callback`, then finally, restore the original default database connection.\n\n- Cache the current default database connection config\n- Create a new connection config for the database by cloning the `$managerConnection` config\n- Set the database as default and connect to it\n- Run the given callback\n- Purge the connection\n- Restore original default connection\n- Purge and reconnect\n\n```php\nuse Envor\\ManagedDatabases\\ManagedDatabases;\n\nManagedDatabases::runOnDatabase(\n    $database = 'database', \n    $callback = fn() =\u003e Artisan::call('migrate', ['--force' =\u003e true]), \n    $managerConnection = 'manager_sqlite'\n);\n```\n\nThe package also includes an `artisan` wrapper for the `runOnDatabase()` method called `managed-databases:run`.\nThe simplest and most harmless way to check it out is by pasting the following command into your terminal:\n\n```bash\nphp artisan managed-databases:run \"migrate:fresh --seed\" --database=\":memory:\" --managerConnection=\"sqlite\"\n```\n\nThis will run your migrations and seeders harmlessly against an in-memory sqlite database. A great way to quickly check if they can run without errors.\n\n### #`ManagedDatabases::configureDatabase()`\n\nThe `configureDatabase()` method will set the given database as the default on on a brand new connection modeled after the given `$managerConnection`\n\n```php\nuse Envor\\ManagedDatabases\\ManagedDatabases;\n\nManagedDatabases::createDatabase('database2', 'sqlite');\n\nManagedDatabases::useDatabase('database2', 'sqlite');\n\nconfig('database.default');\n\n// database2\n\nconfig('database.connections.database2')\n\n// [\n//     \"driver\" =\u003e \"sqlite\",\n//     \"url\" =\u003e null,\n//     \"database\" =\u003e \"/home/forge/mysite.com/storage/app/managed_database2.sqlite\",\n//     \"prefix\" =\u003e \"\",\n//     \"foreign_key_constraints\" =\u003e true,\n// ]\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [inmanturbo](https://github.com/envor)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvor%2Flaravel-managed-databases","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fenvor%2Flaravel-managed-databases","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fenvor%2Flaravel-managed-databases/lists"}