Fixed migrations

This commit is contained in:
Dmitry Khomutov 2016-05-05 22:33:12 +06:00
parent ca2f5ed197
commit ff36c2504f
7 changed files with 56 additions and 68 deletions

View file

@ -10,8 +10,12 @@ class ChangeBuildKeysMigration extends AbstractMigration
public function up()
{
$project = $this->table('project');
$project->renameColumn('git_key', 'ssh_private_key');
$project->renameColumn('public_key', 'ssh_public_key');
if (!$project->hasColumn('ssh_private_key') && $project->hasColumn('git_key')) {
$project->renameColumn('git_key', 'ssh_private_key');
}
if (!$project->hasColumn('ssh_public_key') && $project->hasColumn('public_key')) {
$project->renameColumn('public_key', 'ssh_public_key');
}
}
/**
@ -20,7 +24,11 @@ class ChangeBuildKeysMigration extends AbstractMigration
public function down()
{
$project = $this->table('project');
$project->renameColumn('ssh_private_key', 'git_key');
$project->renameColumn('ssh_public_key', 'public_key');
if (!$project->hasColumn('git_key') && $project->hasColumn('ssh_private_key')) {
$project->renameColumn('ssh_private_key', 'git_key');
}
if (!$project->hasColumn('public_key') && $project->hasColumn('ssh_public_key')) {
$project->renameColumn('ssh_public_key', 'public_key');
}
}
}

View file

@ -23,10 +23,9 @@ class ChooseBranch extends AbstractMigration
public function up()
{
$project = $this->table('project');
$project->addColumn('branch', 'string', [
'after' => 'reference',
'limit' => 250
])->save();
if (!$project->hasColumn('branch')) {
$project->addColumn('branch', 'string', ['after' => 'reference', 'limit' => 250])->save();
}
}
/**
@ -35,6 +34,8 @@ class ChooseBranch extends AbstractMigration
public function down()
{
$project = $this->table('project');
$project->removeColumn('branch')->save();
if ($project->hasColumn('branch')) {
$project->removeColumn('branch')->save();
}
}
}

View file

@ -10,8 +10,9 @@ class ArchiveProject extends AbstractMigration
public function up()
{
$project = $this->table('project');
$project->addColumn('archived', 'boolean', ['default' => 0]);
$project->save();
if (!$project->hasColumn('archived')) {
$project->addColumn('archived', 'boolean', ['default' => 0])->save();
}
}
/**
@ -20,7 +21,8 @@ class ArchiveProject extends AbstractMigration
public function down()
{
$project = $this->table('project');
$project->removeColumn('archived');
$project->save();
if ($project->hasColumn('archived')) {
$project->removeColumn('archived')->save();
}
}
}

View file

@ -12,16 +12,10 @@ class FixColumnTypes extends AbstractMigration
{
// Update the build log column to MEDIUMTEXT:
$build = $this->table('build');
$build->changeColumn('log', 'text', [
'null' => true,
'limit' => MysqlAdapter::TEXT_MEDIUM,
]);
$build->changeColumn('log', 'text', ['null' => true, 'limit' => MysqlAdapter::TEXT_MEDIUM]);
// Update the build meta value column to MEDIUMTEXT:
$buildMeta = $this->table('build_meta');
$buildMeta->changeColumn('meta_value', 'text', [
'null' => false,
'limit' => MysqlAdapter::TEXT_MEDIUM,
]);
$buildMeta->changeColumn('meta_value', 'text', ['null' => false, 'limit' => MysqlAdapter::TEXT_MEDIUM]);
}
}

View file

@ -10,10 +10,12 @@ class UniqueEmailAndNameUserFields extends AbstractMigration
public function up()
{
$user_table = $this->table('user');
$user_table
->addIndex('email', ['unique' => true])
->addIndex('name', ['unique' => true])
->save();
if (!$user_table->hasIndex('email', ['unique' => true])) {
$user_table->addIndex('email', ['unique' => true])->save();
}
if (!$user_table->hasIndex('name', ['unique' => true])) {
$user_table->addIndex('name', ['unique' => true])->save();
}
}
/**
@ -22,9 +24,11 @@ class UniqueEmailAndNameUserFields extends AbstractMigration
public function down()
{
$user_table = $this->table('user');
$user_table
->removeIndex('email', ['unique' => true])
->removeIndex('name', ['unique' => true])
->save();
if ($user_table->hasIndex('email', ['unique' => true])) {
$user_table->removeIndex('email', ['unique' => true])->save();
}
if ($user_table->hasIndex('name', ['unique' => true])) {
$user_table->removeIndex('name', ['unique' => true])->save();
}
}
}

View file

@ -7,23 +7,23 @@ class AddProjectGroups extends AbstractMigration
public function change()
{
$table = $this->table('project_group');
$table->addColumn('title', 'string', ['limit' => 100, 'null' => false]);
$table->save();
if (!$table->hasColumn('title')) {
$table->addColumn('title', 'string', ['limit' => 100, 'null' => false])->save();
$group = new \PHPCI\Model\ProjectGroup();
$group->setTitle('Projects');
$group = new \PHPCI\Model\ProjectGroup();
$group->setTitle('Projects');
/** @var \PHPCI\Model\ProjectGroup $group */
$group = \b8\Store\Factory::getStore('ProjectGroup')->save($group);
\b8\Store\Factory::getStore('ProjectGroup')->save($group);
}
$table = $this->table('project');
$table->addColumn('group_id', 'integer', [
'signed' => true,
'null' => false,
'default' => $group->getId(),
]);
$table->addForeignKey('group_id', 'project_group', 'id', ['delete'=> 'RESTRICT', 'update' => 'CASCADE']);
$table->save();
if (!$table->hasColumn('group_id')) {
$table->addColumn('group_id', 'integer', [
'signed' => true,
'null' => false,
'default' => 1,
]);
$table->addForeignKey('group_id', 'project_group', 'id', ['delete'=> 'RESTRICT', 'update' => 'CASCADE'])->save();
}
}
}

View file

@ -4,37 +4,16 @@ use Phinx\Migration\AbstractMigration;
class RemoveUniqueNameIndex extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
$user = $this->table('user');
if ($user->hasIndex('name', ['unique' => true])) {
$user->removeIndex('name', ['unique' => true]);
$user->save();
$user->removeIndex('name', ['unique' => true])->save();
}
$user->addIndex('name', ['unique' => false]);
$user->save();
if (!$user->hasIndex('name', ['unique' => true])) {
$user->addIndex('name', ['unique' => false])->save();
}
}
}