bilhackmac / databases-manager-module
允许管理多个数据库连接
Requires
- thelia/installer: ~1.1
README
允许管理其他模块的多个数据库连接,并提供解析具有多个定义的 schema.xml
文件的命令。
安装
手动...
将模块复制到 <thelia_root>/local/modules/
目录,并确保模块的名称是 DatabasesManager
。
… 或者使用 Composer
在主 thelia 的 composer.json
文件中添加它。
composer require bilhackmac/databases-manager-module:~1.0
然后
在 thelia 管理面板中激活它。
使用方法
1. schema.xml
未修改的 schema.xml
文件将继续按预期工作,但现在您可以添加一个新的根节点 databases
而不是 database
。
<databases> <database defaultIdMethod="native" name="thelia" namespace="Module\Namespace\Model"> <table name="theliaTable"> <column type="integer" name="id" required="true" primaryKey="true" autoIncrement="true"/> <column type="integer" name="field" required="true"/> </table> <external-schema filename="local/config/schema.xml" referenceOnly="true" /> </database> <database defaultIdMethod="native" name="anotherDB" namespace="Module\Namespace\Model"> <!-- Note database name for later --> <table name="externalTable"> <column type="integer" name="id" required="true" primaryKey="true" autoIncrement="true"/> <column type="integer" name="field" required="true"/> </table> </database> <!-- Add any database node you need ---> </databases>
2. 命令
数据库管理器覆盖了两个 Thelia 2 命令并添加了一个。
php Thelia module:generate:model <moduleName>
并且
php Thelia module:generate:sql <moduleName>
始终按预期工作,但现在处理 schema.xml
文件中的 databases
和多个 database
节点。这些命令还为配置文件中的每个未知数据库名称添加了一个空的数据库配置(例如:在之前的 schema.xml
中的 anotherDB
)。
php Thelia module:schema:recovery <moduleName>
可以在执行前两个命令中的任何一个命令时发生意外退出时恢复 schema.xml
(例如: Ctrl + C
)。
3. 配置
通过在后台办公室模块管理器中点击 Configure
访问数据库配置。您现在可以添加/编辑/删除数据库配置。
但请注意,配置标签必须与 schema.xml
中 database
节点的名称相同,否则,模型将无法找到其数据库的连接。
您可以为当前环境定义数据库配置(默认为 prod
,当通过 index_dev.php
访问时为 dev
)。具有相同标签的环境配置将覆盖共享配置。
如果您不希望 dev
环境访问与 prod
环境相同的数据库,这可能会很有用。
4. 覆盖 Thelia 默认配置
这个功能看起来似乎可以工作,但尚未经过测试。
如果您想连接到除默认数据库之外的其他 Thelia 数据库,请将其标记为 thelia
。这样,您就可以有一个生产数据库和一个开发数据库。