laykou / schema
CakePHP 3.0 的 Schema 文件保存和加载
此包的官方仓库似乎已消失,因此包已被冻结。
dev-master
2017-01-24 21:32 UTC
Requires
- php: >=5.4
- cakephp/cakephp: ~3.0
Requires (Dev)
- cakephp/bake: dev-master
- phpunit/phpunit: *
This package is not auto-updated.
Last update: 2023-03-10 15:15:41 UTC
README
将 schema 保存到一个文件中,然后从 schema 文件恢复数据库。执行 cake migrations migrate
时将自动保存 schema。
支持的数据库源
- Postgres
- MySQL
- SQL Server
SQLite目前不支持
安装
您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。
安装 composer 包的推荐方法是
composer require-dev laykou/schema
更新您的 `config/bootstrap.php``
Plugin::load('Schema', ['bootstrap' => true]);
使用方法
该插件将 default
连接的 schema 保存到 config/schema.php
文件。结构与 fixtures 字段相似。
cake schema save
要加载 schema,请执行以下操作
cake schema load
在加载之前将删除数据库中所有现有的表。您将被要求
Loading the schema from the file Database is not empty. 37 tables will be deleted.
Do you want to continue? (y/n)
要禁用此询问(并以“是”回答)请运行
cake schema load --no-interaction
种子
Schema 插件允许您从 config/seed.php
文件中加载数据。`seed.php` 文件应返回包含表和行的数组
<?php // You can work with custom libraries here or use the Cake's ORM return [ 'articles' => [ [ 'id' => 1, 'category_id' => 1, 'label' => 'CakePHP' ], [ 'id' => 2, 'label' => 'Schema plugin' ] ], 'categories' => [ [ 'id' => 2, 'label' => 'Frameworks' ] ] ];
其他示例
cake schema save --connection test cake schema save --path config/schema/schema.lock cake schema load --connection test --path config/schema/schema.lock --no-interaction # To only drop all tables in database cake schema drop cake schema drop --connection test # Truncate tables before inserting. Otherwise duplicate ID exception is thrown. cake schema seed --truncate cake schema seed --seed custom/path/to/seed.php cake schema seed --connection test --truncate
要向数据库中加载数据,请运行以下命令
cake schema seed
待办事项
cake migrations migrate
后自动创建 schema.php 文件- 数据加种
- 测试
- 更多选项和配置
- 重构和清理代码
已知问题
- SQLite 不完全支持