dev-master
9999999-devChai is a framework of useful tools
The Requires
The Development Requires
v0.0.1
0.0.1.0Chai is a framework of useful tools
The Requires
The Development Requires
Chai is a framework of useful tools
Chai is a collection of tools to aid in the development of PHP applications. It aims to be easy to use and completely framework agnostic. It utilizes components from other frameworks and libraries, so as not to re-invent the wheel., (*1)
Migrations allow you to "version control" your database. You can create tables, update tables, or perform other actions. Most migration systems have an up and down method. The up method does the desired action such as creating or updating a table. The down method does the opposite allowing you to run migrations multiple times without any issues. In addition, Chai has an update method that is ran if the migration has already been applied., (*2)
To get started using migrations, you will need to create a console script
(bin/console
)., (*3)
<?php //use Symfony\Component\Console\Application; use Chai\Console\Application; use Chai\Migrations\Migrations; $migrations = new Migrations(); $migrations->setMigrationsDirectory(__DIR__.'/../app/database/migrations'); $migrations->setDatabaseParameters(array( 'host' => '', 'port' => '', 'username' => '', 'password' => '', 'database' => '', )); $app = new Application('Description', '0.1.0'); $app->register($migrations); $app->run();
Then run bin/console migration:init
, which will create the migrations table., (*4)
You cna create a migration using the console application., (*5)
bin/console migration:create <name>
, (*6)
Migration names must be all lowercase, using underscores (_
) as seperators, and not begin with a number., (*7)
Valid Migration Names, (*8)
Invalid Migration Names, (*9)
All migrations are prefixed with a timestamp. This is to keep migrations unique and to know which order they are to be ran in., (*10)
A basic migration looks like:, (*11)
<?php use Chai\Migrations\BaseMigration; class TestMigration extends BaseMigration { public function up() { // Do something here } public function down() { // Do the opposite here } public function update() { // Do something only if the // migration has already been ran } }
bin/console migration:up [name]
, (*12)
bin/console migration:down [name]
, (*13)
bin/console migration:status
, (*14)
Chai is a framework of useful tools
Chai is a framework of useful tools