Skip to content

Instantly share code, notes, and snippets.

@TamiasSibiricus
Last active August 29, 2015 14:08
Show Gist options
  • Save TamiasSibiricus/1abf1acdc6e32792edad to your computer and use it in GitHub Desktop.
Save TamiasSibiricus/1abf1acdc6e32792edad to your computer and use it in GitHub Desktop.
Sample failes for migrations plugin test
// config/Migrations/20141015141853_initial.php
<?php
use Phinx\Migration\AbstractMigration;
class Initial extends AbstractMigration
{
/**
* Change Method.
*
* More information on this method is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-change-method
*
* Uncomment this method if you would like to use it.
*
public function change()
{
}
*/
/**
* Migrate Up.
*/
public function up()
{
$posts = $this->table('posts');
$posts->addColumn('title', 'string', ['limit' => 255, 'null' => true])
->addColumn('slug', 'string', ['limit' => 255, 'null' => true])
->addColumn('full_text', 'text', ['null' => true])
->save();
}
/**
* Migrate Down.
*/
public function down()
{
$this->dropTable('posts');
}
}
<?php
// config/bootstrap.php
/* ... */
use Cake\Event\EventManager;
use App\Event\MigrationEvent;
EventManager::instance()->attach(
new MigrationEvent,
null
);
//this piece of code does not work in app bootstrap
//use Cake\Event\EventManager;
//use App\Event\MigrationEvent;
//
//EventManager::instance()->attach(
// new App\Event\MigrationEvent,
// null
//);
<?php
// src/Event/MigrationEvent.php
namespace App\Event;
use Cake\Event\EventListenerInterface;
class MigrationEvent implements EventListenerInterface {
public function implementedEvents() {
return array(
'Migration.beforeMigrate' => array(
'callable' => 'onMigrationMigarteBefore',
),
'Migration.afterMigrate' => array(
'callable' => 'onMigrationMigarteAfter',
),
'Migration.beforeRollback' => array(
'callable' => 'onMigrationRollbackBefore',
),
'Migration.afterRollback' => array(
'callable' => 'onMigrationRollbackAfter',
),
);
}
public function onMigrationMigarteBefore($event) {
debug('onMigrationMigarteBefore');
}
public function onMigrationMigarteAfter($event) {
debug('onMigrationMigarteAfter');
}
public function onMigrationRollbackBefore($event) {
debug('onMigrationRollbackBefore');
}
public function onMigrationRollbackAfter($event) {
debug('onMigrationRollbackAfter');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment