Skip to content

Commit 63f31ac

Browse files
Added bigInteger handling within RegistryModifier
1 parent da112a6 commit 63f31ac

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/Schema/RegistryModifier.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ class RegistryModifier
3232
'smallInteger',
3333
'bigInteger',
3434
];
35+
protected const BIG_INTEGER_TYPES = [
36+
'bigint',
37+
'bigInteger',
38+
];
3539
protected const DATETIME_TYPES = ['datetime', 'datetime2'];
3640
protected const INT_COLUMN = AbstractColumn::INT;
3741
protected const STRING_COLUMN = AbstractColumn::STRING;
42+
protected const BIG_INTEGER_COLUMN = 'bigInteger';
3843
protected const DATETIME_COLUMN = 'datetime';
3944
protected const UUID_COLUMN = 'uuid';
4045

@@ -58,6 +63,13 @@ public static function isIntegerType(string $type): bool
5863
return \in_array($matches['type'], self::INTEGER_TYPES, true);
5964
}
6065

66+
public static function isBigIntegerType(string $type): bool
67+
{
68+
\preg_match(self::DEFINITION, $type, $matches);
69+
70+
return \in_array($matches['type'], self::BIG_INTEGER_TYPES, true);
71+
}
72+
6173
public static function isDatetimeType(string $type): bool
6274
{
6375
\preg_match(self::DEFINITION, $type, $matches);
@@ -123,6 +135,32 @@ public function addIntegerColumn(string $columnName, string $fieldName, int|null
123135
return $this->table->column($columnName)->type(self::INT_COLUMN);
124136
}
125137

138+
public function addBigIntegerColumn(
139+
string $columnName,
140+
string $fieldName,
141+
int|null $generated = null,
142+
): AbstractColumn {
143+
if ($this->fields->has($fieldName)) {
144+
if (! static::isBigIntegerType($this->fields->get($fieldName)->getType())) {
145+
throw new BehaviorCompilationException(\sprintf('Field %s must be of type big integer.', $fieldName));
146+
}
147+
$this->validateColumnName($fieldName, $columnName);
148+
$this->fields->get($fieldName)->setGenerated($generated);
149+
150+
return $this->table->column($columnName);
151+
}
152+
153+
$field = (new Field())
154+
->setColumn($columnName)
155+
->setType(self::BIG_INTEGER_COLUMN)
156+
->setTypecast('int')
157+
->setGenerated($generated);
158+
159+
$this->fields->set($fieldName, $field);
160+
161+
return $this->table->column($columnName)->type(self::BIG_INTEGER_COLUMN);
162+
}
163+
126164
public function addStringColumn(string $columnName, string $fieldName, int|null $generated = null): AbstractColumn
127165
{
128166
if ($this->fields->has($fieldName)) {

0 commit comments

Comments
 (0)