mirror of
https://github.com/Oreolek/kohana-migrations.git
synced 2024-06-26 03:40:54 +03:00
Merge pull request #37 from EvanPurkhiser/CS-cleanup
Cleanup coding style to conform to Kohana CS
This commit is contained in:
commit
79614748ef
|
@ -1,4 +1,4 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* The base migration class, must be extended by all migration files
|
||||
|
@ -19,7 +19,7 @@ abstract class Minion_Migration_Base {
|
|||
/**
|
||||
* Constructs the migration
|
||||
*
|
||||
* @param array Information about this migration
|
||||
* @param array $info Information about this migration
|
||||
*/
|
||||
public function __construct(array $info)
|
||||
{
|
||||
|
@ -47,14 +47,15 @@ abstract class Minion_Migration_Base {
|
|||
/**
|
||||
* Runs any SQL queries necessary to bring the database up a migration version
|
||||
*
|
||||
* @param Kohana_Database The database connection to perform actions on
|
||||
* @param Kohana_Database $db The database connection to perform actions on
|
||||
*/
|
||||
abstract public function up(Kohana_Database $db);
|
||||
|
||||
/**
|
||||
* Runs any SQL queries necessary to bring the database schema down a version
|
||||
*
|
||||
* @param Kohana_Database The database connection to perform actions on
|
||||
* @param Kohana_Database $db The database connection to perform actions on
|
||||
*/
|
||||
abstract public function down(Kohana_Database $db);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* A faux database connection for doing dry run migrations
|
||||
|
@ -8,7 +8,8 @@ class Minion_Migration_Database extends Database_MySQL {
|
|||
/**
|
||||
* Creates a disposable instance of the faux connection
|
||||
*
|
||||
* @param array Config for the underlying DB connection
|
||||
* @param string $db_group The database group to use
|
||||
* @param array $config Config for the underlying DB connection
|
||||
* @return Minion_Migration_Database
|
||||
*/
|
||||
public static function faux_instance($db_group = NULL, array $config = NULL)
|
||||
|
@ -68,4 +69,5 @@ class Minion_Migration_Database extends Database_MySQL {
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Minion exception, thrown during a migration error
|
||||
|
@ -9,7 +9,6 @@ class Minion_Migration_Exception extends Kohana_Exception {
|
|||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
public function __construct($message, array $migration, array $variables = array(), $code = 0)
|
||||
{
|
||||
|
@ -30,4 +29,5 @@ class Minion_Migration_Exception extends Kohana_Exception {
|
|||
{
|
||||
return $this->_migration;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* The migration manager is responsible for locating migration files, syncing
|
||||
|
@ -10,7 +10,7 @@
|
|||
class Minion_Migration_Manager {
|
||||
|
||||
/**
|
||||
* The database connection that sould be used
|
||||
* The database connection that should be used
|
||||
* @var Kohana_Database
|
||||
*/
|
||||
protected $_db;
|
||||
|
@ -38,12 +38,11 @@ class Minion_Migration_Manager {
|
|||
*/
|
||||
protected $_executed_migrations = array();
|
||||
|
||||
|
||||
/**
|
||||
* Constructs the object, allows injection of a Database connection
|
||||
*
|
||||
* @param Kohana_Database The database connection that should be passed to migrations
|
||||
* @param Model_Minion_Migration Inject an instance of the minion model into the manager
|
||||
* @param Kohana_Database $db The database connection that should be passed to migrations
|
||||
* @param Model_Minion_Migration $model Inject an instance of the minion model into the manager
|
||||
*/
|
||||
public function __construct(Kohana_Database $db, Model_Minion_Migration $model = NULL)
|
||||
{
|
||||
|
@ -59,7 +58,7 @@ class Minion_Migration_Manager {
|
|||
/**
|
||||
* Set the database connection to be used
|
||||
*
|
||||
* @param Kohana_Database Database connection
|
||||
* @param Kohana_Database $db Database connection
|
||||
* @return Minion_Migration_Manager
|
||||
*/
|
||||
public function set_db(Kohana_Database $db)
|
||||
|
@ -72,7 +71,7 @@ class Minion_Migration_Manager {
|
|||
/**
|
||||
* Set the model to be used in the rest of the app
|
||||
*
|
||||
* @param Model_Minion_Migration Model instance
|
||||
* @param Model_Minion_Migration $model Model instance
|
||||
* @return Minion_Migration_Manager
|
||||
*/
|
||||
public function set_model(Model_Minion_Migration $model)
|
||||
|
@ -85,7 +84,7 @@ class Minion_Migration_Manager {
|
|||
/**
|
||||
* Set whether the manager should execute a dry run instead of a real run
|
||||
*
|
||||
* @param boolean Whether we should do a dry run
|
||||
* @param boolean $dry_run Whether we should do a dry run
|
||||
* @return Minion_Migration_Manager
|
||||
*/
|
||||
public function set_dry_run($dry_run)
|
||||
|
@ -120,8 +119,8 @@ class Minion_Migration_Manager {
|
|||
*
|
||||
*
|
||||
*
|
||||
* @param array Set of groups to update, empty array means all
|
||||
* @param array Versions for specified groups
|
||||
* @param array $group Set of groups to update, empty array means all
|
||||
* @param array $target Versions for specified groups
|
||||
* @return array Array of all migrations that were successfully applied
|
||||
*/
|
||||
public function run_migration($group = array(), $target = TRUE)
|
||||
|
@ -230,7 +229,7 @@ class Minion_Migration_Manager {
|
|||
/**
|
||||
* Gets a database connection for running the migrations
|
||||
*
|
||||
* @param string Database connection group name
|
||||
* @param string $db_group Database connection group name
|
||||
* @return Kohana_Database Database connection
|
||||
*/
|
||||
protected function _get_db_instance($db_group)
|
||||
|
@ -241,4 +240,5 @@ class Minion_Migration_Manager {
|
|||
|
||||
return Minion_Migration_Database::faux_instance($db_group);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Model for managing migrations
|
||||
|
@ -21,7 +21,7 @@ class Model_Minion_Migration extends Model
|
|||
* Constructs the model, taking a Database connection as the first and only
|
||||
* parameter
|
||||
*
|
||||
* @param Kohana_Database Database connection to use
|
||||
* @param Kohana_Database $db Database connection to use
|
||||
*/
|
||||
public function __construct(Kohana_Database $db)
|
||||
{
|
||||
|
@ -46,7 +46,7 @@ class Model_Minion_Migration extends Model
|
|||
* Parses a set of files generated by Kohana::find_files and compiles it
|
||||
* down into an array of migrations
|
||||
*
|
||||
* @param array Available files
|
||||
* @param array $files Available files
|
||||
* @return array Available Migrations
|
||||
*/
|
||||
public function compile_migrations_from_files(array $files)
|
||||
|
@ -87,7 +87,7 @@ class Model_Minion_Migration extends Model
|
|||
* 'id' => 'mygroup:1293214439'
|
||||
* );
|
||||
*
|
||||
* @param string The migration's filename
|
||||
* @param string $file The migration's filename
|
||||
* @return array Array of components about the migration
|
||||
*/
|
||||
public function get_migration_from_filename($file)
|
||||
|
@ -117,8 +117,7 @@ class Model_Minion_Migration extends Model
|
|||
/**
|
||||
* Gets a migration file from its timestamp, description and group
|
||||
*
|
||||
* @param integer|array The migration's ID or an array of timestamp, description
|
||||
* @param string The migration group
|
||||
* @param integer|array $migration The migration's ID or an array of timestamp, description
|
||||
* @return string Path to the migration file
|
||||
*/
|
||||
public function get_filename_from_migration(array $migration)
|
||||
|
@ -143,7 +142,7 @@ class Model_Minion_Migration extends Model
|
|||
* Allows you to work out the class name from either an array of migration
|
||||
* info, or from a migration id
|
||||
*
|
||||
* @param string|array The migration's ID or array of migration data
|
||||
* @param string|array $migration The migration's ID or array of migration data
|
||||
* @return string The migration class name
|
||||
*/
|
||||
public function get_class_from_migration($migration)
|
||||
|
@ -209,7 +208,7 @@ class Model_Minion_Migration extends Model
|
|||
*
|
||||
* Should only really be used during testing
|
||||
*
|
||||
* @param string Table name
|
||||
* @param string $table Table name
|
||||
* @return string|Model_Minion_Migration Get table name or return $this on set
|
||||
*/
|
||||
public function table($table = NULL)
|
||||
|
@ -237,7 +236,7 @@ class Model_Minion_Migration extends Model
|
|||
/**
|
||||
* Inserts a migration into the database
|
||||
*
|
||||
* @param array Migration data
|
||||
* @param array $migration Migration data
|
||||
* @return Model_Minion_Migration $this
|
||||
*/
|
||||
public function add_migration(array $migration)
|
||||
|
@ -252,7 +251,8 @@ class Model_Minion_Migration extends Model
|
|||
/**
|
||||
* Get a migration by its id
|
||||
*
|
||||
* @param string Migration ID
|
||||
* @param string $group Migration ID
|
||||
* @param string $timestamp The migrations timestamp
|
||||
* @return array Migration info
|
||||
*/
|
||||
public function get_migration($group, $timestamp = NULL)
|
||||
|
@ -277,7 +277,7 @@ class Model_Minion_Migration extends Model
|
|||
/**
|
||||
* Deletes a migration from the database
|
||||
*
|
||||
* @param string|array Migration id / info
|
||||
* @param string|array $migration Migration id / info
|
||||
* @return Model_Minion_Migration $this
|
||||
*/
|
||||
public function delete_migration($migration)
|
||||
|
@ -303,8 +303,8 @@ class Model_Minion_Migration extends Model
|
|||
/**
|
||||
* Update an existing migration record to reflect a new one
|
||||
*
|
||||
* @param array The current migration
|
||||
* @param array The new migration
|
||||
* @param array $current The current migration
|
||||
* @param array $new The new migration
|
||||
* @return Model_Minion_Migration $this
|
||||
*/
|
||||
public function update_migration(array $current, array $new)
|
||||
|
@ -334,8 +334,8 @@ class Model_Minion_Migration extends Model
|
|||
/**
|
||||
* Change the applied status for a migration
|
||||
*
|
||||
* @param array Migration information
|
||||
* @param bool Whether this migration has been applied or unapplied
|
||||
* @param array $migration Migration information
|
||||
* @param bool $applied Whether this migration has been applied or unapplied
|
||||
* @return Model_Minion_Migration
|
||||
*/
|
||||
public function mark_migration(array $migration, $applied)
|
||||
|
@ -402,8 +402,8 @@ class Model_Minion_Migration extends Model
|
|||
* Fetch a list of migrations that need to be applied in order to reach the
|
||||
* required version
|
||||
*
|
||||
* @param string The groups to get migrations for
|
||||
* @param mixed Target version
|
||||
* @param string $group The groups to get migrations for
|
||||
* @param mixed $target Target version
|
||||
*/
|
||||
public function fetch_required_migrations(array $group, $target = TRUE)
|
||||
{
|
||||
|
@ -497,9 +497,10 @@ class Model_Minion_Migration extends Model
|
|||
/**
|
||||
* Resolve a (potentially relative) target for a group to a definite timestamp
|
||||
*
|
||||
* @param string Group name
|
||||
* @param string|int Target
|
||||
* @return array First element timestamp, second is boolean (TRUE if up, FALSE if down)
|
||||
* @param string $group Group name
|
||||
* @param string|int $target Target
|
||||
* @return array First element timestamp, second is boolean
|
||||
* (TRUE if up, FALSE if down)
|
||||
*/
|
||||
public function resolve_target($group, $target)
|
||||
{
|
||||
|
@ -574,4 +575,5 @@ class Model_Minion_Migration extends Model
|
|||
|
||||
return array( (string) $results->get('timestamp'), $up);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* The new task provides an easy way to create migration files
|
||||
|
@ -28,8 +28,7 @@
|
|||
*
|
||||
* @author Matt Button <matthew@sigswitch.com>
|
||||
*/
|
||||
class Task_Migrations_New extends Minion_Task
|
||||
{
|
||||
class Task_Migrations_New extends Minion_Task {
|
||||
/**
|
||||
* A set of config options that this task accepts
|
||||
* @var array
|
||||
|
@ -43,7 +42,7 @@ class Task_Migrations_New extends Minion_Task
|
|||
/**
|
||||
* Execute the task
|
||||
*
|
||||
* @param array Configuration
|
||||
* @param array $options Configuration
|
||||
*/
|
||||
protected function _execute(array $options)
|
||||
{
|
||||
|
@ -59,7 +58,15 @@ class Task_Migrations_New extends Minion_Task
|
|||
|
||||
}
|
||||
|
||||
public function generate($options, $up = null, $down = null)
|
||||
/**
|
||||
* Generate the migration file and return the file path
|
||||
*
|
||||
* @param array $options The migration options
|
||||
* @param string $up Contents of the up migration
|
||||
* @param string $down Contents of the down migration
|
||||
* @return string Filename
|
||||
*/
|
||||
public function generate($options, $up = NULL, $down = NULL)
|
||||
{
|
||||
// Trim slashes in group
|
||||
$options['group'] = trim($options['group'], '/');
|
||||
|
@ -79,8 +86,8 @@ class Task_Migrations_New extends Minion_Task
|
|||
$file = $this->_generate_filename($location, $group, $time, $description);
|
||||
|
||||
|
||||
$data = Kohana::FILE_SECURITY.PHP_EOL.
|
||||
View::factory('minion/task/migrations/new/template')
|
||||
$data = Kohana::FILE_SECURITY.PHP_EOL
|
||||
.View::factory('minion/task/migrations/new/template')
|
||||
->set('class', $class)
|
||||
->set('description', $description)
|
||||
->set('up', $up)
|
||||
|
@ -100,8 +107,8 @@ class Task_Migrations_New extends Minion_Task
|
|||
/**
|
||||
* Generate a class name from the group
|
||||
*
|
||||
* @param string group
|
||||
* @param string Timestamp
|
||||
* @param string $group The group
|
||||
* @param string $time Timestamp
|
||||
* @return string Class name
|
||||
*/
|
||||
protected function _generate_classname($group, $time)
|
||||
|
@ -123,24 +130,35 @@ class Task_Migrations_New extends Minion_Task
|
|||
/**
|
||||
* Generates a filename from the group, time and description
|
||||
*
|
||||
* @param string Location to store migration
|
||||
* @param string Timestamp
|
||||
* @param string Description
|
||||
* @param string $location Location to store migration
|
||||
* @param string $group The group
|
||||
* @param string $time Timestamp
|
||||
* @param string $description Description
|
||||
* @return string Filename
|
||||
*/
|
||||
public function _generate_filename($location, $group, $time, $description)
|
||||
protected function _generate_filename($location, $group, $time, $description)
|
||||
{
|
||||
// Max 100 characters, lowecase filenames.
|
||||
// Max 100 characters, lowercase filenames.
|
||||
$label = substr(strtolower($description), 0, 100);
|
||||
|
||||
// Only letters
|
||||
$label = preg_replace('~[^a-z]+~', '-', $label);
|
||||
|
||||
// Add the location, group, and time
|
||||
$filename = $location.$group.$time.'_'.$label;
|
||||
|
||||
// If description was empty, trim underscores
|
||||
$filename = trim($filename, '_');
|
||||
|
||||
return $filename.EXT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the name of the group
|
||||
*
|
||||
* @param string $group The group name
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _valid_group($group)
|
||||
{
|
||||
// Group cannot be empty
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* The Run task compares the current version of the database with the target
|
||||
|
@ -44,8 +44,8 @@
|
|||
*
|
||||
* @author Matt Button <matthew@sigswitch.com>
|
||||
*/
|
||||
class Task_Migrations_Run extends Minion_Task
|
||||
{
|
||||
class Task_Migrations_Run extends Minion_Task {
|
||||
|
||||
/**
|
||||
* A set of config options that this task accepts
|
||||
* @var array
|
||||
|
@ -63,12 +63,10 @@ class Task_Migrations_Run extends Minion_Task
|
|||
/**
|
||||
* Migrates the database to the version specified
|
||||
*
|
||||
* @param array Configuration to use
|
||||
* @param array $options Configuration to use
|
||||
*/
|
||||
protected function _execute(array $options)
|
||||
{
|
||||
$k_config = Kohana::$config->load('minion/migration');
|
||||
|
||||
$groups = $options['group'];
|
||||
$target = $options['to'];
|
||||
|
||||
|
@ -98,8 +96,8 @@ class Task_Migrations_Run extends Minion_Task
|
|||
|
||||
$manager = new Minion_Migration_Manager($db, $model);
|
||||
|
||||
$manager
|
||||
// Sync the available migrations with those in the db
|
||||
$manager
|
||||
->sync_migration_files()
|
||||
->set_dry_run($dry_run);
|
||||
|
||||
|
@ -130,7 +128,7 @@ class Task_Migrations_Run extends Minion_Task
|
|||
/**
|
||||
* Parses a comma delimited set of groups and returns an array of them
|
||||
*
|
||||
* @param string Comma delimited string of groups
|
||||
* @param string $group Comma delimited string of groups
|
||||
* @return array Locations
|
||||
*/
|
||||
protected function _parse_groups($group)
|
||||
|
@ -168,7 +166,7 @@ class Task_Migrations_Run extends Minion_Task
|
|||
*
|
||||
* {group}:(TRUE|FALSE|{migration_id})
|
||||
*
|
||||
* @param string Target version(s) specified by user
|
||||
* @param string $versions Target version(s) specified by user
|
||||
* @return array Versions
|
||||
*/
|
||||
protected function _parse_target_versions($versions)
|
||||
|
@ -205,7 +203,7 @@ class Task_Migrations_Run extends Minion_Task
|
|||
/*
|
||||
* Helper function for parsing target versions in user input
|
||||
*
|
||||
* @param string Input migration target
|
||||
* @param string $version Input migration target
|
||||
* @return boolean|string The parsed target
|
||||
*/
|
||||
protected function _parse_version($version)
|
||||
|
@ -221,4 +219,5 @@ class Task_Migrations_Run extends Minion_Task
|
|||
|
||||
throw new Kohana_Exception('Invalid target version :version', array(':version' => $version));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php defined('SYSPATH') or die('No direct script access.');
|
||||
<?php defined('SYSPATH') OR die('No direct script access.');
|
||||
|
||||
/**
|
||||
* Displays the current status of migrations in all groups
|
||||
|
@ -12,17 +12,16 @@ class Task_Migrations_Status extends Minion_Task {
|
|||
/**
|
||||
* Execute the task
|
||||
*
|
||||
* @param array Config for the task
|
||||
* @param array $options Config for the task
|
||||
*/
|
||||
protected function _execute(array $options)
|
||||
{
|
||||
$db = Database::instance();
|
||||
$model = new Model_Minion_Migration($db);
|
||||
|
||||
$model = new Model_Minion_Migration(Database::instance());
|
||||
$view = new View('minion/task/migrations/status');
|
||||
|
||||
$view->groups = $model->get_group_statuses();
|
||||
|
||||
echo $view;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<?php
|
||||
|
||||
|
||||
return array(
|
||||
// A mapping of group_connections => db_connection to use
|
||||
'group_connection' => array(
|
||||
|
||||
),
|
||||
/**
|
||||
* A mapping of group_connections => db_connection to use
|
||||
*/
|
||||
'group_connection' => array(),
|
||||
|
||||
/**
|
||||
* The table used to store migrations
|
||||
|
|
|
@ -35,4 +35,5 @@ class <?php echo $class; ?> extends Minion_Migration_Base {
|
|||
// $db->query(NULL, 'DROP TABLE ... ');
|
||||
<?php endif; ?>
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,4 +31,3 @@ This was a dry run, if it was a real run the following SQL would've been execute
|
|||
# End Location: <?php echo $group; ?> #
|
||||
################<?php echo $group_padding ?>##
|
||||
<?php endforeach; ?>
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
Minion encountered an error while executing migration `<?php echo $migration['id']; ?>` <?php echo (!empty($migration['description']) ? '('.$migration['description'].')' : '') ?>):
|
||||
Minion encountered an error while executing migration `<?php echo $migration['id']; ?>` <?php echo (( ! empty($migration['description'])) ? ('('.$migration['description'].')') : '') ?>):
|
||||
|
||||
<?php echo $error; ?>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<?php foreach ($groups as $group => $status): ?>
|
||||
* <?php echo $group ?> <?php echo ($status !== NULL ? $status['timestamp'].' '.( !empty($status['description']) ? '('.$status['description'].')' : '' ) : 'Not installed'); ?>
|
||||
* <?php echo $group ?> <?php echo (($status !== NULL) ? ($status['timestamp'].' '.(( ! empty($status['description'])) ? ('('.$status['description'].')') : '')) : 'Not installed'); ?>
|
||||
|
||||
<?php endforeach; ?>
|
||||
|
|
Loading…
Reference in a new issue