What do you think about a merge functionality on database migrations?
In my point of view it would be really usefull if we could merge several migrations into a new one and name it for example “user-blog-feature” or “proj-v.1.0”. With a restriction for the user to select consecutive migrations so that they can accumulate i think it’s possible.
@samdark - For example let’s say i have the following two migrations:
class m110119_191533_create_user_table extends CDbMigration
{
public function up()
{
$this->createTable('User', array(
'user_id' => 'pk',
'username' => 'varchar (100) NOT NULL',
'password' => 'varchar (128) NOT NULL',
'email' => 'varchar (250) NOT NULL',
), 'ENGINE = INNODB DEFAULT CHARSET = UTF8;');
}
public function down()
{
$this->dropTable('User');
}
}
and
class m110121_221939_add_created_at_column_in_user_table extends CDbMigration
{
public function up()
{
$this->addColumn('User', 'created_at', 'timestamp DEFAULT CURRENT_TIMESTAMP');
}
public function down()
{
$this->dropColumn('User', 'created_at');
}
}
Selecting the above migrations for merge would create a new one let’s name it ‘User_table_final’ with code:
class m110126_231528_create_user_table extends CDbMigration
{
public function up()
{
$this->createTable('User', array(
'user_id' => 'pk',
'username' => 'varchar (100) NOT NULL',
'password' => 'varchar (128) NOT NULL',
'email' => 'varchar (250) NOT NULL',
'timestamp' => 'timestamp DEFAULT CURRENT_TIMESTAMP',
), 'ENGINE = INNODB DEFAULT CHARSET = UTF8;');
}
public function down()
{
$this->dropTable('User');
}
@qiang - Yes i second your opinion that this may be too complex -and require code that is not really reusable anywhere else- to be put in the core. It was just a thought and i thought i should share it in the forum.
Hope i can find some free time in the future and try to create this as an extension.