Coder Social home page Coder Social logo

rawmigrator's Introduction

RawMigrator - A Simple Database Migration Service for PHP Applications

Build Status Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License

Package Features

  • Simple to use migrator
  • Create new migration classes
  • Migrate database up and down
  • Supports migration level control

Installation

Composer

RawMigrator is available via Composer/Packagist.

Add "rawphp/raw-migrator": "0.*@dev" to the require block in your composer.json and then run composer install.

{
        "require": {
            "rawphp/raw-migrator": "0.*@dev"
        }
}

You can also simply run the following from the command line:

composer require rawphp/raw-migrator "0.*@dev"

Tarball

Alternatively, just copy the contents of the RawMigrator folder into somewhere that's in your PHP include_path setting. If you don't speak git or just want a tarball, click the 'zip' button at the top of the page in GitHub.

Basic Usage

<?php

use RawPHP\RawMigrator\Migrator;
use RawPHP\RawDatabase\Database;

// configuration
$config = array(
    'migration_path'   => '/path/to/migrations/dir/',            // path to migrations directory
    'namespace'        => 'RawPHP\\RawMigrator\\Migrations\\',   // migrations namespace, leave empty if namespaces not used
    'migration_table'  => 'migrations',                          // migrations table name
    'class_name_style' => Migrator::STYLE_CAMEL_CASE;            // Migrator::STYLE_UNDERSCORE
    'class_prefix'     => 'M',                                   // class prefix for creating new migrations
    'overwrite'        => FALSE,                                 // Whether to overwrite existing migrations of the same name
);

// get new migrator instance
// the migrator expects an instance of RawPHP\RawDatabase\IDatabase class as its first parameter.
// You can use your own database implementation as long as you implement the IDatabase interface.

$database = new Database( );
$database->init( $dbConfig );

// create new instance
$migrator = new Migrator( $database );

// initialise migrator
$migrator->init( $config );

// create a new migration
$migrator->migrationClass = 'CreateUsersTable';

$migrator->createMigration( );

// update database
$migrator->migrateUp( );

// or to migrate up 1 level
$migrator->levels = 1;
$migrator->migrateUp( );

// migrate database down 1 level
$migrator->levels = 1;
$migrator->migrateDown( );


// NOTE: If using the RawConsole package to run these migrations, you need to
// add 'RawPHP\\RawMigrator\\Commands\\' namespace to the console configuration file.

Further usage documentation will be forthcoming.

License

This package is licensed under the MIT. Read LICENSE for information on the software availability and distribution.

Contributing

Please submit bug reports, suggestions and pull requests to the GitHub issue tracker.

Changelog

22-09-2014

  • Updated for PHP 5.3.
  • Added 'namespaces' configuration option for listing migration namespaces.

20-09-2014

  • Changed 'namespace' to 'migration_namespace' migrator configuration.

20-09-2014

  • Added the migration command.
  • Replaced php array configuration with yaml
  • Fixed MigrationException namespace.

18-09-2014

  • Updated to work with the latest rawphp/rawbase package.
  • Replaced php array configuration with yaml

17-09-2014

  • Added DBTestCase class to be used with the migrator when testing database.
  • Added Class Naming Style to Migrator options. Choose between CamelCase and Underscore.

16-09-2014

  • Added optional $levels parameter to migrateUp( ) and migrateDown( ) in Migrator.

13-09-2014

  • Implemented the hook system
  • Moved component configuration from constructor to init()

11-09-2014

  • Initial Code Commit

rawmigrator's People

Watchers

James Cloos avatar Tom Kaczocha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.