shadowprince/autoparis

Automated scheme creator & updater integrated and built for idiorm & paris. Currenlty works only with MySQL

0.1.3 2013-11-17 12:09 UTC

This package is not auto-updated.

Last update: 2024-12-16 15:44:15 UTC


README

Autoparis is a library, that extends j4mie's paris ORM for automated scheme creation and keeping it up to date.

How to use it?

Installing

Autoparis can be simply installed by composer, actual install information you can found at page on packagist.

Requirements

  1. Model should extend \Autoparis\AutoModel and provide public ( non static ) method getFields(). It should return array of instances of \Autoparis\Field or classes extending it.
  2. public static $_field of every model should be setted up.
  3. You should provide lookup_models() function in bin/autoparis.php, that'll return array of models classes
  4. And you should properly configure idiorm when you start autoparis (you can get trough it simply including your project boostrap, that will call ORM::configure's)

Usage

Autoparis is a cli-tool, located in bin/autoparis.php. You can get help trough --help. Autoparis has behavior like django's tool. By default, autoparis will update all schemes for models returned by lookup_models() Like django, autoparis will not modify your tables if you dont provide --force option, because that action can damage data, so dont run it on production databases.

Documentation

There is documentation, that covers few topics that might be unclear and usefull.

Examples

// model class
class User extends \Autoparis\AutoModel {
    public static $_table = 'users';

    public function getFields() {
        return [
            new \Autoparis\Int("id", ["nn" => true]),
            new \Autoparis\Varchar("username", 32),
            new \Autoparis\Varchar("password"", 32),
            new \Autoparis\DateTime("joined", ["default" => "now"])
        ];
    }

// in autoparis.php
ORM::configure(...);

function lookup_models() {
    return ["\User"];
}

$ ./autoparis.php
    Processing \User...
    Up to date.
mysql [db]> show columns from users;
    +----------+-------------+------+-----+---------+-------+
    | Field    | Type        | Null | Key | Default | Extra |
    +----------+-------------+------+-----+---------+-------+
    | id       | int(11)     | NO   |     | NULL    |       |
    | username | varchar(32) | YES  |     | NULL    |       |
    | password | varchar(32) | YES  |     | NULL    |       |
    | joined   | datetime    | YES  |     | NULL    |       |
    +----------+-------------+------+-----+---------+-------+