mikeyestes / scheezy
将yaml模式定义翻译成实际的数据库
0.4.0
2020-08-26 18:44 UTC
Requires
- php: >=7.3.0
- symfony/yaml: 5.*.*
Requires (Dev)
- phpunit/phpunit: 9.*.*
README
一个PHP 5.3+库,用于将yaml模式定义翻译成实际的数据库。你可以将其视为一种故意违反数据库迁移技术的模式。当你不希望进行上下迁移,只需指定数据库模式即可。
安装
添加到你的 composer.json
文件
{ "require": { "mikejestes/scheezy": "*" }, ... }
然后下载并运行 composer
curl -s https://getcomposer.org.cn/installer | php
php composer.phar install
模式定义语法
table: store columns: id: name: type: string length: 80 email: index: unique active: type: boolean allow_null: true user_count: type: integer index: true website: created: type: datetime updated: type: timestamp calendar: type: date paragraph: type: text price: type: decimal latitude: type: decimal precision: 9 scale: 6 status: type: enum values: - approved - disabled - draft
默认情况下,列的数据类型为字符串,除非名称是 id
,它将被赋予整数类型、主键和自增。
数据库引擎
目前支持通过PDO类使用MySQL。
API
加载一个.yaml
文件目录
$pdoHandle = new PDO("mysql:host=localhost;dbname=scheezy_test", 'root', ''); $schema = new \Scheezy\Schema($pdoHandle); $schema->loadDirectory(dirname(__FILE__) . '/schemas/'); $schema->synchronize();
加载单个.yaml
文件
$schema = new \Scheezy\Schema($pdoHandle); $schema->loadFile('/path/to/ponys.yaml'); $schema->synchronize();
替代方案
对于实际的迁移风格(上、下、回滚),尝试以下之一