1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Milkmeowo\Framework\Database\Schema; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Schema\Blueprint as BaseBlueprint; |
6
|
|
|
|
7
|
|
|
class Blueprint extends BaseBlueprint |
8
|
|
|
{ |
9
|
|
|
public function recordStamps() |
10
|
|
|
{ |
11
|
|
|
$this->timestamps(); |
12
|
|
|
$this->ipStamps(); |
13
|
|
|
$this->userStamps(); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function ipStamps() |
17
|
|
|
{ |
18
|
|
|
$this->ipAddress('created_ip')->nullable(); |
19
|
|
|
$this->ipAddress('updated_ip')->nullable(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function userStamps() |
23
|
|
|
{ |
24
|
|
|
$this->unsignedInteger('created_by')->nullable(); |
25
|
|
|
$this->unsignedInteger('updated_by')->nullable(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function softDeletesRecordStamps() |
29
|
|
|
{ |
30
|
|
|
$this->softDeletes(); |
31
|
|
|
$this->softDeletesStamps(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function softDeletesStamps() |
35
|
|
|
{ |
36
|
|
|
$this->ipAddress('deleted_ip')->nullable(); |
37
|
|
|
$this->unsignedInteger('deleted_by')->nullable(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function dropRecordStamps() |
41
|
|
|
{ |
42
|
|
|
$this->dropTimestamps(); |
43
|
|
|
$this->dropIpStamps(); |
44
|
|
|
$this->dropUserStamps(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function dropIpStamps() |
48
|
|
|
{ |
49
|
|
|
$this->dropColumn('created_ip', 'updated_ip'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function dropUserStamps() |
53
|
|
|
{ |
54
|
|
|
$this->dropColumn('created_by', 'updated_by'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function dropSoftDeletesRecordStamps() |
58
|
|
|
{ |
59
|
|
|
$this->dropSoftDeletes(); |
60
|
|
|
$this->dropSoftDeletesStamps(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function dropSoftDeletesStamps() |
64
|
|
|
{ |
65
|
|
|
$this->dropColumn('deleted_ip', 'deleted_by'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Specify a fulltext index for the table. |
70
|
|
|
* |
71
|
|
|
* @param string|array $columns |
72
|
|
|
* @param string $name |
73
|
|
|
* @return \Illuminate\Support\Fluent |
74
|
|
|
*/ |
75
|
|
|
public function fulltext($columns, $name = null) |
76
|
|
|
{ |
77
|
|
|
return $this->indexCommand('fulltext', $columns, $name); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Indicate that the given fulltext key should be dropped. |
82
|
|
|
* |
83
|
|
|
* @param string|array $index |
84
|
|
|
* @return \Illuminate\Support\Fluent |
85
|
|
|
*/ |
86
|
|
|
public function dropFulltext($index) |
87
|
|
|
{ |
88
|
|
|
return $this->dropIndexCommand('dropFulltext', 'fulltext', $index); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Add the index commands fluently specified on columns. |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
protected function addFluentIndexes() |
97
|
|
|
{ |
98
|
|
|
$FluentIndexes = ['primary', 'unique', 'index', 'fulltext']; |
99
|
|
|
foreach ($this->columns as $column) { |
100
|
|
|
foreach ($FluentIndexes as $index) { |
101
|
|
|
// If the index has been specified on the given column, but is simply |
102
|
|
|
// equal to "true" (boolean), no name has been specified for this |
103
|
|
|
// index, so we will simply call the index methods without one. |
104
|
|
|
if ($column->$index === true) { |
105
|
|
|
$this->$index($column->name); |
106
|
|
|
|
107
|
|
|
continue 2; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// If the index has been specified on the column and it is something |
111
|
|
|
// other than boolean true, we will assume a name was provided on |
112
|
|
|
// the index specification, and pass in the name to the method. |
113
|
|
|
elseif (isset($column->$index)) { |
114
|
|
|
$this->$index($column->name, $column->$index); |
115
|
|
|
|
116
|
|
|
continue 2; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|