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