Skip to content

Commit d7886c0

Browse files
committed
text type
1 parent 35df40d commit d7886c0

File tree

5 files changed

+336
-0
lines changed

5 files changed

+336
-0
lines changed

src/Migration/Resources/Database/Column.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
abstract class Column extends Resource
99
{
1010
public const TYPE_STRING = 'string';
11+
public const TYPE_TEXT = 'text';
12+
public const TYPE_MEDIUMTEXT = 'mediumtext';
13+
public const TYPE_LONGTEXT = 'longtext';
14+
1115
public const TYPE_INTEGER = 'integer';
1216
public const TYPE_FLOAT = 'double';
1317
public const TYPE_BOOLEAN = 'boolean';
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 LongText 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 = Database::LENGTH_KEY,
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_LONGTEXT;
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+
}
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 MediumText 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 = Database::LENGTH_KEY,
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_STRING;
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+
}
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 RegularText 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 = Database::LENGTH_KEY,
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_TEXT;
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: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
use Utopia\Migration\Resources\Database\Columns\Integer;
2929
use Utopia\Migration\Resources\Database\Columns\IP;
3030
use Utopia\Migration\Resources\Database\Columns\Line;
31+
use Utopia\Migration\Resources\Database\Columns\MediumText;
3132
use Utopia\Migration\Resources\Database\Columns\Point;
3233
use Utopia\Migration\Resources\Database\Columns\Polygon;
34+
use Utopia\Migration\Resources\Database\Columns\RegularText;
3335
use Utopia\Migration\Resources\Database\Columns\Relationship;
3436
use Utopia\Migration\Resources\Database\Columns\Text;
3537
use Utopia\Migration\Resources\Database\Columns\URL;
@@ -1090,6 +1092,45 @@ private function exportColumns(int $batchSize): void
10901092
updatedAt: $column['$updatedAt'] ?? '',
10911093
);
10921094
break;
1095+
1096+
case Column::TYPE_TEXT:
1097+
$col = new RegularText(
1098+
$column['key'],
1099+
$table,
1100+
required: $column['required'],
1101+
default: $column['default'],
1102+
array: $column['array'],
1103+
size: $column['size'] ?? 65535,
1104+
createdAt: $column['$createdAt'] ?? '',
1105+
updatedAt: $column['$updatedAt'] ?? '',
1106+
);
1107+
break;
1108+
1109+
case Column::TYPE_MEDIUMTEXT:
1110+
$col = new MediumText(
1111+
$column['key'],
1112+
$table,
1113+
required: $column['required'],
1114+
default: $column['default'],
1115+
array: $column['array'],
1116+
size: $column['size'] ?? 16777215,
1117+
createdAt: $column['$createdAt'] ?? '',
1118+
updatedAt: $column['$updatedAt'] ?? '',
1119+
);
1120+
break;
1121+
1122+
case Column::TYPE_LONGTEXT:
1123+
$col = new MediumText(
1124+
$column['key'],
1125+
$table,
1126+
required: $column['required'],
1127+
default: $column['default'],
1128+
array: $column['array'],
1129+
size: $column['size'] ?? 2147483647,
1130+
createdAt: $column['$createdAt'] ?? '',
1131+
updatedAt: $column['$updatedAt'] ?? '',
1132+
);
1133+
break;
10931134
}
10941135

10951136
if (!isset($col)) {

0 commit comments

Comments
 (0)