2017 © Pedro Peláez
 

lithium-library li3_migrations

Database migrations for Lithium PHP framework

image

djordje/li3_migrations

Database migrations for Lithium PHP framework

  • Monday, April 30, 2018
  • by djordje
  • Repository
  • 2 Watchers
  • 2 Stars
  • 34 Installations
  • PHP
  • 0 Dependents
  • 2 Suggesters
  • 1 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Database migrations for Lithium framework Build Status


Dependencies

li3_fixtures - Installation instructions, (*1)

lithium from master branch (after v0.11) with integrated li3_sqltools, (*2)

Usage

create migration

Create new migration file with li3 create migration command:, (*3)

li3 create migration Users
//app/resources/migration/20130506002905_Users.php

namespace app\resources\migration; class Users extends \li3_migrations\models\Migration { protected $_fields = []; protected $_records = []; protected $_meta = []; protected $_source = 'users'; public function up() {} public function down() {} }

Each field can have a type, length, if default or nullable, (*4)


protected $_fields = [ 'id' => ['type' => 'id'], 'name' => ['type' => 'string', 'default' => 'foo', 'length' => 128, 'null' => false], 'bar_id' => ['type' => 'integer'] ];

Meta can be used to set constraints, table engine, charset, (*5)


protected $_meta = [ 'constraints' => [ [ 'type' => 'foreign_key', 'column' => 'id', 'toColumn' => 'id', 'to' => 'other_table' ] ], 'table' => ['charset' => 'utf8', 'engine' => 'InnoDB'] ];

Examples, (*6)

Create new table up and down, (*7)


public function up() { return $this->create() } public function down() { return $this->drop(); }

Create new table and add records, (*8)


protected $_records = array( ['name' => 'foo', 'type' => 1], ['name' => 'bar', 'type' => 1] ); public function up() { if (!$this->create()) return false; return $this->save(); } public function down() { return $this->drop(); }

You can provide arguments to command:, (*9)

  • source - custom table name (this is value of source property): --source=site_users
  • library - specify library to use: --library=li3_usermanager

migrate

Run migrations with li3 migrate command:, (*10)

Available li3 migrate actions:, (*11)

  • up - accept timestamp param: li3 migrate up or li3 migrate up 20130505 or li3 migrate up 20130505102033
  • down - accept timestamp param: li3 migrate down 1 or li3 migrate down 20130505 or li3 migrate down 20130505102033
  • show-available - generate table with all available migrations in current library
  • show-state - show timestamp of latest applied migration

The Versions

30/04 2018

dev-master

9999999-dev https://github.com/djordje/li3_migrations

Database migrations for Lithium PHP framework

  Sources   Download

BSD-3-Clause

The Requires

 

php mysql db migrate lithium li3