ddrv/baseman

database manager

0.9.0 2018-04-24 12:29 UTC

README

Install

php composer.phar require ddrv/baseman

Now supported only SQLite

Usage

<?php

use Ddrv\Baseman\Migration;
use Ddrv\Baseman\Field;

$connection = new PDO('sqlite:/path/to/database.file');

$m = new Migration($connection);

/* 
 * Create text field field1 with default value 'some text'
 * Table table1 be created automatically
 */
$m->field('table1', 'field1', Field::text('some text'));

/* Create nullable text field field2*/
$m->field('table1', 'field2', Field::text()->nullable());

/* Create integer field with default value 100 */
$m->field('table2', 'field1', Field::integer(100));

/* Create some field */
$m->field('table2', 'unused', Field::integer());

/* Primary keys */
$m->primary('table2', 'field1');
$m->primary('table1', array('field1', 'field2'));

/* Unique */
$m->unique('table1', 'field2');
$m->unique('table2', array('field1','unused'));

/* Index */
$m->index('table1', 'field2');
$m->index('table2', array('field1','unused'));

/* Drop field unused from table 2*/
$m->drop('table2', 'unused');

/* Drop table 2*/
$m->drop('table2');

/* Rename tables */
$m->renameTable('table1', 'super_table');

/* Rename fields */
$m->renameField('super_table', 'field1', 'super_field');

/* apply changes */
$m->run();

TODO

  • Fully support for SQLite;
  • Support for MySql;
  • Support for PostgreSQL;
  • Other PDO drivers.