kenny1911/doctrine-views-sync
最新稳定版本:0.2.0
Composer 安装命令:
composer require kenny1911/doctrine-views-sync
包简介
Tools for sync database views, using doctrine
README 文档
README
[ English | Русский ]
Doctrine Views Sync is a lightweight utility for managing database views in Doctrine-based projects. It allows you to synchronize or drop all views via console commands.
Installation
Install the package via Composer:
composer require kenny1911/doctrine-views-sync
Usage
Two console commands are available:
Drop all views
php bin/console doctrine:views:drop
Drops all views in the database that are defined in your project.
Synchronize views
php bin/console doctrine:views:sync
Synchronizes all views — recreates them based on the current application state.
Requirements
- PHP >= 8.1
- Doctrine DBAL
- Symfony Console (if used outside of Symfony, additional setup may be required)
Configuration
Symfony Framework
Example Symfony configuration using a single Doctrine connection.
Basic service registration and command wiring:
services: doctrine.views_provider: class: Kenny1911\DoctrineViewsSync\ViewsProvider\ChainViewsProvider arguments: - !tagged_iterator 'doctrine.views_provider' doctrine.views_sync.metadata_storage: class: Kenny1911\DoctrineViewsSync\Metadata\TableMetadataStorage arguments: - '@doctrine.dbal.default_connection' doctrine.views_sync.factory: class: Kenny1911\DoctrineViewsSync\ViewsSyncFactory factory: [null, 'fromSingleConnection'] arguments: - '@doctrine.dbal.default_connection' - '@doctrine.views_provider' - '@doctrine.views_sync.metadata_storage' Kenny1911\DoctrineViewsSync\Console\ViewsDropCommand: arguments: - '@doctrine.views_sync.factory' autoconfigure: true Kenny1911\DoctrineViewsSync\Console\ViewsSyncCommand: arguments: - '@doctrine.views_sync.factory' autoconfigure: true
Services implementing the Kenny1911\DoctrineViewsSync\ViewsProvider interface must be tagged with doctrine.views_provider.
Example ViewsProvider implementation:
use Doctrine\DBAL\Schema\View; final readonly class UsersViewsProvider implements \Kenny1911\DoctrineViewsSync\ViewsProvider { public function getViews() : iterable { yield new View( name: 'users_credentials', sql: 'SELECT id, username, password FROM users', ); } }
services: UsersViewsProvider: tags: - 'doctrine.views_provider'
To configure the database schema, use the TableMetadataStorage::configureSchema() method.
Development
Tests will run with in-memory sqlite db by default.
If you want to run tests with other dbms, set environment variable DATABASE_URL.
File docker-compose.yml contains prepared settings for different dbms. You must run database servers before run tests
and down after tests was passed.
Running tests example:
# Postgres DATABASE_URL='pdo-pgsql://postgres:123@localhost:5432/views-sync' ./vendor/bin/phpunit
License
MIT
统计信息
- 总下载量: 1.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-14