jenkins-bot has submitted this change and it was merged.

Change subject: Remove index field from FieldDefinition
......................................................................


Remove index field from FieldDefinition

Change-Id: I5d565291e5a85ba75de862ffe1866ee73f2ec760
---
M src/FieldDefinition.php
M src/MySQL/MySqlTableSqlBuilder.php
M src/SQLite/SQLiteTableSqlBuilder.php
M tests/phpunit/FieldDefinitionTest.php
M tests/phpunit/MySQL/MySQLTableSqlBuilderTest.php
M tests/phpunit/SQLite/SQLiteTableSqlBuilderTest.php
6 files changed, 19 insertions(+), 106 deletions(-)

Approvals:
  Denny Vrandecic: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/src/FieldDefinition.php b/src/FieldDefinition.php
index 133830d..c903d59 100644
--- a/src/FieldDefinition.php
+++ b/src/FieldDefinition.php
@@ -55,13 +55,6 @@
        /**
         * @since 0.1
         *
-        * @var string|null
-        */
-       private $index;
-
-       /**
-        * @since 0.1
-        *
         * @var boolean
         */
        private $autoIncrement;
@@ -80,15 +73,8 @@
        const ATTRIB_BINARY = 'binary';
        const ATTRIB_UNSIGNED = 'unsigned';
 
-       const NO_INDEX = null;
-       const INDEX = 'index';
-       const INDEX_UNIQUE = 'unique';
-       const INDEX_FULLTEXT = 'fulltext';
-       const INDEX_PRIMARY = 'primary';
-
        const AUTOINCREMENT = true;
        const NO_AUTOINCREMENT = false;
-
 
        /**
         * @since 0.1
@@ -98,12 +84,11 @@
         * @param boolean $null
         * @param mixed $default
         * @param string|null $attributes
-        * @param string|null $index
         * @param boolean $autoIncrement
         *
-        * @throws InvalidArgumentException
+        * @throws \InvalidArgumentException
         */
-       public function __construct( $name, $type, $null = self::NULL, $default 
= self::NO_DEFAULT, $attributes = null, $index = null, $autoIncrement = false ) 
{
+       public function __construct( $name, $type, $null = self::NULL, $default 
= self::NO_DEFAULT, $attributes = null, $autoIncrement = false ) {
                if ( !is_string( $name ) ) {
                        throw new InvalidArgumentException( 'The field $name 
needs to be a string' );
                }
@@ -116,10 +101,6 @@
                        throw new InvalidArgumentException( 'The $null 
parameter needs to be a boolean' );
                }
 
-               if ( !is_null( $index ) && !is_string( $index ) ) {
-                       throw new InvalidArgumentException( 'The $index 
parameter needs to be a string' );
-               }
-
                if ( !is_bool( $autoIncrement ) ) {
                        throw new InvalidArgumentException( 'The $autoIncrement 
parameter needs to be a boolean' );
                }
@@ -129,7 +110,6 @@
                $this->default = $default;
                $this->attributes = $attributes;
                $this->null = $null;
-               $this->index = $index;
                $this->autoIncrement = $autoIncrement;
        }
 
@@ -191,17 +171,6 @@
                return $this->null;
        }
 
-       /**
-        * Returns the index type of the field.
-        * This is one of the INDEX_ constants or null.
-        *
-        * @since 0.1
-        *
-        * @return string|null
-        */
-       public function getIndex() {
-               return $this->index;
-       }
 
        /**
         * Returns if the field has auto increment.
diff --git a/src/MySQL/MySqlTableSqlBuilder.php 
b/src/MySQL/MySqlTableSqlBuilder.php
index 7848359..1008a00 100644
--- a/src/MySQL/MySqlTableSqlBuilder.php
+++ b/src/MySQL/MySqlTableSqlBuilder.php
@@ -61,6 +61,8 @@
                // TODO: table options
                $sql .= ') ' . 'ENGINE=InnoDB, DEFAULT CHARSET=binary';
 
+               // TODO: indexes
+
                return $sql;
        }
 
@@ -78,8 +80,6 @@
                $sql .= $this->getDefault( $field->getDefault() );
 
                $sql .= $this->getNull( $field->allowsNull() );
-
-               $sql .= $this->getIndexString( $field->getIndex() );
 
                // TODO: add all field stuff relevant here
 
@@ -119,17 +119,6 @@
                        default:
                                throw new RuntimeException( __CLASS__ . ' does 
not support db fields of type ' . $fieldType );
                }
-       }
-
-       protected function getIndexString( $indexType ) {
-               switch ( $indexType ) {
-                       case FieldDefinition::INDEX_PRIMARY:
-                               return ' PRIMARY KEY AUTO_INCREMENT';
-               }
-
-               // TODO: handle other index types
-
-               return '';
        }
 
 }
diff --git a/src/SQLite/SQLiteTableSqlBuilder.php 
b/src/SQLite/SQLiteTableSqlBuilder.php
index 4eab5b7..3519a80 100644
--- a/src/SQLite/SQLiteTableSqlBuilder.php
+++ b/src/SQLite/SQLiteTableSqlBuilder.php
@@ -58,6 +58,8 @@
                // TODO: table options
                $sql .= ');';
 
+               // TODO: indexes
+
                return $sql;
        }
 
@@ -75,8 +77,6 @@
                $sql .= $this->getDefault( $field->getDefault() );
 
                $sql .= $this->getNull( $field->allowsNull() );
-
-               $sql .= $this->getIndexString( $field->getIndex() );
 
                return $sql;
        }
@@ -114,17 +114,6 @@
                        default:
                                throw new RuntimeException( __CLASS__ . ' does 
not support db fields of type ' . $fieldType );
                }
-       }
-
-       protected function getIndexString( $indexType ) {
-               switch ( $indexType ) {
-                       case FieldDefinition::INDEX_PRIMARY:
-                               return ' INTEGER PRIMARY KEY';
-               }
-
-               // TODO: handle other index types
-
-               return '';
        }
 
 }
diff --git a/tests/phpunit/FieldDefinitionTest.php 
b/tests/phpunit/FieldDefinitionTest.php
index 2c1fb5a..411c099 100644
--- a/tests/phpunit/FieldDefinitionTest.php
+++ b/tests/phpunit/FieldDefinitionTest.php
@@ -24,39 +24,23 @@
                $instances = array();
 
                $instances[] = new FieldDefinition(
-                       'names',
-                       FieldDefinition::TYPE_TEXT
+                       'names', FieldDefinition::TYPE_TEXT
                );
 
                $instances[] = new FieldDefinition(
-                       'numbers',
-                       FieldDefinition::TYPE_FLOAT
+                       'numbers', FieldDefinition::TYPE_FLOAT
                );
 
                $instances[] = new FieldDefinition(
-                       'stuffs',
-                       FieldDefinition::TYPE_INTEGER,
-                       false,
-                       42,
-                       FieldDefinition::ATTRIB_UNSIGNED
+                       'stuffs', FieldDefinition::TYPE_INTEGER, false, 42, 
FieldDefinition::ATTRIB_UNSIGNED
                );
 
                $instances[] = new FieldDefinition(
-                       'stuffs',
-                       FieldDefinition::TYPE_INTEGER,
-                       true,
-                       null,
-                       null
+                       'stuffs', FieldDefinition::TYPE_INTEGER, true, null, 
null
                );
 
                $instances[] = new FieldDefinition(
-                       'stuffs',
-                       FieldDefinition::TYPE_INTEGER,
-                       true,
-                       null,
-                       null,
-                       null,
-                       true
+                       'stuffs', FieldDefinition::TYPE_INTEGER, true, null, 
null, true
                );
 
                $argLists = array();
diff --git a/tests/phpunit/MySQL/MySQLTableSqlBuilderTest.php 
b/tests/phpunit/MySQL/MySQLTableSqlBuilderTest.php
index aa6e086..88adff4 100644
--- a/tests/phpunit/MySQL/MySQLTableSqlBuilderTest.php
+++ b/tests/phpunit/MySQL/MySQLTableSqlBuilderTest.php
@@ -68,26 +68,17 @@
                                'tableName',
                                array(
                                        new FieldDefinition(
-                                               'primaryField',
-                                               FieldDefinition::TYPE_INTEGER,
-                                               FieldDefinition::NOT_NULL,
-                                               FieldDefinition::NO_DEFAULT,
-                                               FieldDefinition::NO_ATTRIB,
-                                               FieldDefinition::INDEX_PRIMARY
+                                               'primaryField', 
FieldDefinition::TYPE_INTEGER, FieldDefinition::NOT_NULL, 
FieldDefinition::NO_DEFAULT, FieldDefinition::NO_ATTRIB
                                        ),
                                        new FieldDefinition(
-                                               'textField',
-                                               FieldDefinition::TYPE_TEXT
+                                               'textField', 
FieldDefinition::TYPE_TEXT
                                        ),
                                        new FieldDefinition(
-                                               'intField',
-                                               FieldDefinition::TYPE_INTEGER,
-                                               FieldDefinition::NOT_NULL,
-                                               42
+                                               'intField', 
FieldDefinition::TYPE_INTEGER, FieldDefinition::NOT_NULL, 42
                                        ),
                                )
                        ),
-                       'CREATE TABLE `dbName`.prefix_tableName (primaryField 
INT NOT NULL PRIMARY KEY AUTO_INCREMENT, textField BLOB NULL, intField INT 
DEFAULT  NOT NULL) ENGINE=InnoDB, DEFAULT CHARSET=binary'
+                       'CREATE TABLE `dbName`.prefix_tableName (primaryField 
INT NOT NULL, textField BLOB NULL, intField INT DEFAULT  NOT NULL) 
ENGINE=InnoDB, DEFAULT CHARSET=binary'
                );
 
                return $argLists;
diff --git a/tests/phpunit/SQLite/SQLiteTableSqlBuilderTest.php 
b/tests/phpunit/SQLite/SQLiteTableSqlBuilderTest.php
index 6ac2050..90242be 100644
--- a/tests/phpunit/SQLite/SQLiteTableSqlBuilderTest.php
+++ b/tests/phpunit/SQLite/SQLiteTableSqlBuilderTest.php
@@ -67,26 +67,17 @@
                                'tableName',
                                array(
                                        new FieldDefinition(
-                                               'primaryField',
-                                               FieldDefinition::TYPE_INTEGER,
-                                               FieldDefinition::NOT_NULL,
-                                               FieldDefinition::NO_DEFAULT,
-                                               FieldDefinition::NO_ATTRIB,
-                                               FieldDefinition::INDEX_PRIMARY
+                                               'primaryField', 
FieldDefinition::TYPE_INTEGER, FieldDefinition::NOT_NULL, 
FieldDefinition::NO_DEFAULT, FieldDefinition::NO_ATTRIB
                                        ),
                                        new FieldDefinition(
-                                               'textField',
-                                               FieldDefinition::TYPE_TEXT
+                                               'textField', 
FieldDefinition::TYPE_TEXT
                                        ),
                                        new FieldDefinition(
-                                               'intField',
-                                               FieldDefinition::TYPE_INTEGER,
-                                               FieldDefinition::NOT_NULL,
-                                               42
+                                               'intField', 
FieldDefinition::TYPE_INTEGER, FieldDefinition::NOT_NULL, 42
                                        ),
                                )
                        ),
-                       'CREATE TABLE dbNametableName (primaryField INT NOT 
NULL INTEGER PRIMARY KEY, textField BLOB NULL, intField INT DEFAULT  NOT NULL);'
+                       'CREATE TABLE dbNametableName (primaryField INT NOT 
NULL, textField BLOB NULL, intField INT DEFAULT  NOT NULL);'
                );
 
                return $argLists;

-- 
To view, visit https://gerrit.wikimedia.org/r/76718
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5d565291e5a85ba75de862ffe1866ee73f2ec760
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseDatabase
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <jeroended...@gmail.com>
Gerrit-Reviewer: Denny Vrandecic <denny.vrande...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to