itemvirtual / laravel-doctrine
Laravel 框架的 Doctrine 控制台命令
1.0.6
2023-03-14 15:44 UTC
Requires
- php: ^7.1 || ^8.0
- doctrine/annotations: ^1.13
- doctrine/orm: ^2.12.3
- symfony/cache: ^6.0
Requires (Dev)
README
Laravel 框架的 Doctrine 控制台命令。
此包仅用于保持数据库同步(而不是迁移)。
更新、验证并从数据库生成 xml-mapping。
安装
您可以通过 composer 安装此包
composer require itemvirtual/laravel-doctrine
为了编辑默认配置,您可以执行: (使用 --force
选项进行更新)
php artisan vendor:publish --provider="Itemvirtual\LaravelDoctrine\LaravelDoctrineServiceProvider" --tag=config
Laravel 包含一些预定义的迁移,您可以使用此命令将其放置到位
php artisan vendor:publish --provider="Itemvirtual\LaravelDoctrine\LaravelDoctrineServiceProvider" --tag=laravel_default_migrations
用法
· 从数据库生成 xml-mapping
此命令仅当您已有现有数据库时有用,您通常不需要多次调用此方法
您可以为生成的文件提供目标路径。
您还可以选择仅生成特定表的映射。
php artisan doctrine:generate-mappings [--path=destination/path/to/xml-mappings] [--table=<table_name>]+ php artisan doctrine:generate-mappings --path=database/doctrine/xml-mappings --table=ursers --table=password_resets
选项
--path[=PATH] The path where your xml-mapping files will be generated
--table[=TABLE] The database tables to be generated (multiple values allowed)
· 验证映射和数据库
检查关联是否定义正确,以及其映射是否与数据库同步。
在执行验证之前,您可以删除所有实体。
php artisan doctrine:validate [-R | --remove-entities]
选项
-R, --remove-entities Delete current entities before generating new ones
· 更新数据库
运行更新数据库的查询,或在不查询的情况下预览它们。
在升级之前,您可以删除所有实体。
每次运行此命令时,都会调用 doctrine:generate-entities
php artisan doctrine:update [-D | --dump-sql] [-R | --remove-entities] php artisan doctrine:update -DR
选项
-D, --dump-sql Dumps generated SQL statements to the console (does not execute them)
-R, --remove-entities Delete current entities before generating new ones
· 清除缓存
有时您可能会遇到缺失实体错误,删除缓存数据可以帮助修复它。
php artisan doctrine:clear-cache [--flush]
# This command will run these three commands at once, you can run them separately if you want
php artisan doctrine:clear-cache:metadata [--flush]
php artisan doctrine:clear-cache:query [--flush]
php artisan doctrine:clear-cache:result [--flush]
选项
--flush If defined, cache entries will be flushed instead of deleted/invalidated
· 生成迁移(用于测试)
出于测试目的,您需要项目迁移。您可以使用以下命令生成它。
默认情况下,它们将生成在 tests/database/migrations
php artisan doctrine:migrations-generate [destination/path] php artisan doctrine:migrations-generate --tables users,password_resets --ignore users,password_resets
参数
path If defined, it will generate the files in the given path, by default
选项
-R, --remove Remove previous generated migration files
-O, --output View migrations package console output
-S, --single-file[=SINGLE-FILE] Generate all migrations in a single file [default: "true"]
-T, --tables[=TABLES] A list of Tables or Views you wish to Generate Migrations separated by comma: users,products,labels
-I, --ignore[=IGNORE] A list of Tables or Views you wish to ignore, separated by comma: users,products,labels
"doctrine" 命名空间下可用的命令
doctrine:clear-cache Clear metadata, query and result cache of the various cache drivers doctrine:clear-cache:metadata Clear all metadata cache of the various cache drivers doctrine:clear-cache:query Clear all query cache of the various cache drivers doctrine:clear-cache:result Clear all result cache of the various cache drivers doctrine:convert-mapping Convert mapping information between supported formats doctrine:generate-entities Generate entity classes and method stubs from your mapping information (xml-mappings) doctrine:generate-mappings Generate xml-mappings from your database doctrine:remove-entities Remove all entities doctrine:update Update the database (or dump SQL) based on the entities information doctrine:validate Validate mappings and synchronization with the database doctrine:migrations-generate Generate laravel migration files from database
您可以使用帮助命令查看每个命令的参数和选项
php artisan -help <command>
utf8mb4
要更改表的字符集和校对规则,请将此 options
添加到 entity
<options> <option name="collate">utf8mb4_unicode_ci</option> <option name="charset">utf8mb4</option> </options>
mysql 5.7 的问题
mysql 版本低于 5.7.7 可能会抛出错误 "指定的键太长;最大键长度为 767 字节"
您必须验证任何类型为 string
且 unique=true
的列必须设置其最大长度 length="190"
重要,检查索引
变更日志
有关最近更改的更多信息,请参阅 变更日志
贡献
有关详细信息,请参阅 贡献指南
致谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件