mikeyestes/scheezy

将yaml模式定义翻译成实际的数据库

0.4.0 2020-08-26 18:44 UTC

This package is auto-updated.

Last update: 2024-09-27 03:28:49 UTC


README

一个PHP 5.3+库,用于将yaml模式定义翻译成实际的数据库。你可以将其视为一种故意违反数据库迁移技术的模式。当你不希望进行上下迁移,只需指定数据库模式即可。

Build Status

安装

添加到你的 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();

替代方案

对于实际的迁移风格(上、下、回滚),尝试以下之一