Skip to content

Commit 6d92c14

Browse files
committed
varchar
1 parent bf3074e commit 6d92c14

File tree

4 files changed

+113
-0
lines changed

4 files changed

+113
-0
lines changed

src/Migration/Destinations/Appwrite.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ protected function createColumn(Column $resource): bool
471471
Column::TYPE_LINE => UtopiaDatabase::VAR_LINESTRING,
472472
Column::TYPE_POLYGON => UtopiaDatabase::VAR_POLYGON,
473473
Column::TYPE_TEXT => UtopiaDatabase::VAR_TEXT,
474+
Column::TYPE_VARCHAR => UtopiaDatabase::VAR_VARCHAR,
474475
Column::TYPE_MEDIUMTEXT => UtopiaDatabase::VAR_MEDIUMTEXT,
475476
Column::TYPE_LONGTEXT => UtopiaDatabase::VAR_LONGTEXT,
476477
default => throw new \Exception('Invalid resource type '.$resource->getType()),

src/Migration/Resources/Database/Column.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ abstract class Column extends Resource
99
{
1010
public const TYPE_STRING = 'string';
1111
public const TYPE_TEXT = 'text';
12+
public const TYPE_VARCHAR = 'varchar';
1213
public const TYPE_MEDIUMTEXT = 'mediumtext';
1314
public const TYPE_LONGTEXT = 'longtext';
1415

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace Utopia\Migration\Resources\Database\Columns;
4+
5+
use Utopia\Database\Database;
6+
use Utopia\Migration\Resources\Database\Column;
7+
use Utopia\Migration\Resources\Database\Table;
8+
9+
class Varchar extends Column
10+
{
11+
public function __construct(
12+
string $key,
13+
Table $table,
14+
bool $required = false,
15+
?string $default = null,
16+
bool $array = false,
17+
int $size = 255,
18+
string $format = '',
19+
string $createdAt = '',
20+
string $updatedAt = ''
21+
) {
22+
parent::__construct(
23+
$key,
24+
$table,
25+
size: $size,
26+
required: $required,
27+
default: $default,
28+
array: $array,
29+
format: $format,
30+
createdAt: $createdAt,
31+
updatedAt: $updatedAt
32+
);
33+
}
34+
35+
/**
36+
* @param array{
37+
* key: string,
38+
* collection?: array{
39+
* database: array{
40+
* id: string,
41+
* name: string,
42+
* },
43+
* name: string,
44+
* id: string,
45+
* documentSecurity: bool,
46+
* permissions: ?array<string>
47+
* },
48+
* table?: array{
49+
* database: array{
50+
* id: string,
51+
* name: string,
52+
* },
53+
* name: string,
54+
* id: string,
55+
* rowSecurity: bool,
56+
* permissions: ?array<string>
57+
* },
58+
* required: bool,
59+
* default: ?string,
60+
* array: bool,
61+
* size: int,
62+
* format: string,
63+
* createdAt: string,
64+
* updatedAt: string,
65+
* } $array
66+
* @return self
67+
*/
68+
public static function fromArray(array $array): self
69+
{
70+
return new self(
71+
$array['key'],
72+
Table::fromArray($array['table'] ?? $array['collection']),
73+
required: $array['required'],
74+
default: $array['default'] ?? null,
75+
array: $array['array'],
76+
size: $array['size'],
77+
format: $array['format'],
78+
createdAt: $array['createdAt'] ?? '',
79+
updatedAt: $array['updatedAt'] ?? '',
80+
);
81+
}
82+
83+
public function getType(): string
84+
{
85+
return Column::TYPE_VARCHAR;
86+
}
87+
88+
public function getSize(): int
89+
{
90+
return $this->size;
91+
}
92+
93+
public function getFormat(): string
94+
{
95+
return $this->format;
96+
}
97+
}

src/Migration/Sources/Appwrite.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Utopia\Migration\Resources\Database\Columns\Relationship;
3737
use Utopia\Migration\Resources\Database\Columns\Text;
3838
use Utopia\Migration\Resources\Database\Columns\URL;
39+
use Utopia\Migration\Resources\Database\Columns\Varchar;
3940
use Utopia\Migration\Resources\Database\Database;
4041
use Utopia\Migration\Resources\Database\Index;
4142
use Utopia\Migration\Resources\Database\Row;
@@ -1094,6 +1095,19 @@ private function exportColumns(int $batchSize): void
10941095
);
10951096
break;
10961097

1098+
case Column::TYPE_VARCHAR:
1099+
$col = new Varchar(
1100+
$column['key'],
1101+
$table,
1102+
required: $column['required'],
1103+
default: $column['default'],
1104+
array: $column['array'],
1105+
size: $column['size'] ?? 255,
1106+
createdAt: $column['$createdAt'] ?? '',
1107+
updatedAt: $column['$updatedAt'] ?? '',
1108+
);
1109+
break;
1110+
10971111
case Column::TYPE_TEXT:
10981112
$col = new RegularText(
10991113
$column['key'],

0 commit comments

Comments
 (0)