Skip to content

Commit 8431f1f

Browse files
removed generic attribute and using Attribute as the base
1 parent e4872c1 commit 8431f1f

3 files changed

Lines changed: 34 additions & 101 deletions

File tree

src/Migration/Resources/Database/Attribute.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Utopia\Migration\Resource;
66
use Utopia\Migration\Transfer;
77

8-
abstract class Attribute extends Resource
8+
class Attribute extends Resource
99
{
1010
public const TYPE_STRING = 'string';
1111
public const TYPE_INTEGER = 'integer';
@@ -28,6 +28,7 @@ abstract class Attribute extends Resource
2828
/**
2929
* @param string $key
3030
* @param Table $table
31+
* @param string $fieldType The actual field type (e.g., 'string', 'integer', 'email')
3132
* @param int $size
3233
* @param bool $required
3334
* @param mixed|null $default
@@ -43,6 +44,7 @@ abstract class Attribute extends Resource
4344
public function __construct(
4445
protected readonly string $key,
4546
protected readonly Table $table,
47+
protected readonly string $fieldType = '',
4648
protected readonly int $size = 0,
4749
protected readonly bool $required = false,
4850
protected readonly mixed $default = null,
@@ -85,7 +87,36 @@ public static function getName(): string
8587
return Resource::TYPE_ATTRIBUTE;
8688
}
8789

88-
abstract public function getType(): string;
90+
public function getType(): string
91+
{
92+
return $this->fieldType;
93+
}
94+
95+
/**
96+
* Convert a Column resource to an Attribute resource.
97+
*
98+
* @param Column $column
99+
* @return self
100+
*/
101+
public static function fromColumn(Column $column): self
102+
{
103+
return new self(
104+
$column->getKey(),
105+
$column->getTable(),
106+
$column->getType(),
107+
$column->getSize(),
108+
$column->isRequired(),
109+
$column->getDefault(),
110+
$column->isArray(),
111+
$column->isSigned(),
112+
$column->getFormat(),
113+
$column->getFormatOptions(),
114+
$column->getFilters(),
115+
$column->getOptions(),
116+
$column->getCreatedAt(),
117+
$column->getUpdatedAt()
118+
);
119+
}
89120

90121
public function getGroup(): string
91122
{

src/Migration/Resources/Database/Column.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,6 @@ public function &getOptions(): array
170170
*/
171171
public function getAttribute(): Attribute
172172
{
173-
return GenericAttribute::fromColumn($this);
173+
return Attribute::fromColumn($this);
174174
}
175175
}

src/Migration/Resources/Database/GenericAttribute.php

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)