Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Update .semver
  Update CHANGELOG.md
  Update translation files
  Show prompt for marking as successful when failure
  crlf to lf
  Grammatical corrections for generate command
  Fix CS issues
  Fix grammar in console output
  Tidy up unlinking in tests
  Fix for incorrect naming of all plugin migrations
  • Loading branch information
Chris Burke committed Mar 9, 2015
2 parents 0d62dda + aa141a1 commit b8550a4
Show file tree
Hide file tree
Showing 22 changed files with 844 additions and 812 deletions.
2 changes: 1 addition & 1 deletion .semver
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
:major: 2
:minor: 3
:patch: 5
:patch: 6
:special: ''
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
Changelog
=========

Release 2.3.6
-------------

https://github.com/CakeDC/migrations/tree/2.3.6

* [ccac5a3](https://github.com/cakedc/migrations/commit/ccac5a3) Update translation files
* [bca17ea](https://github.com/cakedc/migrations/commit/bca17ea) Show prompt for marking as successful when failure
* [18aa020](https://github.com/cakedc/migrations/commit/18aa020) crlf to lf
* [db96c9e](https://github.com/cakedc/migrations/commit/db96c9e) Grammatical corrections for generate command
* [cc7b03a](https://github.com/cakedc/migrations/commit/cc7b03a) Fix CS issues
* [942eab0](https://github.com/cakedc/migrations/commit/942eab0) Fix grammar in console output
* [89ddfc1](https://github.com/cakedc/migrations/commit/89ddfc1) Tidy up unlinking in tests
* [894f736](https://github.com/cakedc/migrations/commit/894f736) Fix for incorrect naming of all plugin migrations

Release 2.3.5
-------------

https://github.com/CakeDC/migrations/tree/2.3.5

* [69e6136](https://github.com/cakedc/migrations/commit/69e6136) Add translations for new/missing strings
* [c98ecdd](https://github.com/cakedc/migrations/commit/c98ecdd) Exit shell if comparing schema.php and nothing has changed

Expand Down
99 changes: 71 additions & 28 deletions Console/Command/MigrationShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function getOptionParser() {
->addOption('schema-class', array(
'short' => 's',
'boolean' => false,
'default' => 'App',
'default' => false,
'help' => __('CamelCased Classname without the `Schema` suffix to use when reading or generating schema files. See `Console/cake schema generate --help`.')))
->addSubcommand('status', array(
'help' => __('Displays a status of all plugin and app migrations.')))
Expand Down Expand Up @@ -248,6 +248,13 @@ public function run() {
return true;
}

/**
* Execute migration
*
* @param array $options Options for migration
* @param bool $once True to only run once, false to retry
* @return bool True if success
*/
protected function _execute($options, $once) {
$result = true;
try {
Expand Down Expand Up @@ -278,7 +285,7 @@ protected function _execute($options, $once) {
/**
* Output the SQL log in dry mode
*
* @param $log array
* @param array $log List of queries per migration
* @return void
*/
protected function _outputLog($log) {
Expand All @@ -297,6 +304,14 @@ protected function _outputLog($log) {
$this->hr();
}

/**
* Single step options for up/down migrations
*
* @param array $mapping Migration version mappings
* @param string $latestVersion Latest migration version
* @param array $default Default options for migration
* @return array Modified options for migration
*/
protected function _singleStepOptions($mapping, $latestVersion, $default = array()) {
$options = $default;
$versions = array_keys($mapping);
Expand All @@ -315,6 +330,13 @@ protected function _singleStepOptions($mapping, $latestVersion, $default = array
return $options;
}

/**
* Output prompt with different migration versions to choose from
*
* @param array $mapping Migration version mappings
* @param string $latestVersion Latest migration version
* @return array User-chosen options for migration
*/
protected function _promptVersionOptions($mapping, $latestVersion) {
if (isset($this->args[0]) && is_numeric($this->args[0])) {
$options['version'] = (int)$this->args[0];
Expand All @@ -329,7 +351,7 @@ protected function _promptVersionOptions($mapping, $latestVersion) {
$this->hr();

while (true) {
$response = $this->in(__d('migrations', 'Please, choose what version you want to migrate to. [q]uit or [c]lean.'));
$response = $this->in(__d('migrations', 'Please choose which version you want to migrate to. [q]uit or [c]lean.'));
if (strtolower($response) === 'q') {
return $this->_stop();
} elseif (strtolower($response) === 'c') {
Expand Down Expand Up @@ -375,7 +397,7 @@ public function generate() {
} else {
$oldSchema = $this->_getSchema($this->type);
if ($oldSchema !== false) {
$response = $this->in(__d('migrations', 'Do you want compare the schema.php file to the database?'), array('y', 'n'), 'y');
$response = $this->in(__d('migrations', 'Do you want to compare the schema.php file to the database?'), array('y', 'n'), 'y');
if (strtolower($response) === 'y') {
$this->_generateFromComparison($migration, $oldSchema, $comparison);
if (empty($comparison)) {
Expand All @@ -386,7 +408,7 @@ public function generate() {
$fromSchema = true;
}
} else {
$response = $this->in(__d('migrations', 'Do you want generate a dump from current database?'), array('y', 'n'), 'y');
$response = $this->in(__d('migrations', 'Do you want to generate a dump from the current database?'), array('y', 'n'), 'y');
if (strtolower($response) === 'y') {
$this->_generateDump($migration);
$fromSchema = true;
Expand All @@ -397,18 +419,19 @@ public function generate() {
$this->_finalizeGeneratedMigration($migration, $migrationName, $fromSchema);

if ($fromSchema && isset($comparison)) {
$response = $this->in(__d('migrations', 'Do you want update the schema.php file?'), array('y', 'n'), 'y');
$response = $this->in(__d('migrations', 'Do you want to update the schema.php file?'), array('y', 'n'), 'y');
if (strtolower($response) === 'y') {
$this->_updateSchema();
}
}
}

/**
* generate a migration by comparing schema.php with the database.
* @param array $migration reference to variable of the same name in generate() method
* @param array $oldSchema reference to variable of the same name in generate() method
* @param array $comparison reference to variable of the same name in generate() method
* Generate a migration by comparing schema.php with the database.
*
* @param array &$migration Reference to variable of the same name in generate() method
* @param array &$oldSchema Reference to variable of the same name in generate() method
* @param array &$comparison Reference to variable of the same name in generate() method
* @return void (The variables passed by reference are changed; nothing is returned)
*/
protected function _generateFromComparison(&$migration, &$oldSchema, &$comparison) {
Expand All @@ -424,10 +447,11 @@ protected function _generateFromComparison(&$migration, &$oldSchema, &$compariso
}

/**
* generate a migration from arguments passed in at the command line
* @param array $migration reference to variable of the same name in generate() method
* @param array $migrationName reference to variable of the same name in generate() method
* @param array $comparison reference to variable of the same name in generate() method
* Generate a migration from arguments passed in at the command line
*
* @param array &$migration Reference to variable of the same name in generate() method
* @param array &$migrationName Reference to variable of the same name in generate() method
* @param array &$comparison Reference to variable of the same name in generate() method
* @return void (The variables passed by reference are changed; nothing is returned)
*/
protected function _generateFromCliArgs(&$migration, &$migrationName, &$comparison) {
Expand Down Expand Up @@ -464,6 +488,12 @@ protected function _generateFromCliArgs(&$migration, &$migrationName, &$comparis
}
}

/**
* Return list of field names from array of field/index definitions
*
* @param array $fields Field/index definitions
* @return array List of field names
*/
protected function _fieldNamesArray($fields) {
$fieldNames = array();
foreach ($fields as $name => $value) {
Expand All @@ -476,12 +506,13 @@ protected function _fieldNamesArray($fields) {

/**
* Generate a dump of the current database.
* @param array $migration reference to variable of the same name in generate() method
*
* @param array &$migration Reference to variable of the same name in generate() method
* @return void (The variables passed by reference are changed; nothing is returned)
*/
protected function _generateDump(&$migration) {
$this->hr();
$this->out(__d('migrations', 'Generating dump from current database...'));
$this->out(__d('migrations', 'Generating dump from the current database...'));

$dump = $this->_readSchema();
$dump = $dump['tables'];
Expand All @@ -496,9 +527,10 @@ protected function _generateDump(&$migration) {
/**
* Finalizes the generated migration - offers to preview it,
* prompts for a name, writes the file, and updates db version if needed.
* @param array $migration reference to variable of the same name in generate() method
* @param array $migrationName reference to variable of the same name in generate() method
* @param bool $fromSchema reference to variable of the same name in generate() method
*
* @param array &$migration Reference to variable of the same name in generate() method
* @param array &$migrationName Reference to variable of the same name in generate() method
* @param bool &$fromSchema Reference to variable of the same name in generate() method
* @return void
*/
protected function _finalizeGeneratedMigration(&$migration, &$migrationName, &$fromSchema) {
Expand Down Expand Up @@ -526,6 +558,7 @@ protected function _finalizeGeneratedMigration(&$migration, &$migrationName, &$f

/**
* Prompt the user for a name for their new migration.
*
* @return string
*/
protected function _promptForMigrationName() {
Expand Down Expand Up @@ -689,7 +722,7 @@ protected function _fromComparison($migration, $comparison, $oldTables, $current
* Gets the schema class name
*
* @param string $name Can be 'app' or a plugin name
* @param boolean Return the class name with or without the "Schema" suffix, default is true
* @param bool $suffix Return the class name with or without the "Schema" suffix, default is true
* @return string Returns the schema class name
*/
protected function _getSchemaClassName($name = null, $suffix = true) {
Expand Down Expand Up @@ -814,10 +847,12 @@ protected function _parseCommandLineFields($name) {

/**
* Parse a single argument from the command line into the fields array
* @param array $fields reference to variable of same name in _parseCommandLineFields()
* @param string $field a single command line argument - eg. 'id:primary_key' or 'name:string'
* @param array $validTypes valid data types for the relevant database - eg. string, integer, biginteger, etc.
* @return [type] [description]
*
* @param array &$fields Reference to variable of same name in _parseCommandLineFields()
* @param array &$indexes Reference to variable of same name in _parseCommandLineFields()
* @param string $field A single command line argument - eg. 'id:primary_key' or 'name:string'
* @param array $validTypes Valid data types for the relevant database - eg. string, integer, biginteger, etc.
* @return void
*/
protected function _parseSingleCommandLineField(&$fields, &$indexes, $field, $validTypes) {
if (preg_match('/^(\w*)(?::(\w*))?(?::(\w*))?(?::(\w*))?/', $field, $matches)) {
Expand Down Expand Up @@ -876,6 +911,14 @@ protected function _parseSingleCommandLineField(&$fields, &$indexes, $field, $va
}
}

/**
* Return valid field type based on name of field
*
* @param string $field Name of field
* @param string $type Current type
* @param array $validTypes List of valid types
* @return string Recognized type (eg. integer vs bigint)
*/
protected function _getFieldType($field, $type, $validTypes) {
if (!in_array($type, $validTypes)) {
if ($field == 'id') {
Expand Down Expand Up @@ -961,7 +1004,7 @@ protected function _generateMigration($name, $class, $migration) {
* Write a migration with given name
*
* @param string $name Name of migration
* @param integer $version The version number (timestamp)
* @param int $version The version number (timestamp)
* @param array $migration Migration instructions array
* @return bool
*/
Expand Down Expand Up @@ -1029,7 +1072,7 @@ protected function _getPath($type = null) {
/**
* Callback used to display what migration is being runned
*
* @param CakeMigration $Migration Migration being performed
* @param CakeMigration &$Migration Migration being performed
* @param string $direction Direction being runned
* @return void
*/
Expand All @@ -1040,7 +1083,7 @@ public function beforeMigration(&$Migration, $direction) {
/**
* Callback used to create a new line after the migration
*
* @param CakeMigration $Migration Migration being performed
* @param CakeMigration &$Migration Migration being performed
* @param string $direction Direction being runned
* @return void
*/
Expand All @@ -1051,7 +1094,7 @@ public function afterMigration(&$Migration, $direction) {
/**
* Callback used to display actions being performed
*
* @param CakeMigration $Migration Migration being performed
* @param CakeMigration &$Migration Migration being performed
* @param string $type Type of action. i.e: create_table, drop_table, etc.
* @param array $data Data to send to the callback
* @return void
Expand Down
15 changes: 7 additions & 8 deletions Lib/CakeMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function after($direction) {
/**
* Log a dry run SQL query
*
* @param str $sql
* @param string $sql SQL query
* @return void
*/
public function logQuery($sql) {
Expand Down Expand Up @@ -310,7 +310,7 @@ protected function _run() {
*
* @param string $a Type
* @param string $b Type
* @return integer Comparison value
* @return int Comparison value
*/
protected function migration_order($a, $b) {
$order = array('drop_table', 'rename_table', 'create_table', 'drop_field', 'rename_field', 'alter_field', 'create_field');
Expand Down Expand Up @@ -573,10 +573,9 @@ protected function _invokeCallbacks($callback, $type, $data = array()) {
* This method will invoke the before/afterAction callbacks, it is good when
* you need track every action.
*
* @param string $callback Callback name, beforeMigration, beforeAction
* or afterMigration.
* @param string $type Type of action. i.e: create_table, drop_table, etc.
* Or also can be the direction, for before and after Migration callbacks
* @param string $callback Callback name, beforeMigration, beforeAction or afterMigration.
* @param string $type Type of action (e.g. create_table, drop_table, etc.)
* Also can be the direction (before/after) for Migration callbacks
* @param array $data Data to send to the callback
* @return bool
*/
Expand Down Expand Up @@ -620,7 +619,7 @@ protected function _clearCache() {
*
* @param string $name Model name to be initialized
* @param string $table Table name to be initialized
* @param array $options
* @param array $options Model constructor options
* @return Model
*/
public function generateModel($name, $table = null, $options = array()) {
Expand Down Expand Up @@ -654,7 +653,7 @@ class MigrationException extends Exception {
*
* @param CakeMigration $Migration Reference to the Migration
* @param string $message Message explaining the error
* @param integer $code Error code
* @param int $code Error code
* @return \MigrationException
*/
public function __construct($Migration, $message = '', $code = 0) {
Expand Down
Loading

0 comments on commit b8550a4

Please sign in to comment.