Skip to content

Commit aa07cf9

Browse files
authored
Merge pull request #148 from utopia-php/text-attributes
Text attributes
2 parents 35df40d + 6d92c14 commit aa07cf9

File tree

11 files changed

+471
-9
lines changed

11 files changed

+471
-9
lines changed

src/Migration/Destinations/Appwrite.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,10 @@ protected function createColumn(Column $resource): bool
470470
Column::TYPE_POINT => UtopiaDatabase::VAR_POINT,
471471
Column::TYPE_LINE => UtopiaDatabase::VAR_LINESTRING,
472472
Column::TYPE_POLYGON => UtopiaDatabase::VAR_POLYGON,
473+
Column::TYPE_TEXT => UtopiaDatabase::VAR_TEXT,
474+
Column::TYPE_VARCHAR => UtopiaDatabase::VAR_VARCHAR,
475+
Column::TYPE_MEDIUMTEXT => UtopiaDatabase::VAR_MEDIUMTEXT,
476+
Column::TYPE_LONGTEXT => UtopiaDatabase::VAR_LONGTEXT,
473477
default => throw new \Exception('Invalid resource type '.$resource->getType()),
474478
};
475479

src/Migration/Resources/Database/Column.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
abstract class Column extends Resource
99
{
1010
public const TYPE_STRING = 'string';
11+
public const TYPE_TEXT = 'text';
12+
public const TYPE_VARCHAR = 'varchar';
13+
public const TYPE_MEDIUMTEXT = 'mediumtext';
14+
public const TYPE_LONGTEXT = 'longtext';
15+
1116
public const TYPE_INTEGER = 'integer';
1217
public const TYPE_FLOAT = 'double';
1318
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 = 2147483647,
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 = 16777215,
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_MEDIUMTEXT;
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 = 65535,
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+
}

0 commit comments

Comments
 (0)