1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Database\Migration\Migration; |
4
|
|
|
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface; |
5
|
|
|
use Illuminate\Database\Schema\Blueprint; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class AppendIdToUserMetaColumns |
9
|
|
|
* |
10
|
|
|
* @link http://pyrocms.com/ |
11
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
12
|
|
|
* @author Ryan Thompson <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class AppendIdToUserMetaColumns extends Migration |
|
|
|
|
15
|
|
|
{ |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Run the migrations. |
19
|
|
|
* |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
|
View Code Duplication |
public function up() |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/* @var StreamInterface $stream */ |
25
|
|
|
foreach ($this->streams()->all() as $stream) { |
26
|
|
|
|
27
|
|
|
if ($this->schema()->hasColumn($stream->getEntryTableName(), 'created_by')) { |
28
|
|
|
|
29
|
|
|
$this->schema()->table( |
30
|
|
|
$stream->getEntryTableName(), |
31
|
|
|
function (Blueprint $table) { |
32
|
|
|
$table->renameColumn('created_by', 'created_by_id'); |
33
|
|
|
$table->renameColumn('updated_by', 'updated_by_id'); |
34
|
|
|
} |
35
|
|
|
); |
36
|
|
|
|
37
|
|
|
if ($stream->isTranslatable()) { |
38
|
|
|
|
39
|
|
|
$this->schema()->table( |
40
|
|
|
$stream->getEntryTranslationsTableName(), |
41
|
|
|
function (Blueprint $table) { |
42
|
|
|
$table->renameColumn('created_by', 'created_by_id'); |
43
|
|
|
$table->renameColumn('updated_by', 'updated_by_id'); |
44
|
|
|
} |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Reverse the migrations. |
53
|
|
|
* |
54
|
|
|
* @return void |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function down() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
/* @var StreamInterface $stream */ |
59
|
|
|
foreach ($this->streams()->all() as $stream) { |
60
|
|
|
|
61
|
|
|
if ($this->schema()->hasColumn($stream->getEntryTableName(), 'created_by_id')) { |
62
|
|
|
|
63
|
|
|
$this->schema()->table( |
64
|
|
|
$stream->getEntryTableName(), |
65
|
|
|
function (Blueprint $table) { |
66
|
|
|
$table->renameColumn('created_by_id', 'created_by'); |
67
|
|
|
$table->renameColumn('updated_by_id', 'updated_by'); |
68
|
|
|
} |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
if ($stream->isTranslatable()) { |
72
|
|
|
|
73
|
|
|
$this->schema()->table( |
74
|
|
|
$stream->getEntryTranslationsTableName(), |
75
|
|
|
function (Blueprint $table) { |
76
|
|
|
$table->renameColumn('created_by_id', 'created_by'); |
77
|
|
|
$table->renameColumn('updated_by_id', 'updated_by'); |
78
|
|
|
} |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.