Skip to content

Commit 6fb6f8f

Browse files
authored
Merge pull request #110 from utopia-php/spatial-attribute-support
added spatial type migration support
2 parents eb60a61 + 3ef0244 commit 6fb6f8f

9 files changed

Lines changed: 300 additions & 33 deletions

File tree

composer.lock

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Migration/Destinations/Appwrite.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,9 @@ protected function createColumn(Column $resource): bool
440440
Column::TYPE_EMAIL,
441441
Column::TYPE_URL,
442442
Column::TYPE_ENUM => UtopiaDatabase::VAR_STRING,
443+
Column::TYPE_POINT => UtopiaDatabase::VAR_POINT,
444+
Column::TYPE_LINE => UtopiaDatabase::VAR_LINESTRING,
445+
Column::TYPE_POLYGON => UtopiaDatabase::VAR_POLYGON,
443446
default => throw new \Exception('Invalid resource type '.$resource->getType()),
444447
};
445448

src/Migration/Resources/Database/Column.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ abstract class Column extends Resource
1818
public const TYPE_URL = 'url';
1919
public const TYPE_RELATIONSHIP = 'relationship';
2020

21+
public const TYPE_POINT = 'point';
22+
public const TYPE_LINE = 'linestring';
23+
public const TYPE_POLYGON = 'polygon';
24+
2125
/**
2226
* @param string $key
2327
* @param Table $table
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Utopia\Migration\Resources\Database\Columns;
4+
5+
use Utopia\Migration\Resources\Database\Column;
6+
use Utopia\Migration\Resources\Database\Table;
7+
8+
class Line extends Column
9+
{
10+
public function __construct(
11+
string $key,
12+
Table $table,
13+
bool $required = false,
14+
?array $default = null,
15+
string $createdAt = '',
16+
string $updatedAt = ''
17+
) {
18+
parent::__construct(
19+
$key,
20+
$table,
21+
required: $required,
22+
default: $default,
23+
createdAt: $createdAt,
24+
updatedAt: $updatedAt
25+
);
26+
}
27+
28+
/**
29+
* @param array{
30+
* key: string,
31+
* collection?: array{
32+
* database: array{
33+
* id: string,
34+
* name: string,
35+
* },
36+
* name: string,
37+
* id: string,
38+
* documentSecurity: bool,
39+
* permissions: ?array<string>
40+
* },
41+
* table?: array{
42+
* database: array{
43+
* id: string,
44+
* name: string,
45+
* },
46+
* name: string,
47+
* id: string,
48+
* rowSecurity: bool,
49+
* permissions: ?array<string>
50+
* },
51+
* required: bool,
52+
* default: ?array<mixed>,
53+
* createdAt: string,
54+
* updatedAt: string,
55+
* } $array
56+
* @return self
57+
*/
58+
public static function fromArray(array $array): self
59+
{
60+
return new self(
61+
$array['key'],
62+
Table::fromArray($array['table'] ?? $array['collection']),
63+
required: $array['required'],
64+
default: $array['default'],
65+
createdAt: $array['createdAt'] ?? '',
66+
updatedAt: $array['updatedAt'] ?? '',
67+
);
68+
}
69+
70+
public function getType(): string
71+
{
72+
return Column::TYPE_LINE;
73+
}
74+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Utopia\Migration\Resources\Database\Columns;
4+
5+
use Utopia\Migration\Resources\Database\Column;
6+
use Utopia\Migration\Resources\Database\Table;
7+
8+
class Point extends Column
9+
{
10+
public function __construct(
11+
string $key,
12+
Table $table,
13+
bool $required = false,
14+
?array $default = null,
15+
string $createdAt = '',
16+
string $updatedAt = ''
17+
) {
18+
parent::__construct(
19+
$key,
20+
$table,
21+
required: $required,
22+
default: $default,
23+
createdAt: $createdAt,
24+
updatedAt: $updatedAt
25+
);
26+
}
27+
28+
/**
29+
* @param array{
30+
* key: string,
31+
* collection?: array{
32+
* database: array{
33+
* id: string,
34+
* name: string,
35+
* },
36+
* name: string,
37+
* id: string,
38+
* documentSecurity: bool,
39+
* permissions: ?array<string>
40+
* },
41+
* table?: array{
42+
* database: array{
43+
* id: string,
44+
* name: string,
45+
* },
46+
* name: string,
47+
* id: string,
48+
* rowSecurity: bool,
49+
* permissions: ?array<string>
50+
* },
51+
* required: bool,
52+
* default: ?array<mixed>,
53+
* createdAt: string,
54+
* updatedAt: string,
55+
* } $array
56+
* @return self
57+
*/
58+
public static function fromArray(array $array): self
59+
{
60+
return new self(
61+
$array['key'],
62+
Table::fromArray($array['table'] ?? $array['collection']),
63+
required: $array['required'],
64+
default: $array['default'],
65+
createdAt: $array['createdAt'] ?? '',
66+
updatedAt: $array['updatedAt'] ?? '',
67+
);
68+
}
69+
70+
public function getType(): string
71+
{
72+
return Column::TYPE_POINT;
73+
}
74+
}

0 commit comments

Comments
 (0)