Passed
Push — testing ( 57c125...199f7f )
by Hennik
03:23
created

UpdateLocationTable::down()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
use LaravelSpatial\MysqlConnection;
7
8
class UpdateLocationTable extends Migration
9
{
10
    /**
11
     * Run the migrations.
12
     *
13
     * @return void
14
     */
15
    public function up()
16
    {
17
        Schema::table('test_geometries', function(Blueprint $table) {
18
            // Make sure point is not nullable
19
            $table->point('location')->change();
20
21
            // The other field changes are just here to test if change works with them, we're not changing anything
22
            $table->geometry('geo')->default(null)->nullable()->change();
23
            $table->lineString('line')->default(null)->nullable()->change();
24
            $table->polygon('shape')->default(null)->nullable()->change();
25
            $table->multiPoint('multi_locations')->default(null)->nullable()->change();
26
            $table->multiLineString('multi_lines')->default(null)->nullable()->change();
27
            $table->multiPolygon('multi_shapes')->default(null)->nullable()->change();
28
            $table->geometryCollection('multi_geometries')->default(null)->nullable()->change();
29
30
        });
31
32
        if (is_a(\DB::connection(), MysqlConnection::class)) {
33
            // MySQL < 5.7.5: table has to be MyISAM
34
            \DB::statement('ALTER TABLE test_geometries ENGINE = MyISAM');
35
        }
36
37
        Schema::table('test_geometries', function(Blueprint $table) {
38
            // Add a spatial index on the location field
39
            $table->spatialIndex('location');
40
        });
41
    }
42
43
    /**
44
     * Reverse the migrations.
45
     *
46
     * @return void
47
     */
48
    public function down()
49
    {
50
        Schema::table('test_geometries', function(Blueprint $table) {
51
            $table->dropSpatialIndex(['location']); // either an array of column names or the index name
52
        });
53
54
        if (is_a(\DB::connection(), MysqlConnection::class)) {
55
            \DB::statement('ALTER TABLE test_geometries ENGINE = InnoDB');
56
        }
57
58
        Schema::table('test_geometries', function(Blueprint $table) {
59
            $table->point('location')->nullable()->change();
60
        });
61
    }
62
}
63