Coder Social home page Coder Social logo

migrations's Introduction

CakeDC Migrations Plugin

Bake Status Downloads Latest Version

The Migrations plugin enables developers to quickly and easily manage and migrate between database schema versions.

As an application is developed, changes to the database may be required, and managing that in teams can get extremely difficult. The Migrations plugin enables you to share and coordinate database changes in an iterative manner, removing the complexity of handling these changes.

  • Console: The console script allows you to run migrations up and down.
  • Installation: Migrations can also be run programmatically via an installer script.
  • ORM: The Migrations plugin makes use of the CakePHP ORM and supports all databases provided by the framework.

This is NOT a Backup Tool

We highly recommend to not run the Migrations plugin in a production environment directly without doing a backup first.

However, you can make use of the before() and after() callbacks in the migration files to add logic which triggers a backup script.

Requirements

  • CakePHP 2.5+ (We recomment latest 2.x)
  • PHP 5.3.0+ (We recommend php 7+)

Documentation

For documentation, as well as tutorials, see the Docs directory of this repository.

Support

For bugs and feature requests, please use the issues section of this repository.

Commercial support is also available, contact us for more information.

Contributing

This repository follows the CakeDC Plugin Standard. If you'd like to contribute new features, enhancements or bug fixes to the plugin, please read our Contribution Guidelines for detailed instructions.

License

Copyright 2007-2014 Cake Development Corporation (CakeDC). All rights reserved.

Licensed under the MIT License. Redistributions of the source code included in this repository must retain the copyright notice found in each file.

migrations's People

Contributors

airdrummingfool avatar ajibarra avatar ameboide avatar andrej-griniuk avatar andretefras avatar beporter avatar cauancabral avatar chrisjohnson avatar dagumak avatar dkullmann avatar dogmatic69 avatar gmansilla avatar jameswatts avatar jippi avatar josegonzalez avatar joshuapaling avatar kobake avatar lorenzo avatar phpnut avatar predominant avatar ravage84 avatar real34 avatar renan avatar sharkooon avatar sime avatar sitedyno avatar skie avatar steinkel avatar waldemarnt avatar yeliparra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

migrations's Issues

Update the documentation explaining how to alter indexes

Reported by Pierre Martin | December 14th, 2010 @ 12:00 PM

This is an issue reported by jrbasso on the #cakedc channel

There is a little issue in migrations doc, in http://cakedc.com/eng/downloads/view/cakephp_migrations_plugin.

The "Directive - Alter Field" section says that you can use alter_field to create/drop indexes, but is needed create_field and drop_field to it.
If you use alter_field, it will send 'change' to DboMysql::_alterIndexes() (if using mysql, of course) and change not are supported by cake core... https://github.com/cakephp/cakephp/blob/master/cake/libs/model/datasources/dbo/dbo_mysql.php#L380

Drop index before drop fields

Reported by avairet | February 9th, 2011 @ 09:49 AM

When a migration execute drop_field actions, fields are dropped before indexes. So if an index reference a dropped field, it's impossible to drop it!

'up' => array(
    'drop_field' => array(
        'votes' => array('document_id', 'indexes' => array('doc_vote', 'user_vote', 'idx_UNIQUE')),
    ),
),

In the example above, my index "doc_vote" and my index "idx_UNIQUE" reference "document_id" field, so when I execute this migration, the field "document_id" is dropped first and after that, the two indexes can't be dropped. Here is the error message from MySQL: "1091: Can't DROP 'doc_vote'; check that column/key exists".

Generating a new migration drops all existing tables

Hello

I'm following the guidelines to create an initial migration, and everything works fine. Then I generate an schema file, and after that I try to generate a new migration (without modifications on the schema), and on the migration file it appears to drop all the existing tables (
'up' => array(
'drop_table' => array(/* ALL THE TABLES LISTED HERE */
),

And on the down part it creates them all again.

What I expected was an empty migration file.

After trying that, I modified a field on a table, and tried to generate another migration, obtaining the same exact result (drop for all tables on up, and all of them created back on down - without the field modification)

Am I doing anything wrong, or maybe could be a bug?

Thanks in advance

Typos in readme.md

The following commands described in "readme.md" don't seem to exist:

  • reset
  • down
  • up

The following commands exist but are not documented:

  • status
  • add

The following example is missing the fully-qualified shell name:

cake migration all --plugin Users

time field causes errors

When attempting to alter a field to a time, migration attempts to assign a size which results in a SQL error. I will attach further info to this ticket soon and hopefully, a patch.

Allow insertion of test data from the current Migration

It would be useful to auto-inject data into a migration for the purposes of testing - we could turn off the injection via a flag for application-specific environments - in a similar format as what Fixture class uses. We could simply wrap around the same system for adding/removing data, as well as optionally allowing users the ability to drop all existing data.

Alter field from string to numeric will fail

Hi,

Altering a field from a string type to a numeric type will result in an error in MySQL. For example when altering a ‘varchar’ field to an ‘integer’ the following migration code is generated:

public $migration = array(
  'up' => array(
    'alter_field' => array(
      'users' => array(
        'last_login' => array('type' => 'integer', 'null' => false, 'default' => '0'),
      ),
    ),
.......

However due to the array_merge in CakeMigration.php on line 399 the $defs also hold the collate and charset keys. The alter schema instruction therefore fails:

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT 0 NOT NULL' at line 2

A quick fix for MySQL users is to add the code below before $sql on line 406 in CakeMigration.php (the array can be filled with more numeric types of course).

if (in_array($def['type'], array('integer', 'float'))) {
  unset($def['collate'], $def['charset']);
}

I haven’t looked long enough at the code to provide an actual fix.

Cheers

Error with new 2.1 Version in master

we had migration plugin previously installed, and so have the Table 'schema_migrations' in the db.

Console throws error: "Error: Table "schema_migrations" already exists in database."

tried running the Migrations plugins migration itself, but always get above error.

migration for changing of the engine type is put in the alter field causing errors

Reported by Predominant | September 9th, 2010 @ 11:57 PM

Hi,

'down' => array(
    'alter_field' => array(
        'acos' => array(
            'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_general_ci', 'engine' => 'MyISAM'),
        ),

this was generated.

when i try to run the reset, i get an error occurred when processing. Field tableParameters does not exist in table acos

Please let me know.

Force flag not working when generating migration

$ cake Migrations.migration -f generate

Cake Migration Shell
---------------------------------------------------------------
Current migration version:
  #1333475547  1333475547_adding_response_to_migration
---------------------------------------------------------------
Available migrations:
  [1332195611] 1332195611_initial_migration
        applied Tue, 03 Apr 2012 11:48:35 -0600
  [1333475547] 1333475547_adding_response_to_migration
        applied Tue, 03 Apr 2012 11:52:27 -0600
---------------------------------------------------------------
Please, choose what version you want to migrate to. [q]uit or [c]lean.  
> 

Without -f flag

$ cake Migrations.migration generate

Cake Migration Shell
---------------------------------------------------------------
Do you want compare the schema.php file to the database? (y/n) 
[y] > 

My schema file is generated using the force flag, therefore I also need to generate the migration with the same force flag, this usto work. Now it's not. I'm using the most recent version of master (when writing this ticket) in CakePHP 2.1.1 application.

./cake Migrations.migration all does NOT work

Wow, I spent a good hour trying to figure out why ./Console/cake Migrations.migration all --plugin Users wasn't working and even looked into the file and debugged it. Documentation for migration command should be upgraded across all the plugins. So with this command on this readme Console/cake Migrations.migration -p Migrations.

Error using "cake migration"

When I write in terminal "cake migration" I've got the following error:

Welcome to CakePHP v1.3.12 Console
---------------------------------------------------------------
App : portal-rse
Path: /Applications/MAMP/htdocs/cake/portal-rse
---------------------------------------------------------------
Cake Migration Shell
---------------------------------------------------------------
<pre class="cake-debug"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr1-trace').style.display = (document.getElementById('cakeErr1-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (2)</a>: mysql_connect() [http://php.net/function.mysql-connect]: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) [<b>CORE/cake/libs/model/datasources/dbo/dbo_mysql.php</b>, line <b>561</b>]<div id="cakeErr1-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr1-code').style.display = (document.getElementById('cakeErr1-code').style.display == 'none' ? '' : 'none')">Code</a> | <a href="javascript:void(0);" onclick="document.getElementById('cakeErr1-context').style.display = (document.getElementById('cakeErr1-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr1-context" class="cake-context" style="display: none;">$config    =   array(
    "persistent" => false,
    "host" => "*****",
    "login" => "*****",
    "password" => "*****",
    "database" => "*****",
    "port" => "*****",
    "driver" => "mysql",
    "prefix" => "*****"
)</pre><pre class="stack-trace">mysql_connect - [internal], line ??
DboMysql::connect() - CORE/cake/libs/model/datasources/dbo/dbo_mysql.php, line 561
DboSource::__construct() - CORE/cake/libs/model/datasources/dbo_source.php, line 143
ConnectionManager::getDataSource() - CORE/cake/libs/model/connection_manager.php, line 114
MigrationVersion::__initMigrations() - APP/plugins/migrations/libs/migration_version.php, line 239
MigrationVersion::__construct() - APP/plugins/migrations/libs/migration_version.php, line 61
MigrationShell::startup() - APP/plugins/migrations/vendors/shells/migration.php, line 89
ShellDispatcher::dispatch() - CORE/cake/console/cake.php, line 376
ShellDispatcher::ShellDispatcher() - CORE/cake/console/cake.php, line 139
[main] - CORE/cake/console/cake.php, line 666</pre></div></pre><pre class="cake-debug"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr2-trace').style.display = (document.getElementById('cakeErr2-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (2)</a>: mysql_query(): supplied argument is not a valid MySQL-Link resource [<b>CORE/cake/libs/model/datasources/dbo/dbo_mysql.php</b>, line <b>613</b>]<div id="cakeErr2-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr2-code').style.display = (document.getElementById('cakeErr2-code').style.display == 'none' ? '' : 'none')">Code</a> | <a href="javascript:void(0);" onclick="document.getElementById('cakeErr2-context').style.display = (document.getElementById('cakeErr2-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr2-context" class="cake-context" style="display: none;">$sql    =   "SHOW TABLES FROM `portal_rse`;"</pre><pre class="stack-trace">mysql_query - [internal], line ??
DboMysql::_execute() - CORE/cake/libs/model/datasources/dbo/dbo_mysql.php, line 613
DboMysql::listSources() - CORE/cake/libs/model/datasources/dbo/dbo_mysql.php, line 626
MigrationVersion::__initMigrations() - APP/plugins/migrations/libs/migration_version.php, line 240
MigrationVersion::__construct() - APP/plugins/migrations/libs/migration_version.php, line 61
MigrationShell::startup() - APP/plugins/migrations/vendors/shells/migration.php, line 89
ShellDispatcher::dispatch() - CORE/cake/console/cake.php, line 376
ShellDispatcher::ShellDispatcher() - CORE/cake/console/cake.php, line 139
[main] - CORE/cake/console/cake.php, line 666</pre></div></pre><pre class="cake-debug"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr3-trace').style.display = (document.getElementById('cakeErr3-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (2)</a>: mysql_errno(): supplied argument is not a valid MySQL-Link resource [<b>CORE/cake/libs/model/datasources/dbo/dbo_mysql.php</b>, line <b>695</b>]<div id="cakeErr3-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr3-code').style.display = (document.getElementById('cakeErr3-code').style.display == 'none' ? '' : 'none')">Code</a><pre class="stack-trace">mysql_errno - [internal], line ??
DboMysql::lastError() - CORE/cake/libs/model/datasources/dbo/dbo_mysql.php, line 695
DboSource::execute() - CORE/cake/libs/model/datasources/dbo_source.php, line 257
DboSource::begin() - CORE/cake/libs/model/datasources/dbo_source.php, line 1809
CakeMigration::run() - APP/plugins/migrations/libs/model/cake_migration.php, line 164
MigrationVersion::__initMigrations() - APP/plugins/migrations/libs/migration_version.php, line 245
MigrationVersion::__construct() - APP/plugins/migrations/libs/migration_version.php, line 61
MigrationShell::startup() - APP/plugins/migrations/vendors/shells/migration.php, line 89
ShellDispatcher::dispatch() - CORE/cake/console/cake.php, line 376
ShellDispatcher::ShellDispatcher() - CORE/cake/console/cake.php, line 139
[main] - CORE/cake/console/cake.php, line 666</pre></div></pre>
Fatal error: Uncaught exception 'MigrationException' with message 'SQL Error: ' in /Applications/MAMP/htdocs/cake/portal-rse/plugins/migrations/libs/model/cake_migration.php:243
Stack trace:
#0 /Applications/MAMP/htdocs/cake/portal-rse/plugins/migrations/libs/model/cake_migration.php(220): CakeMigration->_createTable('create_table', Array)
#1 /Applications/MAMP/htdocs/cake/portal-rse/plugins/migrations/libs/model/cake_migration.php(169): CakeMigration->_run()
#2 /Applications/MAMP/htdocs/cake/portal-rse/plugins/migrations/libs/migration_version.php(245): CakeMigration->run('up')
#3 /Applications/MAMP/htdocs/cake/portal-rse/plugins/migrations/libs/migration_version.php(61): MigrationVersion->__initMigrations()
#4 /Applications/MAMP/htdocs/cake/portal-rse/plugins/migrations/vendors/shells/migration.php(89): MigrationVersion->__construct(Array)
#5 /Applications/MAMP/htdocs/cakephp/cake/console/cake.php(376): MigrationShell->startup()
#6 /Applications/MAMP/htdocs/cakephp/cake/console/cake.php(139): ShellDispatcher->dispatch() in /Applications/MAMP/htdocs/cake/portal-rse/plugins/migrations/libs/model/cake_migration.php on line 243

I've commented lines 87..89 and it works.

$this->Version =& new MigrationVersion(array(
    'connection' => $this->connection
));

"run reset" does not drop tables with a datasource that uses a prefix

Use Case:

Create a datasource that uses a prefix
Run a migration file that creates a table
Check if table was created. It should be created with no problems, it has $prefix . $tableName.
Now run cake Migrations.migration run reset

Result: table was not dropped
Expected result: table should have been dropped

Another use case is: change "reset" for "down", i. e. : cake Migrations.migration run down. Even though it says it dropped the table, it does not drop it.

Migrations plugin is not aware of foreign keys or unsigned fields

We are working on a ddbb with innodb tables, and with some foreign keys. The migrations plugin does not seem to be aware of the existence of such foreign keys.

We are "condemned" to keep a log of the modifications in foreign keys apart from the migrations, so the whole idea gets lost.

Also the plugin doesn't treat right the unsigned fields.

ClassRegistry not found on CakePHP 2.3.0-RC2

When I run "cake Migrations.migration" on CakePHP 2.3.0-RC2, the following messages are displayed.

"PHP Fatal error: Class 'ClassRegistry' not found in /path/to/app/Plugin/Mi
grations/Lib/MigrationVersion.php on line 62"

It works adding App::uses('ClassRegistry', 'Utitly') in MigrationVersion.php.

Regenerating table(s) when accidentally dropped

If i accidentally drop the tables from a migration plugin (ie 'Ratings' in my example), but the schema_migrations table still has an entry for 'ratings', then when I do 'migration run down -plugin ratings', it complains that the table does not exist. Unfortunately, it aborts at that point and fails to remove the entry from 'schema_migrations', so when I run 'migration run up -plugin ratings', it does absolutely nothing (not creating the desired table) because it things it's already created. 'migration run down' should remove the entry from 'schema_migrations' regardless of whether the table exists or not, in these accidental cases.

Provide a way to keep unsupported DB features

Due to the way CakePHP's schema shell works, running migrations destroy all database information that isn't supported by CakePHP:

  • Table and column comments
  • Foreign keys
  • Check constraints
  • ...

It'd be really cool that your plugin provides a mechanism to enhance the barebones builtin schemas so you can run migrations while not losing your database structure.

Plugin doesn't take names with capitals

Trying to name the migration with any capital letters prompts the user again for a valid name that only contains alphanumeric characters. "001 Initial migration" won't work, but "001 initial migration" will. I was using %>cake migration generate -plugin mypluginname to reproduce this error.

acos, aros, aros_acos are added to migrations when i generate for Plugin Log

I have this commit for Log Plugin

simkimsia/Log@f0044c6

I added a new column to the logs table in the database.

Then i execute

cake20 Migrations.migration generate --plugin Log

then i choose compare with schema.php [Y]

the migrations is generated with the new column AND 3 tables acos, aros, aros_acos are also generated.

Question:

Is this a bug? if so, how do i temporarily fix it?

if not, then how do i prevent this?

generate migration cannot detect new tables

I updated my schema to the database BEFORE the new table is added.

I then added a new table to the database

I then run

cake2 Migrations.migration generate

compare schema.php to database i chose yes.

The migration generated did not detect the new table.

Generating migration creates no directives

Generating successive migrations, per the documentation, does not produce any usable information. both the up[] and down[] arrays are empty unless cake migration generate -f is used, which follows the expected behavior.

Using CakePHP 1.3 stable.

Issues with keys on MySql

Hi,

Often happens the situation with wrong migration generation when make changes a keys.
Plugin creates something like 'calendar_holidays' => array('', 'indexes' => array('type', 'date')),
and when run such migration there is an error with '' field.

Next:
in UP sections, created section for keys is placed on first place, so migration tries to create the existing key when it is not deleted yet.

Regards,
Vlad

Class names can only be 33 characters long

The limit for the length of a class name is 33 characters in the database table. However, the generation shell does not impose any limit to the class length. This can cause long names to be truncated and for the shell to think that the migration has not been applied yet.

Propose to either increase the character limit, or add a length check when adding the migration.

PHP 5.4 Errors

Strict Error: Only variables should be assigned by reference in [/var/www/app/Plugin/Migrations/Lib/CakeMigration.php, line 510]

Migration should detect possible key length overflow

Reported by Jose Lorenzo Rodríguez | October 8th, 2010 @ 12:50 AM

When creating new KEY for a table, and this table is encoded in utf-8, it could happend that the length of the keys exceeds the mysql 1000 bytes maximum for key, as in utf-8, each character is 3 bytes long.

My suggestion is to truncate the key to the closest length that would not overflow the 1000 bytes restriction. like

KEY BY_EMAIL (email(233),passwd(100))

get fatal error when running cake migration all

Hi, i renamed one of my tabels from pages to webpages because conflict with the pages_controller

so i run a migration generate. but somehow the new migration file did not contain drop tables pages and create tables webpages.

so i deleted the migration files and run migration reset

i get this error
Fatal error: Call to undefined method stdClass::run() in C:\xampp\htdocs\wp\app\plugins\migrations\libs\migration_version.php on line 216

please advise

Exit error codes for migration shell

It would be useful to send different exit codes if the migration shell doesn't execute it's task fully, e.g. on abort, on error, etc. This way it can be easily used by build tools like Ant and Phing for automating migrations.

It looks like it's a case of passing an integer value as an argument to $this->_stop() in the MigrationShell class.

Thanks

Error: Field "tableParameters" does not exists in [...]

The migration below has produced this error:

Migration: 009_utf8_collations_encodings Error: Field "tableParameters" does not exists in "admins".

Which is odd, since it was auto-generated from the migrations plugin.

public $migration = array(
'up' => array(
'alter_field' => array(
'admins' => array(
'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_bin'),
),
'down' => array(
'alter_field' => array(
'admins' => array(
'tableParameters' =>array('charset' => 'latin1', 'collate' => 'latin1_swedish_ci', 'engine' => 'MyISAM'),
)
);

2 Tests in develop branch fail

When I've merged a PR today I ran the test before and after, in both cases these two tests failed:

  1. CakeMigrationTest::testTruncateLongIndexKey
    Failed asserting that true is false.

  2. MigrationShellTest::testGenerateDump
    Failed asserting that two strings are equal.

Implement "Preview SQL" feature for "run" command

It'd be interesting to have a way to preview the SQL queries that will be executed against the database. Benefits:

  • Can easily spot errors
  • Can test changes in a local copy of live DB and then deploy with a regular SQL client

Generating a update migration causes schema_migration table to be dropped

Following the basic instructions for generating a update migration:
cake schema generate -f
change db
cake migration generate -f

This causes Migration to add 'schema_migrations' under the drop_table array. This causes a problem when attempting to upgrade a older db (SQL error that 'schema_migrations' table does not exist)

Problem is caused by line 508 of vendors/shell/migration.php.

following migration can run down but not run up

public $migration = array(
    'up' => array(
        'alter_field' => array(
            'products' => array(
                'created_by' => array('type' => 'integer', 'null' => false, 'default' => NULL),
                'modified_by' => array('type' => 'integer', 'null' => false, 'default' => NULL),
            ),
        ),
    ),
    'down' => array(
        'alter_field' => array(
            'products' => array(
                'created_by' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 30, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
                'modified_by' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 30, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
            ),
        ),
    ),
);

Migrations does not take length of integer fields into consideration

Reported by Jippi | February 21st, 2011 @ 03:31 PM

Hi,

I have a SQL file like this:

CREATE TABLE IF NOT EXISTS `applications` (
  `id` varchar(36) COLLATE utf8_danish_ci NOT NULL,
  `module_id` varchar(255) COLLATE utf8_danish_ci NOT NULL,
  `name` varchar(255) COLLATE utf8_danish_ci NOT NULL,
  `slug` varchar(255) COLLATE utf8_danish_ci NOT NULL,
  `is_active` tinyint(1) NOT NULL,
  `app_id` bigint(20) DEFAULT NULL,
  `api_key` varchar(255) COLLATE utf8_danish_ci DEFAULT NULL,
  `app_secret` varchar(255) COLLATE utf8_danish_ci DEFAULT NULL,
  `layout` varchar(255) COLLATE utf8_danish_ci NOT NULL,
  `theme` varchar(255) COLLATE utf8_danish_ci NOT NULL,
  `page_id` varchar(36) COLLATE utf8_danish_ci NOT NULL,
  `use_absolute_urls` tinyint(1) NOT NULL,
  `use_ssl` tinyint(1) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_danish_ci;

Notice that app_id is bigint(20), but the migration only reports it as an integer - which in mysql talk is int(11) - which is too small a width of my integer field, since it's going to store facebook ids, which is well beyond the normal int(11) length

    var $applications = array(
        'id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'key' => 'primary', 'collate' => 'utf8_danish_ci', 'charset' => 'utf8'),
        'module_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'collate' => 'utf8_danish_ci', 'charset' => 'utf8'),
        'name' => array('type' => 'string', 'null' => false, 'default' => NULL, 'collate' => 'utf8_danish_ci', 'charset' => 'utf8'),
        'slug' => array('type' => 'string', 'null' => false, 'default' => NULL, 'collate' => 'utf8_danish_ci', 'charset' => 'utf8'),
        'is_active' => array('type' => 'boolean', 'null' => false, 'default' => NULL),
        'app_id' => array('type' => 'integer', 'null' => true, 'default' => NULL),
        'api_key' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_danish_ci', 'charset' => 'utf8'),
        'app_secret' => array('type' => 'string', 'null' => true, 'default' => NULL, 'collate' => 'utf8_danish_ci', 'charset' => 'utf8'),
        'layout' => array('type' => 'string', 'null' => false, 'default' => NULL, 'collate' => 'utf8_danish_ci', 'charset' => 'utf8'),
        'theme' => array('type' => 'string', 'null' => false, 'default' => NULL, 'collate' => 'utf8_danish_ci', 'charset' => 'utf8'),
        'page_id' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 36, 'collate' => 'utf8_danish_ci', 'charset' => 'utf8'),
        'use_absolute_urls' => array('type' => 'boolean', 'null' => false, 'default' => NULL),
        'use_ssl' => array('type' => 'boolean', 'null' => false, 'default' => NULL),
        'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)),
        'tableParameters' => array('charset' => 'utf8', 'collate' => 'utf8_danish_ci', 'engine' => 'InnoDB')
    );

Drop tables in schema comparison

When i do "migration generate -f" and pick schema diff, the result migration drop all tables that don have modifications.

Recreated situation:

  • Install the example app

  • Make initial "migration all"

  • Generate the schema "schema generate -f"

  • Add a field "test" to the table "ingredients".

  • Generate new migration "migration generate -f"

  • The result migration UP section looks like that:

    var $migration = array(
    'up' => array(
    'add_field' => array(
    'ingredients' => array(
    'test' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'length' => 10),
    ),
    ),
    'drop_table' => array(
    'categories', 'ingredients_recipes', 'recipes', 'schema_migrations', 'users'
    ),
    ),

I look into the sources and note that this is because this pice of code in line 390 of migation.php

    foreach ($oldTables as $table => $fields) {
        if (!isset($comparison[$table])) {
            $migration['up']['drop_table'][] = $table;
            $migration['down']['create_table'][$table] = $fields;
        }
    }

I debug the generate function and the result of compare new and old schema is this array:

Array(
[ingredients] => Array (
[add] => Array (
[test] => Array (
[type] => integer
[null] =>
[default] =>
[length] => 10
))))

Thats why drop the tables. This is a bug? or maybe the result of comparison must be diferent?

generate command accepts invalid migration names

The Console\cake Migrations.migration generate command accepts invalid names that will later result in a crash:

Please enter the descriptive name of the migration to generate:
> Claves foráneas
Generating Migration...
Error: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xA0Neas' for column 'class' at row 1
#0 E:\Test\lib\Cake\Model\Datasource\DboSource.php(461): PDOStatement->execute(Array)
#1 E:\Test\lib\Cake\Model\Datasource\DboSource.php(427): DboSource->_execute('INSERT INTO `ga...', Array)
#2 E:\Test\lib\Cake\Model\Datasource\DboSource.php(1009): DboSource->execute('INSERT INTO `ga...')
#3 E:\Test\lib\Cake\Model\Model.php(1730): DboSource->create(Object(SchemaMigration), Array, Array)
#4 E:\Test\app\Plugin\Migrations\Lib\MigrationVersion.php(116): Model->save(Array)
#5 E:\Test\app\Plugin\Migrations\Console\Command\MigrationShell.php(352): MigrationVersion->setVersion('1345794161', 'app')
#6 E:\Test\lib\Cake\Console\Shell.php(390): MigrationShell->generate()
#7 E:\Test\lib\Cake\Console\ShellDispatcher.php(201): Shell->runCommand('generate', Array)
#8 E:\Test\lib\Cake\Console\ShellDispatcher.php(69): ShellDispatcher->dispatch()
#9 E:\Test\app\Console\cake.php(33): ShellDispatcher::run(Array)
#10 {main}
HY000

Tested with current master on Windows XP Professional (Spanish/Spain).

The Migrations.SchemaMigration model must extends Model instead of AppModel

In MigrationVersion::__initMigrations(), the Model "Migrations.SchemaMigration" is initialized using ClassRegistry::init()

Since the model is not shipped in the plugin, Cake will create a ghost model extending AppModel.
This behavior could cause issues if the application's AppModel is related to an application model whose table has not been created yet. In this case the error "Error: Missing database table 'xxxx' for model 'XXXX'" will be thrown and the shell could not be run.

A solution would be to create an empty model in the plugin, extending Model. I implemented it in my fork and will do a pull request.

Attempting to compare migration / generate to schema fatal error

Fatal error: Class 'AppSchema' not found in /Library/www/htdocs/internal/pixd/trunk/htdocs/plugins/migrations/vendors/shells/migration.php on line 218

This occurs when attempting to compare a generate to the schema file, even a freshly generated schema.php and snapshots (tried both) on a plugin. I have not tried this on the app yet.

%> cake migration generate -plugin mypluginname
> name it
> y
error.....

Cakephp 1.3.6 + PHP 5.3.3

Issues with model caching

Reported by Pierre Martin | January 31st, 2011 @ 02:27 AM

Ticket from an email from Scott Reeves

Using your migrations plugin, I've seen quite often that the plugin will fail to generate a diff between the database and schema.php (empty $migration array) if model caching is enabled.

I think bypassing the model cache should be built into the plugin if possible.

Problem with CakePHP 2.1 branch

Migrations plugin needs to reflect CakePHP api changes
from
(2.0) DboSource::fullTableName($model, $quote = true)
to
(2.1) DboSource::fullTableName($model, $quote = true, $schema = true)
otherwise check of schema_migrations table can not pass.

Error during migration does not rollback previous actions

Reported by avairet | February 13th, 2011 @ 08:39 AM

CakePHP 1.3.7/MySQL 5.1 (MyISAM) context.

When an error occurs during a migration, previous actions are not rollbacked, so it's impossible to run again without make rollback manually in the database.

Consider my report in the "Prefixes issue" ticket:
http://cakedc.lighthouseapp.com/projects/59617-migrations-plugin/ti...

In migration number 5, there is an error with a drop table action, so migration is stopping and it is not marked as applied in the schema_migrations table. But the first migration actions are nevertheless executed:

'create_field' => array('documents' => array('description' => array('type' => 'text', 'null' => true, 'default' => NULL, 'collate' => 'utf8_unicode_ci', 'charset' => 'utf8'),),),
'alter_field' => array('documents' => array('content' => array('type' => 'text', 'null' => true, 'default' => NULL, 'collate' => 'utf8_unicode_ci', 'charset' => 'utf8'),),),

So after that, if I run migration number 5 again, I have this error: "decription field allready exists in the database"...

I add my 5 migration files to the ticket. Run it one by one and you will see the problem for migration number 5.

migrations.zip

Fatal error when comparing to schema.php

On RC3 I can't get further than the initial step. When I try to do a comparison with schema.php I get a fatal error from php.

The problem appears to be that you expect the schema class to be called AppSchema when in fact it may be named any number of things. It looks like Cake is using the "app" folder name as the class name.

 $this->name = Inflector::camelize(Inflector::slug(Configure::read('App.dir')));

The error output:

Welcome to CakePHP v1.3.0-RC3 Console
---------------------------------------------------------------
App : great
Path: /Users/martin/Sites/cake/great
---------------------------------------------------------------
Cake Migration Shell
---------------------------------------------------------------
Please enter the descriptive name of the migration to generate:  
> 002 test
Do you wanna compare the schema.php file to the database? (y/n) 
[y] > 
---------------------------------------------------------------
Comparing schema.php to the database...
PHP Fatal error:  Class 'AppSchema' not found in /Users/martin/Sites/cake/great/plugins/migrations/vendors/shells/migration.php on line 218

Fatal error: Class 'AppSchema' not found in /Users/martin/Sites/cake/great/plugins/migrations/vendors/shells/migration.php on line 218

migrations already migrated but still get prompted

I was previously using migrations before 2.1

Now I have switched to 2.1, the migrations files in the app/Config/Migrations start with huge numbers like 1337679202

Whenever i run Migrations.migration all,

those files get prompted even though the migrations occurred already.

Please advise quickly. My jenkins on server uses Migrations plugin as a build step and I do not want to trigger errors non stop

When i try run migration generate inside app folder named with dash.

Reported by Daniel Pakuschewski | September 29th, 2011 @ 12:09 PM

What i did:

Welcome to CakePHP v1.3.12 Console
---------------------------------------------------------------
App : communication-meeting
Path: /home/daniel/www/daniel/communication-meeting
---------------------------------------------------------------
Cake Migration Shell
---------------------------------------------------------------
Please enter the descriptive name of the migration to generate:  
> alter_table_video
PHP Fatal error:  Class 'Communication-meetingSchema' not found in /var/www/share/cakephp/plugins/migrations/vendors/shells/migration.php on line 504

Fatal error: Class 'Communication-meetingSchema' not found in /var/www/share/cakephp/plugins/migrations/vendors/shells/migration.php on line 504

How i fixed it:
Near line 499 of vendors/shells/migration.php i added a str_replace to remove dash.

 $name = Inflector::camelize($type) . 'Schema';
 if ($type == 'app' && !class_exists($name)) {
      $this->params['app'] = str_replace('-', '', $this->params['app']);
      $name = Inflector::camelize($this->params['app']) . 'Schema';
 }

I know it isnt the best fix but solved for now. ;)

[Request] Specify the database/host to migrate

Guys how can I specify the database/host to run the Migrations?

We have here a database for each client, so we would need to run the migrations for each database.

Also, we would need a way to check if we need to create the migrations table or not, because the script will run automatically.

Any ideas?


But the main problem is, I'm getting an error trying to execute any command from the manual:

Error: Shell class MigrationsShell could not be found.

(I already loaded the plugin on bootstrap.php)

Thanks guys.

cake migration generate is suddenly not working. empty arrays for up and down

hi

previously my migrations generate is working just fine creating the migration schema differences.

however, recently it is no longer working properly. the files are generated but the up and down are empty arrays.

i cannot recall what i did beforehand as i did quite a lot of other stuff including:

generating a new schema using cake schema create and then overwriting my old one.
deleting a few migrations that were wrong and then removing them from the map.php accordingly.
did a more than a few times of using cake migration reset and cake migration all

currently the following commands still work as pernormal:
cake migration all
will update to latest migration

cake migration reset
will empty the database

cake migration
will list all current migrations and statuses.

Please advise. I am heavily reliant on migrations and its quite troublesome to code the directives one by one now that my cake migration generate is no longer working properly

How do you do alter_table?

Reported by mark (at netplenish) | June 23rd, 2011 @ 08:54 PM

There is no documentation on alter_table directives.

cake migration issues. different behaviour on my own project versus fresh copies

i am having a lot of weird behaviour with migrations on my current project running on 1.3.0 stable release.

  1. now migrations cannot properly make changes with comparing with the schema on my stable release
  2. then i went to run the test cases for migrations plugin. all passed except for 2.
  3. then out of sheer frustration i went to redownload a fresh copy of the 1.3.0 RC4 and teh 1.3.0 stable that was released recently and redownload a fresh copy of migrations and have 2 clean cake apps installed. and the latest migrations and latest simpletest 1.0.1 on them.
  4. now on these 2 fresh copies i can pass all the unit tests. and some data was logged in the schema migrations table after the unit tests were passed. not sure if this is supposed to be the case.
  5. then i try to make the migrations on these 2 fresh copies, i cannot even make the initial ones.
  6. then i try to generate schema on these 2 fresh copies. now i cannot even do that on these 2 fresh copies.
  7. unbelievably, on my own project i can still do schema generate and the initial migration with the dump
  8. everytime i switch from using cake on my own project or the 2 fresh copies i always change the the system variables and the User Path variable to use the correct cake/console for the individual cases above.

i am tired of all these wacky behavior. i am just going to remove schema in my own project and keep using generate dump with my migrations.

to think recently my migrations all of a sudden was working again after some problems.

my OS is windows vista, php is 5.3.1 my xampp is 1.7.3

i can zip and send you all 3 different installations of the cake (rc4 fresh, stable fresh, my own project 1.3.0 stable plus the sql files)

Please help. Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.