|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Schema; |
|
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
5
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
6
|
|
|
|
|
7
|
|
|
use App\Models\JobPoster; |
|
8
|
|
|
|
|
9
|
|
|
class ChangeJobPosterRemoteWorkColumnToBool extends Migration |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Run the migrations. |
|
13
|
|
|
* |
|
14
|
|
|
* @return void |
|
15
|
|
|
*/ |
|
16
|
|
|
public function up() |
|
17
|
|
|
{ |
|
18
|
|
|
// Since the ORM doesn't support a direct text to boolean migration we |
|
19
|
|
|
// have to get a little creative. |
|
20
|
|
|
|
|
21
|
|
|
// Add a new temp boolean column to the table |
|
22
|
|
|
Schema::table('job_posters', function (Blueprint $table) { |
|
23
|
|
|
$table->boolean('remote_work_allowed_new')->default(false); |
|
24
|
|
|
}); |
|
25
|
|
|
|
|
26
|
|
|
// Loop through the existing entries and populate the new column |
|
27
|
|
|
$jobPosters = JobPoster::all(); |
|
28
|
|
|
if ($jobPosters) { |
|
|
|
|
|
|
29
|
|
|
foreach ($jobPosters as $jobPoster) { |
|
30
|
|
|
if ($jobPoster->remote_work_allowed === '1' || $jobPoster->remote_work_allowed === true) { |
|
31
|
|
|
$jobPoster->remote_work_allowed_new = true; |
|
|
|
|
|
|
32
|
|
|
} elseif ($jobPoster->remote_work_allowed === '0' || $jobPoster->remote_work_allowed === false) { |
|
33
|
|
|
$jobPoster->remote_work_allowed_new = false; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$jobPoster->save(); |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
// Drop the old column |
|
41
|
|
|
Schema::table('job_posters', function (Blueprint $table) { |
|
42
|
|
|
$table->dropColumn('remote_work_allowed'); |
|
43
|
|
|
}); |
|
44
|
|
|
|
|
45
|
|
|
// Rename the new one |
|
46
|
|
|
Schema::table('job_posters', function (Blueprint $table) { |
|
47
|
|
|
$table->renameColumn('remote_work_allowed_new', 'remote_work_allowed'); |
|
48
|
|
|
}); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Reverse the migrations. |
|
53
|
|
|
* |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
|
|
public function down() |
|
57
|
|
|
{ |
|
58
|
|
|
// Since the ORM doesn't support a direct boolean to text migration we |
|
59
|
|
|
// have to get a little creative. |
|
60
|
|
|
|
|
61
|
|
|
// Add a new temp string column to the table |
|
62
|
|
|
Schema::table('job_posters', function (Blueprint $table) { |
|
63
|
|
|
$table->string('remote_work_allowed_new')->default('0'); |
|
64
|
|
|
}); |
|
65
|
|
|
|
|
66
|
|
|
// Loop through the existing entries and populate the new column |
|
67
|
|
|
$jobPosters = JobPoster::all(); |
|
68
|
|
|
if ($jobPosters) { |
|
|
|
|
|
|
69
|
|
|
foreach ($jobPosters as $jobPoster) { |
|
70
|
|
|
if ($jobPoster->remote_work_allowed === '1' || $jobPoster->remote_work_allowed === true) { |
|
71
|
|
|
$jobPoster->remote_work_allowed_new = '1'; |
|
|
|
|
|
|
72
|
|
|
} elseif ($jobPoster->remote_work_allowed === '0' || $jobPoster->remote_work_allowed === false) { |
|
73
|
|
|
$jobPoster->remote_work_allowed_new = '0'; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$jobPoster->save(); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
// Drop the old column |
|
81
|
|
|
Schema::table('job_posters', function (Blueprint $table) { |
|
82
|
|
|
$table->dropColumn('remote_work_allowed'); |
|
83
|
|
|
}); |
|
84
|
|
|
|
|
85
|
|
|
// Rename the new one |
|
86
|
|
|
Schema::table('job_posters', function (Blueprint $table) { |
|
87
|
|
|
$table->renameColumn('remote_work_allowed_new', 'remote_work_allowed'); |
|
88
|
|
|
}); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|