ViewCreationMigration::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
class ViewCreationMigration extends AbstractMigration
6
{
7
	/**
8
	 * Change Method.
9
	 *
10
	 * More information on this method is available here:
11
	 * http://docs.phinx.org/en/latest/migrations.html#the-change-method
12
	 *
13
	 * Uncomment this method if you would like to use it.
14
	 *
15
	public function change()
16
	{
17
	}
18
	*/
19
	
20
	/**
21
	 * Migrate Up.
22
	 */
23
	public function up()
24
	{
25
		if ( ! $this->hasTable('todo_task_view'))
26
		{
27
			$this->execute("CREATE VIEW todo_task_view AS
28
				SELECT todo_item.id, todo_item.user_id, todo_item.category_id, todo_item.title, todo_item.due, todo_item.modified, todo_item.created, todo_category.title AS category, todo_priority.value AS priority, todo_status.value AS status, todo_status.id AS status_id FROM (((todo_item LEFT JOIN todo_category ON ((todo_category.id = todo_item.category_id))) LEFT JOIN todo_priority ON ((todo_priority.id = todo_item.priority))) LEFT JOIN todo_status ON ((todo_status.id = todo_item.status))) ORDER BY todo_item.due, todo_item.priority DESC, todo_item.created;
29
				");
30
		}
31
	}
32
33
	/**
34
	 * Migrate Down.
35
	 */
36
	public function down()
37
	{
38
		$this->execute('DROP VIEW todo_task_view');
39
	}
40
}