1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Quantum PHP Framework |
5
|
|
|
* |
6
|
|
|
* An open source software development framework for PHP |
7
|
|
|
* |
8
|
|
|
* @package Quantum |
9
|
|
|
* @author Arman Ag. <[email protected]> |
10
|
|
|
* @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) |
11
|
|
|
* @link http://quantum.softberg.org/ |
12
|
|
|
* @since 2.9.5 |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Quantum\Migration\Templates; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class MigrationTable |
19
|
|
|
* @package Quantum\Migration |
20
|
|
|
*/ |
21
|
|
|
class MigrationTemplate |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Create migration template |
26
|
|
|
* @param string $className |
27
|
|
|
* @param string $tableName |
28
|
|
|
* @return string |
29
|
|
|
*/ |
30
|
|
|
public static function create(string $className, string $tableName): string |
31
|
|
|
{ |
32
|
|
|
return '<?php |
33
|
|
|
|
34
|
|
|
use Quantum\Libraries\Database\Factories\TableFactory; |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
class ' . ucfirst($className) . ' extends QtMigration |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
public function up(?TableFactory $tableFactory) { |
41
|
|
|
$table = $tableFactory->create(\'' . $tableName . '\'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function down(?TableFactory $tableFactory) |
45
|
|
|
{ |
46
|
|
|
$tableFactory->drop(\'' . $tableName . '\'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
'; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Alter migration template |
56
|
|
|
* @param string $className |
57
|
|
|
* @param string $tableName |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public static function alter(string $className, string $tableName): string |
61
|
|
|
{ |
62
|
|
|
return '<?php |
63
|
|
|
|
64
|
|
|
use Quantum\Libraries\Database\Factories\TableFactory; |
65
|
|
|
|
66
|
|
|
class ' . ucfirst($className) . ' extends QtMigration |
67
|
|
|
{ |
68
|
|
|
|
69
|
|
|
public function up(?TableFactory $tableFactory) { |
70
|
|
|
$table = $tableFactory->get(\'' . $tableName . '\'); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function down(?TableFactory $tableFactory) |
74
|
|
|
{ |
75
|
|
|
$table = $tableFactory->get(\'' . $tableName . '\'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Rename migration template |
85
|
|
|
* @param string $className |
86
|
|
|
* @param string $tableName |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public static function rename(string $className, string $tableName): string |
90
|
|
|
{ |
91
|
|
|
return '<?php |
92
|
|
|
|
93
|
|
|
use Quantum\Libraries\Database\Factories\TableFactory; |
94
|
|
|
|
95
|
|
|
class ' . ucfirst($className) . ' extends QtMigration |
96
|
|
|
{ |
97
|
|
|
|
98
|
|
|
public function up(?TableFactory $tableFactory) { |
99
|
|
|
$tableFactory->rename(\'' . $tableName . '\', $newName); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function down(?TableFactory $tableFactory) |
103
|
|
|
{ |
104
|
|
|
$tableFactory->rename($newName, \'' . $tableName . '\'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
'; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Drop migration template |
114
|
|
|
* @param string $className |
115
|
|
|
* @param string $tableName |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public static function drop(string $className, string $tableName): string |
119
|
|
|
{ |
120
|
|
|
return '<?php |
121
|
|
|
|
122
|
|
|
use Quantum\Libraries\Database\Factories\TableFactory; |
123
|
|
|
|
124
|
|
|
class ' . ucfirst($className) . ' extends QtMigration |
125
|
|
|
{ |
126
|
|
|
|
127
|
|
|
public function up(?TableFactory $tableFactory) { |
128
|
|
|
$tableFactory->drop(\'' . $tableName . '\'); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
public function down(?TableFactory $tableFactory) |
132
|
|
|
{ |
133
|
|
|
// |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
'; |
139
|
|
|
} |
140
|
|
|
} |