From ff36c2504f909dcd8fbe7990ff4b1df515b75d6a Mon Sep 17 00:00:00 2001 From: Dmitry Khomutov Date: Thu, 5 May 2016 22:33:12 +0600 Subject: [PATCH] Fixed migrations --- ...0513153133_change_build_keys_migration.php | 16 +++++++--- .../20140611170618_choose_branch.php | 11 +++---- .../20150131075425_archive_project.php | 10 ++++--- .../20150203105015_fix_column_types.php | 10 ++----- ...4958_unique_email_and_name_user_fields.php | 20 ++++++++----- .../20151008140800_add_project_groups.php | 28 +++++++++--------- ...0151009100610_remove_unique_name_index.php | 29 +++---------------- 7 files changed, 56 insertions(+), 68 deletions(-) diff --git a/src/PHPCI/Migrations/20140513153133_change_build_keys_migration.php b/src/PHPCI/Migrations/20140513153133_change_build_keys_migration.php index 7fd253cc..c2390607 100644 --- a/src/PHPCI/Migrations/20140513153133_change_build_keys_migration.php +++ b/src/PHPCI/Migrations/20140513153133_change_build_keys_migration.php @@ -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'); + } } } diff --git a/src/PHPCI/Migrations/20140611170618_choose_branch.php b/src/PHPCI/Migrations/20140611170618_choose_branch.php index 3422322a..12526b9d 100644 --- a/src/PHPCI/Migrations/20140611170618_choose_branch.php +++ b/src/PHPCI/Migrations/20140611170618_choose_branch.php @@ -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(); + } } } diff --git a/src/PHPCI/Migrations/20150131075425_archive_project.php b/src/PHPCI/Migrations/20150131075425_archive_project.php index f1c0b39b..fae9e00c 100644 --- a/src/PHPCI/Migrations/20150131075425_archive_project.php +++ b/src/PHPCI/Migrations/20150131075425_archive_project.php @@ -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(); + } } } \ No newline at end of file diff --git a/src/PHPCI/Migrations/20150203105015_fix_column_types.php b/src/PHPCI/Migrations/20150203105015_fix_column_types.php index 2c873b11..4fbc210d 100644 --- a/src/PHPCI/Migrations/20150203105015_fix_column_types.php +++ b/src/PHPCI/Migrations/20150203105015_fix_column_types.php @@ -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]); } } diff --git a/src/PHPCI/Migrations/20150324174958_unique_email_and_name_user_fields.php b/src/PHPCI/Migrations/20150324174958_unique_email_and_name_user_fields.php index 99ac87f5..4198806d 100644 --- a/src/PHPCI/Migrations/20150324174958_unique_email_and_name_user_fields.php +++ b/src/PHPCI/Migrations/20150324174958_unique_email_and_name_user_fields.php @@ -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(); + } } } diff --git a/src/PHPCI/Migrations/20151008140800_add_project_groups.php b/src/PHPCI/Migrations/20151008140800_add_project_groups.php index 987896ce..bc6e1c79 100644 --- a/src/PHPCI/Migrations/20151008140800_add_project_groups.php +++ b/src/PHPCI/Migrations/20151008140800_add_project_groups.php @@ -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(); + } } } diff --git a/src/PHPCI/Migrations/20151009100610_remove_unique_name_index.php b/src/PHPCI/Migrations/20151009100610_remove_unique_name_index.php index 2633c28b..028c9114 100644 --- a/src/PHPCI/Migrations/20151009100610_remove_unique_name_index.php +++ b/src/PHPCI/Migrations/20151009100610_remove_unique_name_index.php @@ -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(); + } } }