Skip to content

Commit aad71bf

Browse files
committed
Fixes for Laravel 5.2+/MySQL 8:
- Added Srid to MySqlGrammar - Added explicit charset and collation to migrations in tests - Fixed show create command in tests for MySQL 8 - Changed branch alias to 3.0
1 parent 3578a93 commit aad71bf

File tree

4 files changed

+47
-13
lines changed

4 files changed

+47
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
},
4444
"extra": {
4545
"branch-alias": {
46-
"dev-master": "2.0.x-dev"
46+
"dev-master": "3.0.x-dev"
4747
},
4848
"laravel": {
4949
"providers": [

src/Schema/Grammars/MySqlGrammar.php

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,25 @@
88

99
class MySqlGrammar extends IlluminateMySqlGrammar
1010
{
11+
/**
12+
* The possible column modifiers.
13+
*
14+
* @var array
15+
*/
16+
// protected $modifiers = [
17+
// 'Unsigned', 'Charset', 'Collate', 'VirtualAs', 'StoredAs', 'Nullable',
18+
// 'Default', 'Increment', 'Comment', 'After', 'First', 'Srid',
19+
// ];
20+
21+
public function __construct()
22+
{
23+
$this->modifiers[] = 'Srid';
24+
}
25+
1126
/**
1227
* Adds a statement to add a geometry column.
1328
*
14-
* @param \Illuminate\Support\Fluent $column
29+
* @param Fluent $column
1530
*
1631
* @return string
1732
*/
@@ -23,7 +38,7 @@ public function typeGeometry(Fluent $column)
2338
/**
2439
* Adds a statement to add a point column.
2540
*
26-
* @param \Illuminate\Support\Fluent $column
41+
* @param Fluent $column
2742
*
2843
* @return string
2944
*/
@@ -35,7 +50,7 @@ public function typePoint(Fluent $column)
3550
/**
3651
* Adds a statement to add a linestring column.
3752
*
38-
* @param \Illuminate\Support\Fluent $column
53+
* @param Fluent $column
3954
*
4055
* @return string
4156
*/
@@ -47,7 +62,7 @@ public function typeLinestring(Fluent $column)
4762
/**
4863
* Adds a statement to add a polygon column.
4964
*
50-
* @param \Illuminate\Support\Fluent $column
65+
* @param Fluent $column
5166
*
5267
* @return string
5368
*/
@@ -59,7 +74,7 @@ public function typePolygon(Fluent $column)
5974
/**
6075
* Adds a statement to add a multipoint column.
6176
*
62-
* @param \Illuminate\Support\Fluent $column
77+
* @param Fluent $column
6378
*
6479
* @return string
6580
*/
@@ -71,7 +86,7 @@ public function typeMultipoint(Fluent $column)
7186
/**
7287
* Adds a statement to add a multilinestring column.
7388
*
74-
* @param \Illuminate\Support\Fluent $column
89+
* @param Fluent $column
7590
*
7691
* @return string
7792
*/
@@ -83,7 +98,7 @@ public function typeMultilinestring(Fluent $column)
8398
/**
8499
* Adds a statement to add a multipolygon column.
85100
*
86-
* @param \Illuminate\Support\Fluent $column
101+
* @param Fluent $column
87102
*
88103
* @return string
89104
*/
@@ -95,7 +110,7 @@ public function typeMultipolygon(Fluent $column)
95110
/**
96111
* Adds a statement to add a geometrycollection column.
97112
*
98-
* @param \Illuminate\Support\Fluent $column
113+
* @param Fluent $column
99114
*
100115
* @return string
101116
*/
@@ -107,13 +122,28 @@ public function typeGeometrycollection(Fluent $column)
107122
/**
108123
* Compile a spatial index key command.
109124
*
110-
* @param \Grimzy\LaravelMysqlSpatial\Schema\Blueprint $blueprint
111-
* @param \Illuminate\Support\Fluent $command
125+
* @param Blueprint $blueprint
126+
* @param Fluent $command
112127
*
113128
* @return string
114129
*/
115130
public function compileSpatial(Blueprint $blueprint, Fluent $command)
116131
{
117132
return $this->compileKey($blueprint, $command, 'spatial');
118133
}
134+
135+
/**
136+
* Get the SQL for a SRID column modifier.
137+
*
138+
* @param Blueprint $blueprint
139+
* @param Fluent $column
140+
*
141+
* @return string|null
142+
*/
143+
protected function modifySrid(Blueprint $blueprint, Fluent $column)
144+
{
145+
if (!is_null($column->srid) && is_int($column->srid) && $column->srid > 0) {
146+
return ' srid '.$column->srid;
147+
}
148+
}
119149
}

tests/Integration/MigrationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function testTableWasCreatedWithRightTypes()
1414
$result = DB::selectOne('SHOW CREATE TABLE geometry');
1515

1616
$expected = 'CREATE TABLE `geometry` (
17-
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
17+
`id` int unsigned NOT NULL AUTO_INCREMENT,
1818
`geo` geometry DEFAULT NULL,
1919
`location` point NOT NULL,
2020
`line` linestring DEFAULT NULL,
@@ -38,7 +38,7 @@ public function testTableWasCreatedWithSrid()
3838
$result = DB::selectOne('SHOW CREATE TABLE with_srid');
3939

4040
$expected = 'CREATE TABLE `with_srid` (
41-
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
41+
`id` int unsigned NOT NULL AUTO_INCREMENT,
4242
`geo` geometry /*!80003 SRID 3857 */ DEFAULT NULL,
4343
`location` point /*!80003 SRID 3857 */ DEFAULT NULL,
4444
`line` linestring /*!80003 SRID 3857 */ DEFAULT NULL,

tests/Integration/Migrations/CreateTables.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class CreateLocationTable extends Migration
1414
public function up()
1515
{
1616
Schema::create('geometry', function (Blueprint $table) {
17+
$table->charset = 'utf8mb4';
18+
$table->collation = 'utf8mb4_unicode_ci';
1719
$table->increments('id');
1820
$table->geometry('geo')->default(null)->nullable();
1921
$table->point('location'); // required to be not null in order to add an index
@@ -32,6 +34,8 @@ public function up()
3234
});
3335

3436
Schema::create('with_srid', function (Blueprint $table) {
37+
$table->charset = 'utf8mb4';
38+
$table->collation = 'utf8mb4_unicode_ci';
3539
$table->increments('id');
3640
$table->geometry('geo', 3857)->default(null)->nullable();
3741
$table->point('location', 3857)->default(null)->nullable();

0 commit comments

Comments
 (0)