1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Laravel Love. |
5
|
|
|
* |
6
|
|
|
* (c) Anton Komarev <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Cog\Laravel\Love\Console\Commands; |
15
|
|
|
|
16
|
|
|
use Illuminate\Console\Command; |
17
|
|
|
use Illuminate\Database\ConnectionInterface; |
18
|
|
|
use Illuminate\Database\Schema\Blueprint; |
19
|
|
|
use Illuminate\Database\Schema\Builder; |
20
|
|
|
use Illuminate\Support\Facades\Config; |
21
|
|
|
use Illuminate\Support\Facades\DB; |
22
|
|
|
use Illuminate\Support\Facades\Schema; |
23
|
|
|
|
24
|
|
|
final class UpgradeV7ToV8 extends Command |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* The name and signature of the console command. |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $signature = 'love:upgrade-v7-to-v8'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The console command description. |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $description = 'Upgrade love package from v7 to v8'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Execute the console command. |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function handle(): void |
46
|
|
|
{ |
47
|
|
|
$this->dbChangeReactionTypes(); |
48
|
|
|
$this->dbChangeReactions(); |
49
|
|
|
$this->dbChangeReactantReactionCounters(); |
50
|
|
|
$this->dbChangeReactantReactionTotals(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
private function dbChangeReactionTypes(): void |
54
|
|
|
{ |
55
|
|
|
$this->getDbSchema()->table('love_reaction_types', function (Blueprint $table) { |
56
|
|
|
$table->renameColumn('weight', 'mass'); |
57
|
|
|
}); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function dbChangeReactions(): void |
61
|
|
|
{ |
62
|
|
|
$this->getDbSchema()->table('love_reactions', function (Blueprint $table) { |
63
|
|
|
$table->decimal('rate', 4, 2)->after('reaction_type_id'); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
$this |
67
|
|
|
->getDbQuery() |
68
|
|
|
->table('love_reactions') |
69
|
|
|
->where('rate', 0.0) |
70
|
|
|
->update([ |
71
|
|
|
'rate' => 1.0, |
72
|
|
|
]); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
private function dbChangeReactantReactionCounters(): void |
76
|
|
|
{ |
77
|
|
|
$this->getDbSchema()->table('love_reactant_reaction_counters', function (Blueprint $table) { |
78
|
|
|
$table->unsignedBigInteger('count')->default(null)->change(); |
79
|
|
|
$table->decimal('weight', 22, 2)->default(null)->change(); |
80
|
|
|
}); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
private function dbChangeReactantReactionTotals(): void |
84
|
|
|
{ |
85
|
|
|
$this->getDbSchema()->table('love_reactant_reaction_totals', function (Blueprint $table) { |
86
|
|
|
$table->unsignedBigInteger('count')->default(null)->change(); |
87
|
|
|
$table->decimal('weight', 22, 2)->default(null)->change(); |
88
|
|
|
}); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
private function getDbSchema(): Builder |
92
|
|
|
{ |
93
|
|
|
return Schema::connection($this->getDatabaseConnection()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
private function getDbQuery(): ConnectionInterface |
97
|
|
|
{ |
98
|
|
|
return DB::connection($this->getDatabaseConnection()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
private function getDatabaseConnection(): ?string |
102
|
|
|
{ |
103
|
|
|
return Config::get('love.storage.database.connection'); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|