m130915_101849_add_setting_pk_for_mysql::up()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 21
rs 10
1
<?php
2
3
class m130915_101849_add_setting_pk_for_mysql extends CDbMigration
4
{
5
6
	public function up()
7
	{
8
		// Bail out if we are not configured for MySQL
9
		if (strpos(Yii::app()->db->connectionString, 'sqlite') === 0)
10
		{
11
			echo "Not configured to use MySQL, skipping this migration ...\n";
12
			return true;
13
		}
14
15
		// Try to drop any previous defined primary key (in case someone fixed 
16
		// this on their own)
17
		try
18
		{
19
			$this->dropPrimaryKey('name', 'settings');
20
		}
21
		catch (CDbException $e)
22
		{
23
			// ignore the exception, it means the primary key doesn't exist
24
		}
25
26
		$this->addPrimaryKey('PRIMARY', 'settings', 'name');
27
	}
28
29
	public function down()
30
	{
31
		echo "m130915_101849_add_setting_pk_for_mysql does not support migration down.\n";
32
		return false;
33
	}
34
35
}