55use Utopia \Migration \Resource ;
66use 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 {
0 commit comments