Code Monkey home page Code Monkey logo

migrations's Introduction

Database migrations plugin for CakePHP

Build Status License

This is a pre-alpha version of a Database Migrations system for CakePHP 3.0. It is currently under development and should be considered experimental.

The plugin consists of a wrapper for the phinx migrations library.

Installation

You can install this plugin into your CakePHP application using composer. For existing applications you can add the following to your composer.json file:

"require": {
	"cakephp/migrations": "dev-master"
}

And run php composer.phar update

Configuration

You will need to add the following line to your application's bootstrap.php file:

Plugin::load('Migrations');

Additionally, you will need to configure the default database configuration in your config/app.php file.

Usage

This plugins provides the Migrations shell that you can invoke from your application's root folder:

$ bin/cake migrations

The command above will display a list of available options. Make sure you read the official phinx documentation to understand how migrations are created and executed in your database.

Create a migration file with tables from your database

To create your first migration file, execute:

$ bin/cake bake migration Initial [-p PluginName] [-c connection]

This will create a phinx file with tables found in your database. By default, this will just add tables that have model files, but you can create a file with all tables by adding the option --checkModel false.

Create an empty migration file

To create an empty migration file, execute:

$ bin/cake migrations create Name

This will create a file under config/Migrations that you can edit to complete the migration steps as documented in phinx's manual.

Please note that you will need to learn how to write your own migrations, you need to fill in the up() and down() or change() methods if you want automatically reversible migrations.

Once again, please make sure you read the official phinx documentation to understand how migrations are created and executed in your database.

Run the migration

After modifying the migration file, you can run your changes in the database by executing:

$ bin/cake migrations migrate

Rollback a migration

If you added any steps to revert a migration in the down() callback, you can execute this command and have that function executed:

$ bin/cake migrations rollback

Watch migrations status

By executing this command you will have an overview of the migrations that have been executed and those still pending to be run:

$ bin/cake migrations status

Usage for plugins

All the commands from above support the --plugin or -p option:

$ bin/cake migrations status -p PluginName

Usage for connections

All the commands from above support the --connection or -c option:

$ bin/cake migrations migrate -c my_datasource

Usage for custom primary key id in tables

To create a table called statuses and use a CHAR (36) for the id field, this requires you to turn off the id.

See:

$table = $this->table('statuses',
    [
        'id' => false,
        'primary_key' => ['id']
    ]);
$table->addColumn('id', 'char', ['limit' => 36])
    ->addColumn('name', 'char', ['limit' => 255])
    ->addColumn('model', 'string', ['limit' => 128])
    ->create();

migrations's People

Contributors

lorenzo avatar josegonzalez avatar ad7six avatar cake17 avatar luke83 avatar markstory avatar dakota avatar admad avatar johannesnagl avatar kh12e avatar commercial-hippie avatar williamn avatar

Watchers

David Yell 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.