Skip to content

Commit

Permalink
Dev Fixed several installer issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Oct 2, 2015
1 parent 672d5b2 commit 6177aca
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 15 deletions.
1 change: 1 addition & 0 deletions protected/components/MigrationManager.php
@@ -1,6 +1,7 @@
<?php
namespace ls\components;

use \CHtml;
/**
* Application component that manages Yii migrations.
* Most of the protected functions have been copies from CMigrateCommand,
Expand Down
2 changes: 1 addition & 1 deletion protected/core/db/DbConnection.php
Expand Up @@ -26,7 +26,7 @@ public function executeFile($fileName, $prefix)
throw new \Exception("SQL file is not readable.");
}
$sql = strtr(file_get_contents($fileName), ['prefix_' => $prefix]);
$this->createCommand($sql)->execute();
$this->pdoInstance->exec($sql);
return true;
}
}
2 changes: 1 addition & 1 deletion protected/core/db/SmartColumnTypeTrait.php
Expand Up @@ -11,7 +11,7 @@ trait SmartColumnTypeTrait
* @param string $type
*/
protected function splitColumnType($type) {
$regex = '/^([a-zA-Z]+ ?)\s*(\(.+\))?\s*(.*)$/';
$regex = '/^([a-zA-Z ]+)\s*(\(.+\))?\s*(.*)$/';
if (preg_match($regex, $type, $matches)) {
return [
'base' => trim($matches[1]),
Expand Down
Expand Up @@ -10,7 +10,7 @@ class m150322_132458_add_series_to_survey extends CDbMigration
*/
public function safeUp()
{
$this->addColumn('{{surveys}}', 'use_series', 'boolean DEFAULT 0 NOT NULL');
$this->addColumn('{{surveys}}', 'use_series', 'boolean DEFAULT FALSE NOT NULL');
}

/**
Expand Down
Expand Up @@ -13,7 +13,7 @@ public function safeUp()
{
// We are removing languages from the answer table and moving it to the translation table.
$table = \ls\models\Answer::model()->tableName();
$this->dropPrimaryKey('', $table);
$this->dropPrimaryKey($table . '_pkey', $table);
$this->addColumn(\ls\models\Answer::model()->tableName(), 'id', 'pk');
$this->renameColumn($table, 'qid', 'question_id');
$this->dbConnection->schema->getTable($table, true);
Expand Down
Expand Up @@ -12,7 +12,7 @@ public function safeUp()
{
// We are removing languages from the answer table and moving it to the translation table.
$table = \ls\models\QuestionGroup::model()->tableName();
// $this->renameColumn($table, 'gid', 'id');

$this->dbConnection->schema->getTable($table, true);
$groups = \ls\models\QuestionGroup::model()->findAll();
$deleted = $created = 0;
Expand Down
Expand Up @@ -12,21 +12,30 @@ public function safeUp()
{
$table = \ls\models\ParticipantAttributeName::model()->tableName();
$this->renameColumn($table, 'attribute_type', 'type');
$this->renameColumn($table, 'attribute_id', 'id');
$this->renameColumn($table, 'defaultname', 'name');
$this->renameColumn($table, 'visible', 'visible_old');
$this->addColumn($table, 'visible', 'bool');

$this->update($table, [
'visible' => 0
], 'visible_old = "FALSE"');
], 'visible_old = :false', [
':false' => 'FALSE'
]);
$this->update($table, [
'visible' => 1
], 'visible_old = "TRUE"');
], 'visible_old = :true', [
':true' => 'TRUE'
]);
$this->dropColumn($table, 'visible_old');
$this->alterColumn($table, 'id', 'int');
$this->dropPrimaryKey('', $table);
$this->alterColumn($table, 'id', 'pk');
// Remove auto increment from column.
$this->alterColumn($table, 'attribute_id', 'int');
$this->dropPrimaryKey($table . '_pkey', $table);
$this->addColumn($table, 'id', 'pk');
$this->update($table, [
'id' => new \CDbExpression('attribute_id')
]);
$this->dropColumn($table, 'attribute_id');

return true;
}

Expand Down
Expand Up @@ -10,11 +10,15 @@ class m150706_092139_unique_question_codes_per_scale extends CDbMigration
*/
public function safeUp()
{
$this->dropIndex('unique_question_codes', '{{questions}}');
$this->createIndex('unique_question_codes', '{{questions}}', ['sid', 'title', 'parent_qid', 'scale_id'], true);
return true;
try {
$this->dropForeignKey('unique_question_codes', '{{questions}}');
} catch (\Exception $e) {
$this->dropIndex('unique_question_codes', '{{questions}}');
}
$this->createIndex('unique_question_codes', '{{questions}}', ['sid', 'title', 'parent_qid', 'scale_id'], true);
return true;
}

/**
* @return boolean True if migration was a success.
*/
Expand Down
1 change: 1 addition & 0 deletions protected/tests/unit/DbSchemasTestCase.php
Expand Up @@ -50,6 +50,7 @@ public function testPgSql()
{
$schema = new \PgsqlSchema($this->db);
$this->assertEquals('numeric (10,0)', $schema->getColumnType('decimal'));
$this->assertEquals('character varying(10) NOT NULL', $schema->getColumnType('string(10) NOT NULL'));
$this->doForClass(\PgsqlSchema::class);
}

Expand Down

0 comments on commit 6177aca

Please sign in to comment.