Fixed migrations

This commit is contained in:
Dmitry Khomutov 2016-05-07 12:43:21 +06:00
parent be645cbd9f
commit fd5dd16a64
11 changed files with 165 additions and 102 deletions

View file

@ -9,7 +9,6 @@ class InitialMigration extends AbstractMigration
{
public function up()
{
// Set up tables:
$this->createBuildTable();
$this->createBuildMetaTable();
$this->createProjectTable();
@ -19,27 +18,18 @@ class InitialMigration extends AbstractMigration
$build = $this->table('build');
if (!$build->hasForeignKey('project_id')) {
$build->addForeignKey('project_id', 'project', 'id', ['delete'=> 'CASCADE', 'update' => 'CASCADE']);
$build->addForeignKey('project_id', 'project', 'id', ['delete'=> 'CASCADE', 'update' => 'CASCADE'])->save();
}
$build->save();
$buildMeta = $this->table('build_meta');
if (!$buildMeta->hasForeignKey('build_id')) {
$buildMeta->addForeignKey('build_id', 'build', 'id', ['delete'=> 'CASCADE', 'update' => 'CASCADE']);
$buildMeta->addForeignKey('build_id', 'build', 'id', ['delete'=> 'CASCADE', 'update' => 'CASCADE'])->save();
}
if (!$buildMeta->hasForeignKey('project_id')) {
$buildMeta->addForeignKey('project_id', 'project', 'id', ['delete'=> 'CASCADE', 'update' => 'CASCADE']);
$buildMeta->addForeignKey('project_id', 'project', 'id', ['delete'=> 'CASCADE', 'update' => 'CASCADE'])->save();
}
$buildMeta->save();
}
public function down()
{
}
protected function createBuildTable()
@ -51,62 +41,60 @@ class InitialMigration extends AbstractMigration
}
if (!$table->hasColumn('project_id')) {
$table->addColumn('project_id', 'integer');
$table->addColumn('project_id', 'integer')->save();
}
if (!$table->hasColumn('commit_id')) {
$table->addColumn('commit_id', 'string', ['limit' => 50]);
$table->addColumn('commit_id', 'string', ['limit' => 50])->save();
}
if (!$table->hasColumn('status')) {
$table->addColumn('status', 'integer', ['limit' => 4]);
$table->addColumn('status', 'integer', ['limit' => 4])->save();
}
if (!$table->hasColumn('log')) {
$table->addColumn('log', 'text');
$table->addColumn('log', 'text')->save();
}
if (!$table->hasColumn('branch')) {
$table->addColumn('branch', 'string', ['limit' => 50]);
$table->addColumn('branch', 'string', ['limit' => 50])->save();
}
if (!$table->hasColumn('created')) {
$table->addColumn('created', 'datetime');
$table->addColumn('created', 'datetime')->save();
}
if (!$table->hasColumn('started')) {
$table->addColumn('started', 'datetime');
$table->addColumn('started', 'datetime')->save();
}
if (!$table->hasColumn('finished')) {
$table->addColumn('finished', 'datetime');
$table->addColumn('finished', 'datetime')->save();
}
if (!$table->hasColumn('committer_email')) {
$table->addColumn('committer_email', 'string', ['limit' => 250]);
$table->addColumn('committer_email', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('commit_message')) {
$table->addColumn('commit_message', 'text');
$table->addColumn('commit_message', 'text')->save();
}
if (!$table->hasColumn('extra')) {
$table->addColumn('extra', 'text');
$table->addColumn('extra', 'text')->save();
}
if ($table->hasColumn('plugins')) {
$table->removeColumn('plugins');
$table->removeColumn('plugins')->save();
}
if (!$table->hasIndex(['project_id'])) {
$table->addIndex(['project_id']);
$table->addIndex(['project_id'])->save();
}
if (!$table->hasIndex(['status'])) {
$table->addIndex(['status']);
$table->addIndex(['status'])->save();
}
$table->save();
}
protected function createBuildMetaTable()
@ -118,26 +106,24 @@ class InitialMigration extends AbstractMigration
}
if (!$table->hasColumn('project_id')) {
$table->addColumn('project_id', 'integer');
$table->addColumn('project_id', 'integer')->save();
}
if (!$table->hasColumn('build_id')) {
$table->addColumn('build_id', 'integer');
$table->addColumn('build_id', 'integer')->save();
}
if (!$table->hasColumn('meta_key')) {
$table->addColumn('meta_key', 'string', ['limit' => 250]);
$table->addColumn('meta_key', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('meta_value')) {
$table->addColumn('meta_value', 'text');
$table->addColumn('meta_value', 'text')->save();
}
if (!$table->hasIndex(['build_id', 'meta_key'])) {
$table->addIndex(['build_id', 'meta_key']);
$table->addIndex(['build_id', 'meta_key'])->save();
}
$table->save();
}
protected function createProjectTable()
@ -149,50 +135,48 @@ class InitialMigration extends AbstractMigration
}
if (!$table->hasColumn('title')) {
$table->addColumn('title', 'string', ['limit' => 250]);
$table->addColumn('title', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('reference')) {
$table->addColumn('reference', 'string', ['limit' => 250]);
$table->addColumn('reference', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('git_key')) {
$table->addColumn('git_key', 'text');
$table->addColumn('git_key', 'text')->save();
}
if (!$table->hasColumn('public_key')) {
$table->addColumn('public_key', 'text');
$table->addColumn('public_key', 'text')->save();
}
if (!$table->hasColumn('type')) {
$table->addColumn('type', 'string', ['limit' => 50]);
$table->addColumn('type', 'string', ['limit' => 50])->save();
}
if (!$table->hasColumn('access_information')) {
$table->addColumn('access_information', 'string', ['limit' => 250]);
$table->addColumn('access_information', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('last_commit')) {
$table->addColumn('last_commit', 'string', ['limit' => 250]);
$table->addColumn('last_commit', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('build_config')) {
$table->addColumn('build_config', 'text');
$table->addColumn('build_config', 'text')->save();
}
if (!$table->hasColumn('allow_public_status')) {
$table->addColumn('allow_public_status', 'integer');
$table->addColumn('allow_public_status', 'integer')->save();
}
if ($table->hasColumn('token')) {
$table->removeColumn('token');
$table->removeColumn('token')->save();
}
if (!$table->hasIndex(['title'])) {
$table->addIndex(['title']);
$table->addIndex(['title'])->save();
}
$table->save();
}
protected function createUserTable()
@ -204,25 +188,23 @@ class InitialMigration extends AbstractMigration
}
if (!$table->hasColumn('email')) {
$table->addColumn('email', 'string', ['limit' => 250]);
$table->addColumn('email', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('hash')) {
$table->addColumn('hash', 'string', ['limit' => 250]);
$table->addColumn('hash', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('name')) {
$table->addColumn('name', 'string', ['limit' => 250]);
$table->addColumn('name', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('is_admin')) {
$table->addColumn('is_admin', 'integer');
$table->addColumn('is_admin', 'integer')->save();
}
if (!$table->hasIndex(['email'])) {
$table->addIndex(['email']);
$table->addIndex(['email'])->save();
}
$table->save();
}
}

View file

@ -7,9 +7,11 @@ class ChangeBuildKeysMigration extends AbstractMigration
public function up()
{
$project = $this->table('project');
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');
}
@ -18,9 +20,11 @@ class ChangeBuildKeysMigration extends AbstractMigration
public function down()
{
$project = $this->table('project');
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

@ -7,6 +7,7 @@ class ChooseBranch extends AbstractMigration
public function up()
{
$project = $this->table('project');
if (!$project->hasColumn('branch')) {
$project->addColumn('branch', 'string', ['after' => 'reference', 'limit' => 250])->save();
}
@ -15,6 +16,7 @@ class ChooseBranch extends AbstractMigration
public function down()
{
$project = $this->table('project');
if ($project->hasColumn('branch')) {
$project->removeColumn('branch')->save();
}

View file

@ -14,6 +14,7 @@ class FixDatabaseColumns extends AbstractMigration
}
$build = $this->table('build');
$build->changeColumn('project_id', 'integer', ['null' => false]);
$build->changeColumn('commit_id', 'string', ['limit' => 50, 'null' => false]);
$build->changeColumn('status', 'integer', ['null' => false]);
@ -27,12 +28,14 @@ class FixDatabaseColumns extends AbstractMigration
$build->changeColumn('extra', 'text', ['null' => true]);
$buildMeta = $this->table('build_meta');
$buildMeta->changeColumn('project_id', 'integer', ['null' => false]);
$buildMeta->changeColumn('build_id', 'integer', ['null' => false]);
$buildMeta->changeColumn('meta_key', 'string', ['limit' => 250, 'null' => false]);
$buildMeta->changeColumn('meta_value', 'text', ['null' => false]);
$project = $this->table('project');
$project->changeColumn('title', 'string', ['limit' => 250, 'null' => false]);
$project->changeColumn('reference', 'string', ['limit' => 250, 'null' => false]);
$project->changeColumn('branch', 'string', ['limit' => 50, 'null' => false, 'default' => 'master']);
@ -45,6 +48,7 @@ class FixDatabaseColumns extends AbstractMigration
$project->changeColumn('allow_public_status', 'integer', ['null' => false, 'default' => 0]);
$user = $this->table('user');
$user->changeColumn('email', 'string', ['limit' => 250, 'null' => false]);
$user->changeColumn('hash', 'string', ['limit' => 250, 'null' => false]);
$user->changeColumn('is_admin', 'integer', ['null' => false, 'default' => 0]);
@ -55,4 +59,9 @@ class FixDatabaseColumns extends AbstractMigration
$pdo->exec('SET foreign_key_checks = 1');
}
}
public function down()
{
}
}

View file

@ -7,6 +7,7 @@ class ArchiveProject extends AbstractMigration
public function up()
{
$project = $this->table('project');
if (!$project->hasColumn('archived')) {
$project->addColumn('archived', 'boolean', ['default' => 0])->save();
}
@ -15,6 +16,7 @@ class ArchiveProject extends AbstractMigration
public function down()
{
$project = $this->table('project');
if ($project->hasColumn('archived')) {
$project->removeColumn('archived')->save();
}

View file

@ -7,12 +7,23 @@ class FixColumnTypes extends AbstractMigration
{
public function up()
{
// Update the build log column to MEDIUMTEXT:
$build = $this->table('build');
$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]);
}
public function down()
{
$build = $this->table('build');
$build->changeColumn('log', 'text', ['null' => true]);
$buildMeta = $this->table('build_meta');
$buildMeta->changeColumn('meta_value', 'text', ['null' => false]);
}
}

View file

@ -7,9 +7,11 @@ class UniqueEmailAndNameUserFields extends AbstractMigration
public function up()
{
$user_table = $this->table('user');
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();
}
@ -18,9 +20,11 @@ class UniqueEmailAndNameUserFields extends AbstractMigration
public function down()
{
$user_table = $this->table('user');
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,6 +7,7 @@ class AddProjectGroups extends AbstractMigration
public function up()
{
$table = $this->table('project_group');
if (!$this->hasTable('project_group')) {
$table->create();
}
@ -21,26 +22,31 @@ class AddProjectGroups extends AbstractMigration
}
$table = $this->table('project');
if (!$table->hasColumn('group_id')) {
$table->addColumn('group_id', 'integer', [
'signed' => true,
'null' => false,
'default' => 1,
]);
$table->addColumn('group_id', 'integer', ['signed' => true, 'null' => false, 'default' => 1,])->save();
}
if (!$table->hasForeignKey('group_id')) {
$table->addForeignKey('group_id', 'project_group', 'id', ['delete'=> 'RESTRICT', 'update' => 'CASCADE'])->save();
}
}
public function down()
{
$table = $this->table('project');
if ($table->hasForeignKey('group_id')) {
$table->dropForeignKey('group_id');
}
if ($table->hasColumn('group_id')) {
$table->removeColumn('group_id');
}
$table = $this->table('project_group');
if ($this->hasTable('project_group')) {
$table->drop();
}
$table = $this->table('project');
if ($table->hasColumn('group_id')) {
$table->removeColumn('group_id');
}
}
}

View file

@ -4,7 +4,7 @@ use Phinx\Migration\AbstractMigration;
class RemoveUniqueNameIndex extends AbstractMigration
{
public function change()
public function up()
{
$user = $this->table('user');

View file

@ -5,20 +5,65 @@ use Phinx\Db\Adapter\MysqlAdapter;
class ErrorsTable extends AbstractMigration
{
public function change()
public function up()
{
$table = $this->table('build_error');
$table->addColumn('build_id', 'integer', ['signed' => true]);
$table->addColumn('plugin', 'string', ['limit' => 100]);
$table->addColumn('file', 'string', ['limit' => 250, 'null' => true]);
$table->addColumn('line_start', 'integer', ['signed' => false, 'null' => true]);
$table->addColumn('line_end', 'integer', ['signed' => false, 'null' => true]);
$table->addColumn('severity', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY]);
$table->addColumn('message', 'string', ['limit' => 250]);
$table->addColumn('created_date', 'datetime');
$table->addIndex(['build_id', 'created_date'], ['unique' => false]);
$table->addForeignKey('build_id', 'build', 'id', ['delete'=> 'CASCADE', 'update' => 'CASCADE']);
$table->save();
if (!$this->hasTable('build_error')) {
$table->create();
}
if (!$table->hasColumn('build_id')) {
$table->addColumn('build_id', 'integer', ['signed' => true])->save();
}
if (!$table->hasColumn('plugin')) {
$table->addColumn('plugin', 'string', ['limit' => 100])->save();
}
if (!$table->hasColumn('file')) {
$table->addColumn('file', 'string', ['limit' => 250, 'null' => true])->save();
}
if (!$table->hasColumn('line_start')) {
$table->addColumn('line_start', 'integer', ['signed' => false, 'null' => true])->save();
}
if (!$table->hasColumn('line_end')) {
$table->addColumn('line_end', 'integer', ['signed' => false, 'null' => true])->save();
}
if (!$table->hasColumn('severity')) {
$table->addColumn('severity', 'integer', ['signed' => false, 'limit' => MysqlAdapter::INT_TINY])->save();
}
if (!$table->hasColumn('message')) {
$table->addColumn('message', 'string', ['limit' => 250])->save();
}
if (!$table->hasColumn('created_date')) {
$table->addColumn('created_date', 'datetime')->save();
}
if (!$table->hasIndex(['build_id', 'created_date'], ['unique' => false])) {
$table->addIndex(['build_id', 'created_date'], ['unique' => false])->save();
}
if (!$table->hasForeignKey('build_id')) {
$table->addForeignKey('build_id', 'build', 'id', ['delete'=> 'CASCADE', 'update' => 'CASCADE'])->save();
}
}
public function down()
{
$table = $this->table('build_error');
if ($table->hasForeignKey('build_id')) {
$table->dropForeignKey('build_id')->save();
}
if ($this->hasTable('build_error')) {
$table->drop();
}
}
}

View file

@ -16,11 +16,11 @@ class ConvertErrors extends AbstractMigration
*/
protected $errorStore;
public function change()
public function up()
{
$count = 100;
$this->metaStore = \b8\Store\Factory::getStore('BuildMeta');
$this->metaStore = \b8\Store\Factory::getStore('BuildMeta');
$this->errorStore = \b8\Store\Factory::getStore('BuildError');
while ($count == 100) {
@ -29,29 +29,27 @@ class ConvertErrors extends AbstractMigration
/** @var \PHPCI\Model\BuildMeta $meta */
foreach ($data as $meta) {
try {
switch ($meta->getMetaKey()) {
case 'phpmd-data':
$this->processPhpMdMeta($meta);
break;
switch ($meta->getMetaKey()) {
case 'phpmd-data':
$this->processPhpMdMeta($meta);
break;
case 'phpcs-data':
$this->processPhpCsMeta($meta);
break;
case 'phpcs-data':
$this->processPhpCsMeta($meta);
break;
case 'phpdoccheck-data':
$this->processPhpDocCheckMeta($meta);
break;
case 'phpdoccheck-data':
$this->processPhpDocCheckMeta($meta);
break;
case 'phpcpd-data':
$this->processPhpCpdMeta($meta);
break;
case 'phpcpd-data':
$this->processPhpCpdMeta($meta);
break;
case 'technical_debt-data':
$this->processTechnicalDebtMeta($meta);
break;
}
} catch (\Exception $ex) {}
case 'technical_debt-data':
$this->processTechnicalDebtMeta($meta);
break;
}
$this->metaStore->delete($meta);
}