mikejestes/scheezy

Translate yaml schema definitions into real actual databases

Installs: 4 177

Dependents: 0

Stars: 1

Watchers: 2

Forks: 1

Language: PHP

0.2.1 2014-04-17 18:30 UTC

README

A PHP 5.3+ library to translate yaml schema definitions into real, actual databases. You could view this as an intentional anti-pattern to database migration techniques. For when you don't want to migrate up and down, just dictate the database schema.

Build Status

Installation

Add to your composer.json file:

    {
        "require": {
            "mikejestes/scheezy": "*"
        },

        ...
    }

Then download and run composer:

curl -s https://getcomposer.org/installer | php
php composer.phar install

Schema Definition Syntax

table: store
columns:
    id:
    name:
        type: string
        length: 80
    email:
        index: unique
    active:
        type: boolean
    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

A column defaults to string type, unless the name is id which is given an integer type, a primary key, and auto_increment.

Database engines

Currently supports mysql through PDO classes.

API

Load a directory of .yaml files

$pdoHandle = new PDO("mysql:host=localhost;dbname=scheezy_test", 'root', '');

$schema = new \Scheezy\Schema($pdoHandle);
$schema->loadDirectory(dirname(__FILE__) . '/schemas/');
$schema->synchronize();

Load a single .yaml file

$schema = new \Scheezy\Schema($pdoHandle);
$schema->loadFile('/path/to/ponys.yaml');
$schema->synchronize();

Alternatives

For actual migration style (up, down, rollback) try one of these: