protected function migration_down($table_event, $table_action, $table_name, $args) { $down = Template::func('down'); if ($table_event === 'create') { $schema = Template::schema('drop', $table_name, false); // Add drop schema into down function $down = $this->add_after('{', $schema, $down); } else { // for delete, add, and update $schema = Template::schema('table', $table_name); } if ($table_event === 'delete') { $fields = $this->add_columns($args); // add fields to schema $schema = $this->add_after('function($table) {', $fields, $schema); // add schema to down function $down = $this->add_after('{', $schema, $down); } else { if ($table_event === 'add') { $fields = $this->drop_columns($args); // add fields to schema $schema = $this->add_after('function($table) {', $fields, $schema); // add schema to down function $down = $this->add_after('{', $schema, $down); } else { if ($table_event === 'update') { // add schema to down function $down = $this->add_after('{', $schema, $down); } } } return $down; }