1
|
|
|
<?php namespace Anomaly\Streams\Platform\Database\Migration; |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Addon\Addon; |
4
|
|
|
use Anomaly\Streams\Platform\Assignment\Contract\AssignmentRepositoryInterface; |
5
|
|
|
use Anomaly\Streams\Platform\Field\Contract\FieldRepositoryInterface; |
6
|
|
|
use Anomaly\Streams\Platform\Stream\Contract\StreamRepositoryInterface; |
7
|
|
|
use Illuminate\Database\Schema\Builder; |
8
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
9
|
|
|
|
10
|
|
|
abstract class Migration extends \Illuminate\Database\Migrations\Migration |
11
|
|
|
{ |
12
|
|
|
|
13
|
|
|
use DispatchesJobs; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The addon instance. |
17
|
|
|
* |
18
|
|
|
* This is set by the migrator when |
19
|
|
|
* an addon is being migrated. |
20
|
|
|
* |
21
|
|
|
* @var Addon |
22
|
|
|
*/ |
23
|
|
|
protected $addon = null; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The stream namespace. |
27
|
|
|
* |
28
|
|
|
* @var null|string |
29
|
|
|
*/ |
30
|
|
|
protected $namespace = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The migration fields. |
34
|
|
|
* |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
protected $fields = []; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The migration stream. |
41
|
|
|
* |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
protected $stream = []; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The migration assignments. |
48
|
|
|
* |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
protected $assignments = []; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Should the migration delete its stream when rolling back? |
55
|
|
|
* |
56
|
|
|
* @var bool |
57
|
|
|
*/ |
58
|
|
|
protected $delete = true; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Return the migration's contextual namespace. |
62
|
|
|
* |
63
|
|
|
* @return string |
64
|
|
|
*/ |
65
|
|
|
public function contextualNamespace() |
66
|
|
|
{ |
67
|
|
|
return $this->getNamespace() ?: $this->addon->getSlug(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Return the field repository. |
72
|
|
|
* |
73
|
|
|
* @return FieldRepositoryInterface |
74
|
|
|
*/ |
75
|
|
|
public function fields() |
76
|
|
|
{ |
77
|
|
|
return app(FieldRepositoryInterface::class); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Return the stream repository. |
82
|
|
|
* |
83
|
|
|
* @return StreamRepositoryInterface |
84
|
|
|
*/ |
85
|
|
|
public function streams() |
86
|
|
|
{ |
87
|
|
|
return app(StreamRepositoryInterface::class); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Return the assignment repository. |
92
|
|
|
* |
93
|
|
|
* @return AssignmentRepositoryInterface |
94
|
|
|
*/ |
95
|
|
|
public function assignments() |
96
|
|
|
{ |
97
|
|
|
return app(AssignmentRepositoryInterface::class); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Return the schema builder. |
102
|
|
|
* |
103
|
|
|
* @return Builder |
104
|
|
|
*/ |
105
|
|
|
public function schema() |
106
|
|
|
{ |
107
|
|
|
return app('db')->connection()->getSchemaBuilder(); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Return the delete flag. |
112
|
|
|
* |
113
|
|
|
* @return bool |
114
|
|
|
*/ |
115
|
|
|
public function getDelete() |
116
|
|
|
{ |
117
|
|
|
return $this->delete; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set the addon. |
122
|
|
|
* |
123
|
|
|
* @param Addon $addon |
124
|
|
|
*/ |
125
|
|
|
public function setAddon(Addon $addon) |
126
|
|
|
{ |
127
|
|
|
$this->addon = $addon; |
128
|
|
|
|
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Get the addon. |
134
|
|
|
* |
135
|
|
|
* @return Addon |
136
|
|
|
*/ |
137
|
|
|
public function getAddon() |
138
|
|
|
{ |
139
|
|
|
return $this->addon; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Get the namespace. |
144
|
|
|
* |
145
|
|
|
* @return null|string |
146
|
|
|
*/ |
147
|
|
|
public function getNamespace() |
148
|
|
|
{ |
149
|
|
|
return $this->namespace; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Set the fields. |
154
|
|
|
* |
155
|
|
|
* @param array $fields |
156
|
|
|
* @return $this |
157
|
|
|
*/ |
158
|
|
|
public function setFields(array $fields) |
159
|
|
|
{ |
160
|
|
|
$this->fields = $fields; |
161
|
|
|
|
162
|
|
|
return $this; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get the fields. |
167
|
|
|
* |
168
|
|
|
* @return array |
169
|
|
|
*/ |
170
|
|
|
public function getFields() |
171
|
|
|
{ |
172
|
|
|
return $this->fields; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Set the stream. |
177
|
|
|
* |
178
|
|
|
* @param array $stream |
179
|
|
|
* @return $this |
180
|
|
|
*/ |
181
|
|
|
public function setStream(array $stream) |
182
|
|
|
{ |
183
|
|
|
$this->stream = $stream; |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Get the stream. |
190
|
|
|
* |
191
|
|
|
* @return array |
192
|
|
|
*/ |
193
|
|
|
public function getStream() |
194
|
|
|
{ |
195
|
|
|
return $this->stream; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Set the assignments. |
200
|
|
|
* |
201
|
|
|
* @param array $assignments |
202
|
|
|
* @return $this |
203
|
|
|
*/ |
204
|
|
|
public function setAssignments(array $assignments) |
205
|
|
|
{ |
206
|
|
|
$this->assignments = $assignments; |
207
|
|
|
|
208
|
|
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Get the assignments. |
213
|
|
|
* |
214
|
|
|
* @return array |
215
|
|
|
*/ |
216
|
|
|
public function getAssignments() |
217
|
|
|
{ |
218
|
|
|
return $this->assignments; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Migrate |
223
|
|
|
*/ |
224
|
|
|
public function up() |
225
|
|
|
{ |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Rollback |
230
|
|
|
*/ |
231
|
|
|
public function down() |
232
|
|
|
{ |
233
|
|
|
} |
234
|
|
|
} |
235
|
|
|
|