mikejestes/scheezy

Translate yaml schema definitions into real actual databases

0.4.0 2020-08-26 18:44 UTC

This package is auto-updated.

Last update: 2024-10-27 03:36:57 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
        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

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: