Completed
Push — master ( 29dd4a...211d70 )
by Joseph
11:41
created

AddEnabledDisabledTimestamps::down()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
use Illuminate\Support\Facades\Schema;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Database\Migrations\Migration;
6
7
class AddEnabledDisabledTimestamps extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     */
12
    public function up()
13
    {
14
        Schema::table('cloud_storages', function (Blueprint $table) {
15
            $table->timestamp('enabled_at')->nullable();
16
            $table->timestamp('disabled_at')->nullable();
17
        });
18
19
        // Need to make sure we have some enabled_at date for all currently enabled connections
20
        \STS\StorageConnect\Models\CloudStorage::where('enabled', 1)->get()->each(function($storage) {
21
            $storage->update(['enabled_at' => $storage->created_at]);
22
        });
23
24
        // Same for disabled
25
        \STS\StorageConnect\Models\CloudStorage::where('enabled', 0)->get()->each(function($storage) {
26
            $storage->update(['disabled_at' => $storage->updated_at]);
27
        });
28
    }
29
30
    /**
31
     * Reverse the migrations.
32
     */
33
    public function down()
34
    {
35
36
    }
37
}