{"id":15529363,"url":"https://github.com/mnapoli/dbal-schema","last_synced_at":"2025-08-16T21:06:40.555Z","repository":{"id":44775121,"uuid":"84128564","full_name":"mnapoli/dbal-schema","owner":"mnapoli","description":"DB schema manager for Doctrine DBAL","archived":false,"fork":false,"pushed_at":"2023-12-20T20:42:03.000Z","size":40,"stargazers_count":97,"open_issues_count":0,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-08-08T19:06:00.459Z","etag":null,"topics":["db-schema","doctrine","doctrine-dbal","php"],"latest_commit_sha":null,"homepage":null,"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/mnapoli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","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,"publiccode":null,"codemeta":null},"funding":{"github":"mnapoli","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2017-03-06T22:42:08.000Z","updated_at":"2024-10-06T22:54:08.000Z","dependencies_parsed_at":"2023-12-20T21:52:46.182Z","dependency_job_id":null,"html_url":"https://github.com/mnapoli/dbal-schema","commit_stats":{"total_commits":34,"total_committers":9,"mean_commits":"3.7777777777777777","dds":0.5294117647058824,"last_synced_commit":"a923ed6642247788b4b1b2538b2bc2c07f2485b5"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/mnapoli/dbal-schema","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fdbal-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fdbal-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fdbal-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fdbal-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnapoli","download_url":"https://codeload.github.com/mnapoli/dbal-schema/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnapoli%2Fdbal-schema/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270770276,"owners_count":24642112,"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","status":"online","status_checked_at":"2025-08-16T02:00:11.002Z","response_time":91,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["db-schema","doctrine","doctrine-dbal","php"],"created_at":"2024-10-02T11:17:28.033Z","updated_at":"2025-08-16T21:06:40.511Z","avatar_url":"https://github.com/mnapoli.png","language":"PHP","readme":"A schema manager for [Doctrine DBAL](http://www.doctrine-project.org/projects/dbal.html): all the convenience of the Doctrine ORM, without using the ORM.\n\n## Why?\n\nDoctrine ORM can automatically manage your DB schema based on your entity mapping. This feature is lost when using the DBAL instead of the ORM.\n\nThis package lets you achieve something similar by defining your DB schema with PHP code. It also lets you manage your database using a Symfony Console command similar to Symfony's native `doctrine:schema:update` command, as well as DB migrations.\n\n## Installation\n\n```bash\ncomposer require mnapoli/dbal-schema\n```\n\n## Usage\n\n### 1. Define a schema\n\nDefine your DB schema by implementing the `SchemaDefinition` interface:\n\n```php\nclass MySchemaDefinition implements \\DbalSchema\\SchemaDefinition\n{\n    public function define(Schema $schema)\n    {\n        $usersTable = $schema-\u003ecreateTable('users');\n        $usersTable-\u003eaddColumn('id', 'integer');\n        $usersTable-\u003eaddColumn('email', 'string');\n        $usersTable-\u003eaddColumn('lastLogin', 'datetime');\n        $usersTable-\u003eaddColumn('score', 'float', [\n            'notnull' =\u003e false,\n        ]);\n        $usersTable-\u003esetPrimaryKey(['id']);\n        $usersTable-\u003eaddUniqueIndex(['email']);\n    }\n}\n```\n\nYou can read the whole API available on [Doctrine's documentation](http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/schema-representation.html).\n\n### 2. Set up the schema\n\nDoctrine can now generate/update your database based on your schema.\n\n#### Using Symfony\n\nHere is an example of configuration that can go in your `config/services.yml`:\n\n```yaml\nservices:\n\n    DbalSchema\\SchemaDefinition:\n        # Replace this with your class name\n        alias: App\\Database\\MySchemaDefinition\n    DbalSchema\\DbalSchemaProvider:\n    # Register the commands:\n    DbalSchema\\DbalSchemaCommand:\n    DbalSchema\\Command\\UpdateCommand:\n    DbalSchema\\Command\\PurgeCommand:\n```\n\nThis configuration assumes your services are autowired.\n\nOnce the services are registered, you can now run the commands:\n\n```bash\nbin/console dbal:schema:update\nbin/console dbal:schema:purge\n```\n\n#### Using [Silly](https://github.com/mnapoli/silly)\n\nUsing Silly you can ignore the many separate command classes and simply use the `DbalSchemaCommand` class:\n\n```php\n$schema = new MySchemaDefinition();\n$dbalConnection = /* your DBAL connection, see http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html */\n\n$command = new DbalSchemaCommand($dbalConnection, $schema);\n\n$application = new Silly\\Application();\n$application-\u003ecommand('db [--force]', [$command, 'update']);\n$application-\u003ecommand('db-purge [--force]', [$command, 'purge']);\n$application-\u003erun();\n```\n\nIf you are using the [Silly PHP-DI edition](https://github.com/mnapoli/silly/blob/master/docs/php-di.md) it's even simpler as [PHP-DI](http://php-di.org/) can instantiate the `DbalSchemaCommand` service:\n\n```php\n$application-\u003ecommand('db [--force]', [DbalSchemaCommand::class, 'update']);\n$application-\u003ecommand('db-purge [--force]', [DbalSchemaCommand::class, 'purge']);\n```\n\n### 3. Optional: database migrations\n\nIf you prefer using database migrations instead of running `bin/console dbal:schema:update`, DBAL Schema integrates with Doctrine Migrations.\n\nTo set it up, we need the `setService()` method call to happen like in the example below:\n\n```php\nuse Doctrine\\Migrations\\DependencyFactory;\nuse Doctrine\\Migrations\\Provider\\SchemaProvider;\nuse DbalSchema\\DbalSchemaProvider;\n\n$doctrineMigrationDependencyFactory = DependencyFactory::fromConnection(...);\n\n$doctrineMigrationDependencyFactory-\u003esetService(SchemaProvider::class, new DbalSchemaProvider(new MySchemaDefinition()));\n```\n\nIn Symfony, it can be done by installing the [DoctrineMigrationsBundle](https://symfony.com/doc/current/bundles/DoctrineMigrationsBundle/index.html) and editing `config/packages/doctrine_migrations.yaml`:\n\n```yml\ndoctrine_migrations:\n    # ...\n    services:\n        Doctrine\\Migrations\\Provider\\SchemaProvider: DbalSchema\\DbalSchemaProvider\n```\n\nNow, you can run:\n\n```bash\nbin/console doctrine:migrations:diff\n```\n\nto generate migrations based on your DBAL schema.\n","funding_links":["https://github.com/sponsors/mnapoli"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnapoli%2Fdbal-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnapoli%2Fdbal-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnapoli%2Fdbal-schema/lists"}