diff --git a/extensions/sphinx/Schema.php b/extensions/sphinx/Schema.php index 5afb445..557becd 100644 --- a/extensions/sphinx/Schema.php +++ b/extensions/sphinx/Schema.php @@ -86,9 +86,6 @@ class Schema extends \yii\db\mysql\Schema $table->columns[$column->name] = $column; if ($column->isPrimaryKey) { $table->primaryKey[] = $column->name; - if ($column->autoIncrement) { - $table->sequenceName = ''; - } } } return true; @@ -104,9 +101,9 @@ class Schema extends \yii\db\mysql\Schema $column = new ColumnSchema; $column->name = $info['Field']; + $column->isPrimaryKey = ($column->name == 'id'); // Not supported : //$column->allowNull = $info['Null'] === 'YES'; - //$column->isPrimaryKey = strpos($info['Key'], 'PRI') !== false; //$column->autoIncrement = stripos($info['Extra'], 'auto_increment') !== false; //$column->comment = $info['Comment']; diff --git a/tests/unit/data/sphinx/sphinx.conf b/tests/unit/data/sphinx/sphinx.conf index fb28525..e58166c 100644 --- a/tests/unit/data/sphinx/sphinx.conf +++ b/tests/unit/data/sphinx/sphinx.conf @@ -1,6 +1,13 @@ +# Sphinx configuration for the unit tests # -# Minimal Sphinx configuration sample (clean, simple, functional) -# +# Setup test environment: +# - initialize test database source: +# mysql -D yii2test -u test < /path/to/yii/tests/unit/data/sphinx/sphinx.sql +# - setup test Sphinx indexes: +# indexer --config /path/to/yii/tests/unit/data/sphinx/sphinx.conf --all [--rotate] +# - run the "searchd" daemon: +# searchd --config /path/to/yii/tests/unit/data/sphinx/sphinx.conf + source yii2_test_article_src { @@ -19,6 +26,7 @@ source yii2_test_article_src sql_attr_uint = id sql_attr_uint = author_id sql_attr_timestamp = add_date + sql_attr_multi = uint tag from query; SELECT article_id AS id, tag_id AS tag FROM yii2_test_article_tag sql_query_info = SELECT * FROM yii2_test_article WHERE id=$id } diff --git a/tests/unit/data/sphinx/sphinx.sql b/tests/unit/data/sphinx/sphinx.sql index b6a2ef7..1cdd5ae 100644 --- a/tests/unit/data/sphinx/sphinx.sql +++ b/tests/unit/data/sphinx/sphinx.sql @@ -26,3 +26,16 @@ CREATE TABLE IF NOT EXISTS `yii2_test_item` ( INSERT INTO `yii2_test_item` (`id`, `name`, `description`, `category_id`, `price`) VALUES (1, 'pencil', 'Simple pencil', 1, 2.5), (2, 'table', 'Wooden table', 2, 100); + +CREATE TABLE IF NOT EXISTS `yii2_test_article_tag` ( + `article_id` int(11) NOT NULL, + `tag_id` int(11) NOT NULL, + PRIMARY KEY (`article_id`,`tag_id`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8; + +INSERT INTO `yii2_test_article_tag` (`article_id`, `tag_id`) VALUES +(1, 1), +(1, 2), +(1, 3), +(2, 3), +(2, 4); \ No newline at end of file