Skip to content

Commit

Permalink
Created a migration file to change the class name field length to 255…
Browse files Browse the repository at this point in the history
…. Added a warning in the console if the user inputs a description longer than 255 characters.
  • Loading branch information
airdrummingfool committed Jun 4, 2012
1 parent 35c5917 commit 8a9cc5d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Config/Migration/003_increase_class_name_length.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php
class IncreaseClassNameLength extends CakeMigration {

/**
* Migration description
*
* @var string
* @access public
*/
public $description = 'Increase the maximum length of class names.';

/**
* Actions to be performed
*
* @var array $migration
* @access public
*/
public $migration = array(
'up' => array(
'alter_field' => array(
'schema_migrations' => array(
'class' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 255, 'name' => 'class')
)
)
),
'down' => array(
'alter_field' => array(
'schema_migrations' => array(
'class' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 33, 'name' => 'class')
)
)
)
);

/**
* Before migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function after($direction) {
return true;
}
}

?>
3 changes: 3 additions & 0 deletions Console/Command/MigrationShell.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ public function generate() {
if (!preg_match('/^([A-Za-z0-9_]+|\s)+$/', $name) || is_numeric($name[0])) {
$this->out('');
$this->err(__d('Migrations', 'Migration name (%s) is invalid. It must only contain alphanumeric characters and start with a letter.', $name));
} elseif (strlen($name) > 255) {
$this->out('');
$this->err(__d('Migrations', 'Migration name (%s) is invalid. It cannot be longer than 255 characters.', $name));
} else {
$name = str_replace(' ', '_', trim($name));
break;
Expand Down

0 comments on commit 8a9cc5d

Please sign in to comment.