/** * Tests some config functions. */ public function testConfigFunctions() { // Create new schema $index = new IndexColumn(); // Check return types $this->assertTrue(is_array($index->attributeLabels())); $this->assertTrue(is_array($index->rules())); $this->assertTrue(is_array($index->relations())); $this->assertTrue(is_array($index->primaryKey())); }
/** * Shows the table structure */ public function actionStructure() { $table = $this->loadTable(); if (!$table instanceof Table) { $response = new AjaxResponse(); $response->addNotification("error", Yii::t("core", "tableLoadErrorTitle", array("{table}" => $this->table)), Yii::t("core", "tableLoadErrorMessage", array("{table}" => $this->table))); $response->executeJavaScript("sideBar.loadTables(schema)"); $this->sendJSON($response); } // Constraints if (StorageEngine::check($table->ENGINE, StorageEngine::SUPPORTS_FOREIGN_KEYS)) { $foreignKeys = array(); $sql = 'SELECT * FROM KEY_COLUMN_USAGE ' . 'WHERE TABLE_SCHEMA = :tableSchema ' . 'AND TABLE_NAME = :tableName ' . 'AND REFERENCED_TABLE_SCHEMA IS NOT NULL'; $table->foreignKeys = ForeignKey::model()->findAllBySql($sql, array('tableSchema' => $table->TABLE_SCHEMA, 'tableName' => $table->TABLE_NAME)); foreach ($table->foreignKeys as $key) { $foreignKeys[] = $key->COLUMN_NAME; } } else { $foreignKeys = false; } // Indices $sql = 'SELECT * FROM STATISTICS ' . 'WHERE TABLE_SCHEMA = :tableSchema ' . 'AND TABLE_NAME = :tableName ' . 'GROUP BY INDEX_NAME ' . 'ORDER BY INDEX_NAME = \'PRIMARY\' DESC, INDEX_NAME'; $table->indices = Index::model()->findAllBySql($sql, array('tableSchema' => $table->TABLE_SCHEMA, 'tableName' => $table->TABLE_NAME)); foreach ($table->indices as $index) { $index->columns = IndexColumn::model()->findAllByAttributes(array('TABLE_SCHEMA' => $table->TABLE_SCHEMA, 'TABLE_NAME' => $table->TABLE_NAME, 'INDEX_NAME' => $index->INDEX_NAME)); } // Indices (seperate for each column) $indicesRaw = Index::model()->findAllByAttributes(array('TABLE_SCHEMA' => $table->TABLE_SCHEMA, 'TABLE_NAME' => $table->TABLE_NAME)); // Triggers $table->triggers = Trigger::model()->findAllByAttributes(array('EVENT_OBJECT_SCHEMA' => $table->TABLE_SCHEMA, 'EVENT_OBJECT_TABLE' => $table->TABLE_NAME)); $this->render('structure', array('table' => $table, 'canAlter' => Yii::app()->user->privileges->checkTable($table->TABLE_SCHEMA, $table->TABLE_NAME, 'ALTER'), 'foreignKeys' => $foreignKeys, 'indicesRaw' => $indicesRaw)); }
/** * Tests to add an Index to a Column with Type Fulltext */ public function testSetTypeFullText() { // Create index $index = new Index(); $index->TABLE_NAME = 'table2'; $index->TABLE_SCHEMA = 'indextest'; $index->INDEX_NAME = 'newname'; $index->setType('FULLTEXT'); // Add new column $columns = $index->columns; $col = new IndexColumn(); $col->COLUMN_NAME = 'pk'; $columns[] = $col; $col = new IndexColumn(); $col->COLUMN_NAME = 'varchar'; $col->SUB_PART = 10; $columns[] = $col; $index->columns = $columns; // Try saving $index->save(); // Reload index and load index columns $index->refresh(); $cols = IndexColumn::model()->findAllByAttributes(array('TABLE_SCHEMA' => $index->TABLE_SCHEMA, 'TABLE_NAME' => $index->TABLE_NAME, 'INDEX_NAME' => $index->INDEX_NAME)); // Check properties $this->assertEquals('newname', $index->INDEX_NAME); $this->assertEquals('FULLTEXT', $index->getType()); }