1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the O2System Reactor package. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @author Steeve Andrian Salim |
9
|
|
|
* @copyright Copyright (c) Steeve Andrian Salim |
10
|
|
|
*/ |
11
|
|
|
// ------------------------------------------------------------------------ |
12
|
|
|
|
13
|
|
|
namespace O2System\Reactor\Models\Sql; |
14
|
|
|
|
15
|
|
|
// ------------------------------------------------------------------------ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Migration |
19
|
|
|
* @package O2System\Reactor\Models\Sql |
20
|
|
|
*/ |
21
|
|
|
abstract class Migration |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Migration::$group |
25
|
|
|
* |
26
|
|
|
* Database connection group. |
27
|
|
|
* |
28
|
|
|
* @var string |
29
|
|
|
*/ |
30
|
|
|
public $group = 'default'; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Migration::$db |
34
|
|
|
* |
35
|
|
|
* Database connection instance. |
36
|
|
|
* |
37
|
|
|
* @var \O2System\Database\Sql\Abstracts\AbstractConnection |
38
|
|
|
*/ |
39
|
|
|
public $db; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Migration::$qb |
43
|
|
|
* |
44
|
|
|
* Database query builder instance. |
45
|
|
|
* |
46
|
|
|
* @var \O2System\Database\Sql\Abstracts\AbstractQueryBuilder |
47
|
|
|
*/ |
48
|
|
|
public $qb; |
49
|
|
|
|
50
|
|
|
// ------------------------------------------------------------------------ |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Migration::$forge |
54
|
|
|
* |
55
|
|
|
* Database forge instance. |
56
|
|
|
* |
57
|
|
|
* @var \O2System\Database\Sql\Abstracts\AbstractForge |
58
|
|
|
*/ |
59
|
|
|
public $forge; |
60
|
|
|
|
61
|
|
|
// ------------------------------------------------------------------------ |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Migration::__construct |
65
|
|
|
*/ |
66
|
|
|
public function __construct() |
67
|
|
|
{ |
68
|
|
|
// Set database connection |
69
|
|
|
if (method_exists(database(), 'loadConnection')) { |
70
|
|
|
if ($this->db = database()->loadConnection($this->group)) { |
71
|
|
|
$this->qb = $this->db->getQueryBuilder(); |
72
|
|
|
$this->forge = $this->db->getForge(); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
// ------------------------------------------------------------------------ |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Migration::__call |
81
|
|
|
* |
82
|
|
|
* @param string $method |
83
|
|
|
* @param array $arguments |
84
|
|
|
* |
85
|
|
|
* @return mixed |
86
|
|
|
*/ |
87
|
|
|
public function __call($method, array $arguments = []) |
88
|
|
|
{ |
89
|
|
|
if (method_exists($this, $method)) { |
90
|
|
|
return call_user_func_array([&$this, $method], $arguments); |
91
|
|
|
} elseif (method_exists($this->db, $method)) { |
92
|
|
|
return call_user_func_array([&$this->db, $method], $arguments); |
93
|
|
|
} elseif (method_exists($this->forge, $method)) { |
94
|
|
|
return call_user_func_array([&$this->forge, $method], $arguments); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
//-------------------------------------------------------------------- |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Migration::up |
104
|
|
|
* |
105
|
|
|
* Perform a migration step. |
106
|
|
|
*/ |
107
|
|
|
abstract public function up(); |
108
|
|
|
|
109
|
|
|
//-------------------------------------------------------------------- |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Migration::down |
113
|
|
|
* |
114
|
|
|
* Revert a migration step. |
115
|
|
|
*/ |
116
|
|
|
abstract public function down(); |
117
|
|
|
} |