Skip to content

Commit b0d526a

Browse files
authored
Merge pull request #263 from kitloong/feature/spatial
Remove unsupported spatial column types
2 parents e46bdbe + f6a162b commit b0d526a

File tree

5 files changed

+22
-43
lines changed

5 files changed

+22
-43
lines changed

src/Database/Models/MySQL/MySQLColumn.php

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,7 @@ public function __construct(string $table, array $column)
8787

8888
case ColumnType::GEOGRAPHY:
8989
case ColumnType::GEOMETRY:
90-
case ColumnType::GEOMETRY_COLLECTION:
91-
case ColumnType::LINE_STRING:
92-
case ColumnType::MULTI_LINE_STRING:
93-
case ColumnType::POINT:
94-
case ColumnType::MULTI_POINT:
95-
case ColumnType::POLYGON:
96-
case ColumnType::MULTI_POLYGON:
97-
$this->setRealSpatialColumn();
90+
$this->setRealSpatialColumn($column['type_name']);
9891
break;
9992

10093
default:
@@ -248,34 +241,35 @@ private function setStoredDefinition(): void
248241
/**
249242
* Set to geometry or geography.
250243
*/
251-
private function setRealSpatialColumn(): void
244+
private function setRealSpatialColumn(string $typeName): void
252245
{
253-
switch ($this->type) {
254-
case ColumnType::GEOMETRY_COLLECTION:
246+
switch ($typeName) {
247+
case 'geometrycollection':
248+
case 'geomcollection':
255249
$this->spatialSubType = 'geometryCollection';
256250
break;
257251

258-
case ColumnType::LINE_STRING:
252+
case 'linestring':
259253
$this->spatialSubType = 'lineString';
260254
break;
261255

262-
case ColumnType::MULTI_LINE_STRING:
256+
case 'multilinestring':
263257
$this->spatialSubType = 'multiLineString';
264258
break;
265259

266-
case ColumnType::POINT:
260+
case 'point':
267261
$this->spatialSubType = 'point';
268262
break;
269263

270-
case ColumnType::MULTI_POINT:
264+
case 'multipoint':
271265
$this->spatialSubType = 'multiPoint';
272266
break;
273267

274-
case ColumnType::POLYGON:
268+
case 'polygon':
275269
$this->spatialSubType = 'polygon';
276270
break;
277271

278-
case ColumnType::MULTI_POLYGON:
272+
case 'multipolygon':
279273
$this->spatialSubType = 'multiPolygon';
280274
break;
281275

src/Database/Models/MySQL/MySQLColumnType.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,19 @@ class MySQLColumnType extends DatabaseColumnType
4747
'varchar' => ColumnType::STRING,
4848
'year' => ColumnType::YEAR,
4949

50+
'geomcollection' => ColumnType::GEOMETRY,
51+
'linestring' => ColumnType::GEOMETRY,
52+
'multilinestring' => ColumnType::GEOMETRY,
53+
'point' => ColumnType::GEOMETRY,
54+
'multipoint' => ColumnType::GEOMETRY,
55+
'polygon' => ColumnType::GEOMETRY,
56+
'multipolygon' => ColumnType::GEOMETRY,
57+
5058
// For MariaDB
5159
'uuid' => ColumnType::UUID,
5260

53-
// Removed from Laravel v11
54-
'geomcollection' => ColumnType::GEOMETRY_COLLECTION,
55-
'linestring' => ColumnType::LINE_STRING,
56-
'multilinestring' => ColumnType::MULTI_LINE_STRING,
57-
'point' => ColumnType::POINT,
58-
'multipoint' => ColumnType::MULTI_POINT,
59-
'polygon' => ColumnType::POLYGON,
60-
'multipolygon' => ColumnType::MULTI_POLYGON,
61-
62-
// For MariaDB
63-
'geometrycollection' => ColumnType::GEOMETRY_COLLECTION,
61+
// For MariaDB and MySQL57
62+
'geometrycollection' => ColumnType::GEOMETRY,
6463
];
6564

6665
/**

src/Enum/Migrations/Method/ColumnType.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,16 @@ enum ColumnType: string implements MethodName
2323
case FLOAT = 'float';
2424
case GEOGRAPHY = 'geography';
2525
case GEOMETRY = 'geometry';
26-
case GEOMETRY_COLLECTION = 'geometryCollection';
2726
case INCREMENTS = 'increments';
2827
case INTEGER = 'integer';
2928
case IP_ADDRESS = 'ipAddress';
3029
case JSON = 'json';
3130
case JSONB = 'jsonb';
32-
case LINE_STRING = 'lineString';
3331
case LONG_TEXT = 'longText';
3432
case MAC_ADDRESS = 'macAddress';
3533
case MEDIUM_INCREMENTS = 'mediumIncrements';
3634
case MEDIUM_INTEGER = 'mediumInteger';
3735
case MEDIUM_TEXT = 'mediumText';
38-
case MULTI_LINE_STRING = 'multiLineString';
39-
case MULTI_POINT = 'multiPoint';
40-
case MULTI_POLYGON = 'multiPolygon';
41-
case POINT = 'point';
42-
case POLYGON = 'polygon';
4336
case REMEMBER_TOKEN = 'rememberToken';
4437
case SET = 'set';
4538
case SMALL_INCREMENTS = 'smallIncrements';

src/MigrationsGeneratorServiceProvider.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,6 @@ protected function registerColumnTypeGenerator(): void
189189
[
190190
ColumnType::GEOGRAPHY,
191191
ColumnType::GEOMETRY,
192-
ColumnType::GEOMETRY_COLLECTION,
193-
ColumnType::LINE_STRING,
194-
ColumnType::MULTI_LINE_STRING,
195-
ColumnType::POINT,
196-
ColumnType::MULTI_POINT,
197-
ColumnType::MULTI_POLYGON,
198-
ColumnType::POLYGON,
199192
] as $columnType
200193
) {
201194
$this->columnTypeSingleton($columnType, SpatialColumn::class);

tests/resources/database/migrations/general/2020_03_21_000000_expected_create_all_columns_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function up()
8080

8181
if (
8282
!in_array(DB::getDriverName(), [Driver::MARIADB->value, Driver::MYSQL->value]) ||
83-
version_compare(DB::getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), '5.7', 'eq')
83+
version_compare(DB::getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION), '5.8', '>')
8484
) {
8585
$table->geography('geography');
8686
$table->geography('geographyGeometryCollection', 'geometryCollection');

0 commit comments

Comments
 (0)