From 1b28d43b7fcf1c4ea4ba7f7cda1c41ca8b3ccf31 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Tue, 2 Dec 2014 16:41:07 +0000 Subject: [PATCH] Fixing database stuff --- .../20140730143702_fix_database_columns.php | 12 +++++ PHPCI/Model/Base/BuildBase.php | 11 +++-- PHPCI/Model/Base/BuildMetaBase.php | 10 ++-- PHPCI/Model/Base/ProjectBase.php | 47 +++++++++++++++++-- PHPCI/Model/Base/UserBase.php | 8 ++-- 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/PHPCI/Migrations/20140730143702_fix_database_columns.php b/PHPCI/Migrations/20140730143702_fix_database_columns.php index 6594dd02..809fc878 100644 --- a/PHPCI/Migrations/20140730143702_fix_database_columns.php +++ b/PHPCI/Migrations/20140730143702_fix_database_columns.php @@ -9,6 +9,13 @@ class FixDatabaseColumns extends AbstractMigration */ public function up() { + $dbAdapter = $this->getAdapter(); + + if ($dbAdapter instanceof \Phinx\Db\Adapter\PdoAdapter) { + $pdo = $dbAdapter->getConnection(); + $pdo->exec('SET foreign_key_checks = 0'); + } + $build = $this->table('build'); $build->changeColumn('project_id', 'integer', array('null' => false)); $build->changeColumn('commit_id', 'string', array('limit' => 50, 'null' => false)); @@ -45,5 +52,10 @@ class FixDatabaseColumns extends AbstractMigration $user->changeColumn('hash', 'string', array('limit' => 250, 'null' => false)); $user->changeColumn('is_admin', 'integer', array('null' => false, 'default' => 0)); $user->changeColumn('name', 'string', array('limit' => 250, 'null' => false)); + + if ($dbAdapter instanceof \Phinx\Db\Adapter\PdoAdapter) { + $pdo = $dbAdapter->getConnection(); + $pdo->exec('SET foreign_key_checks = 1'); + } } } diff --git a/PHPCI/Model/Base/BuildBase.php b/PHPCI/Model/Base/BuildBase.php index 97b427b5..119290e2 100644 --- a/PHPCI/Model/Base/BuildBase.php +++ b/PHPCI/Model/Base/BuildBase.php @@ -110,16 +110,15 @@ class BuildBase extends Model 'commit_id' => array( 'type' => 'varchar', 'length' => 50, - 'nullable' => true, 'default' => null, ), 'status' => array( - 'type' => 'tinyint', - 'length' => 4, + 'type' => 'int', + 'length' => 11, 'default' => null, ), 'log' => array( - 'type' => 'longtext', + 'type' => 'text', 'nullable' => true, 'default' => null, ), @@ -155,7 +154,7 @@ class BuildBase extends Model 'default' => null, ), 'extra' => array( - 'type' => 'longtext', + 'type' => 'text', 'nullable' => true, 'default' => null, ), @@ -382,10 +381,12 @@ class BuildBase extends Model /** * Set the value of CommitId / commit_id. * + * Must not be null. * @param $value string */ public function setCommitId($value) { + $this->_validateNotNull('CommitId', $value); $this->_validateString('CommitId', $value); if ($this->data['commit_id'] === $value) { diff --git a/PHPCI/Model/Base/BuildMetaBase.php b/PHPCI/Model/Base/BuildMetaBase.php index a979e1d9..0ac8fa93 100644 --- a/PHPCI/Model/Base/BuildMetaBase.php +++ b/PHPCI/Model/Base/BuildMetaBase.php @@ -91,17 +91,15 @@ class BuildMetaBase extends Model 'build_id' => array( 'type' => 'int', 'length' => 11, - 'nullable' => true, 'default' => null, ), 'meta_key' => array( 'type' => 'varchar', - 'length' => 255, + 'length' => 250, 'default' => null, ), 'meta_value' => array( - 'type' => 'longtext', - 'nullable' => true, + 'type' => 'text', 'default' => null, ), ); @@ -238,10 +236,12 @@ class BuildMetaBase extends Model /** * Set the value of BuildId / build_id. * + * Must not be null. * @param $value int */ public function setBuildId($value) { + $this->_validateNotNull('BuildId', $value); $this->_validateInt('BuildId', $value); if ($this->data['build_id'] === $value) { @@ -276,10 +276,12 @@ class BuildMetaBase extends Model /** * Set the value of MetaValue / meta_value. * + * Must not be null. * @param $value string */ public function setMetaValue($value) { + $this->_validateNotNull('MetaValue', $value); $this->_validateString('MetaValue', $value); if ($this->data['meta_value'] === $value) { diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index 0161243c..305cafbf 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -36,6 +36,7 @@ class ProjectBase extends Model 'id' => null, 'title' => null, 'reference' => null, + 'branch' => null, 'ssh_private_key' => null, 'type' => null, 'access_information' => null, @@ -53,6 +54,7 @@ class ProjectBase extends Model 'id' => 'getId', 'title' => 'getTitle', 'reference' => 'getReference', + 'branch' => 'getBranch', 'ssh_private_key' => 'getSshPrivateKey', 'type' => 'getType', 'access_information' => 'getAccessInformation', @@ -72,6 +74,7 @@ class ProjectBase extends Model 'id' => 'setId', 'title' => 'setTitle', 'reference' => 'setReference', + 'branch' => 'setBranch', 'ssh_private_key' => 'setSshPrivateKey', 'type' => 'setType', 'access_information' => 'setAccessInformation', @@ -104,6 +107,11 @@ class ProjectBase extends Model 'length' => 250, 'default' => null, ), + 'branch' => array( + 'type' => 'varchar', + 'length' => 50, + 'default' => 'master', + ), 'ssh_private_key' => array( 'type' => 'text', 'nullable' => true, @@ -112,7 +120,7 @@ class ProjectBase extends Model 'type' => array( 'type' => 'varchar', 'length' => 50, - 'default' => 1, + 'default' => null, ), 'access_information' => array( 'type' => 'varchar', @@ -137,9 +145,8 @@ class ProjectBase extends Model 'default' => null, ), 'allow_public_status' => array( - 'type' => 'tinyint', - 'length' => 4, - 'default' => null, + 'type' => 'int', + 'length' => 11, ), ); @@ -193,6 +200,18 @@ class ProjectBase extends Model return $rtn; } + /** + * Get the value of Branch / branch. + * + * @return string + */ + public function getBranch() + { + $rtn = $this->data['branch']; + + return $rtn; + } + /** * Get the value of SshPrivateKey / ssh_private_key. * @@ -337,6 +356,26 @@ class ProjectBase extends Model $this->_setModified('reference'); } + /** + * Set the value of Branch / branch. + * + * Must not be null. + * @param $value string + */ + public function setBranch($value) + { + $this->_validateNotNull('Branch', $value); + $this->_validateString('Branch', $value); + + if ($this->data['branch'] === $value) { + return; + } + + $this->data['branch'] = $value; + + $this->_setModified('branch'); + } + /** * Set the value of SshPrivateKey / ssh_private_key. * diff --git a/PHPCI/Model/Base/UserBase.php b/PHPCI/Model/Base/UserBase.php index 514a0db9..e9be15a0 100644 --- a/PHPCI/Model/Base/UserBase.php +++ b/PHPCI/Model/Base/UserBase.php @@ -90,14 +90,12 @@ class UserBase extends Model 'default' => null, ), 'is_admin' => array( - 'type' => 'tinyint', - 'length' => 1, - 'default' => null, + 'type' => 'int', + 'length' => 11, ), 'name' => array( 'type' => 'varchar', 'length' => 250, - 'nullable' => true, 'default' => null, ), ); @@ -259,10 +257,12 @@ class UserBase extends Model /** * Set the value of Name / name. * + * Must not be null. * @param $value string */ public function setName($value) { + $this->_validateNotNull('Name', $value); $this->_validateString('Name', $value); if ($this->data['name'] === $value) {