1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Potatobase (https://github.com/PotatoPowered/potatobase) |
4
|
|
|
* |
5
|
|
|
* Licensed under The MIT License |
6
|
|
|
* For full copyright and license information, please see the LICENSE |
7
|
|
|
* Redistributions of files must retain the above copyright notice. |
8
|
|
|
* |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
10
|
|
|
* @copyright Copyright (c) Potato Powered Software |
11
|
|
|
* @link http://potatopowered.net |
12
|
|
|
* @author Blake Sutton <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
namespace Potatobase\DB; |
15
|
|
|
|
16
|
|
|
use Phinx\Db\Table as BaseTable; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Table |
20
|
|
|
* |
21
|
|
|
* This class is an extension to the default migration tools Table object. The goal of this object is to extend the base |
22
|
|
|
* table so that we can provide some default column builders and other tools. |
23
|
|
|
* |
24
|
|
|
* @package Potatobase\DB |
25
|
|
|
*/ |
26
|
|
|
class Table extends BaseTable |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Add a Created Timestamp Column |
30
|
|
|
* |
31
|
|
|
* This function is a simple accessor to allow a universal design for the created timestamp. |
32
|
|
|
* |
33
|
|
|
* @return BaseTable The table object with a created column added. |
34
|
|
|
*/ |
35
|
|
View Code Duplication |
public function addCreated() |
|
|
|
|
36
|
|
|
{ |
37
|
|
|
return $this->addColumn( |
38
|
|
|
'created', |
39
|
|
|
'datetime', |
40
|
|
|
[ |
41
|
|
|
'default' => null, |
42
|
|
|
'limit' => null, |
43
|
|
|
'null' => true, |
44
|
|
|
] |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Add a Modified Timestamp Column |
50
|
|
|
* |
51
|
|
|
* This function is a simple accessor to allow a universal design for the modified timestamp. |
52
|
|
|
* |
53
|
|
|
* @return BaseTable The table object with a modified column added. |
54
|
|
|
*/ |
55
|
|
View Code Duplication |
public function addModified() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
return $this->addColumn( |
58
|
|
|
'modified', |
59
|
|
|
'datetime', |
60
|
|
|
[ |
61
|
|
|
'default' => null, |
62
|
|
|
'limit' => null, |
63
|
|
|
'null' => true, |
64
|
|
|
] |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Add a varchar column to the table |
70
|
|
|
* |
71
|
|
|
* This function will be used to add a different styles of varchar type columns to the table. It can be called |
72
|
|
|
* directly but it is recommended to use the specific column creation methods. |
73
|
|
|
* |
74
|
|
|
* @param string $name Name of the column to add |
75
|
|
|
* @param int $size Character limit of the new column |
76
|
|
|
* @param bool $nullable Is the field be nullable |
77
|
|
|
* @param string $default The default value for the field |
78
|
|
|
* @return BaseTable The table object with the varchar column added. |
79
|
|
|
*/ |
80
|
|
|
public function addVarChar($name, $size, $nullable = false, $default = null) |
81
|
|
|
{ |
82
|
|
|
return $this->addColumn( |
83
|
|
|
$name, |
84
|
|
|
'string', |
85
|
|
|
[ |
86
|
|
|
'default' => $default, |
87
|
|
|
'limit' => $size, |
88
|
|
|
'null' => $nullable |
89
|
|
|
] |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Add a tiny varchar column to the table |
95
|
|
|
* |
96
|
|
|
* This function adds a 25 character length varchar column to the table. |
97
|
|
|
* + **Type:** varchar |
98
|
|
|
* + **Size:** 25 |
99
|
|
|
* + **Nullable:** false |
100
|
|
|
* + **Default:** null |
101
|
|
|
* |
102
|
|
|
* @param string $name Name of the column to add |
103
|
|
|
* @param bool $nullable Is the field be nullable |
104
|
|
|
* @param string $default The default value for the field |
105
|
|
|
* @return BaseTable The table object with a 25 character varchar column added |
106
|
|
|
*/ |
107
|
|
|
public function addTinyText($name, $nullable = false, $default = null) |
108
|
|
|
{ |
109
|
|
|
return $this->addVarChar($name, 25, $nullable, $default); |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.