Skip to content

Commit

Permalink
create "bigint" column for "integer" in Migrator
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed May 24, 2024
1 parent 1418be0 commit 74e1b74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Schema/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,18 +240,22 @@ public function field(string $fieldName, array $options = []): self
$refType = $options['ref_type'] ?? self::REF_TYPE_NONE;
unset($options['ref_type']);

if ($type === 'integer') {
$type = 'bigint';
}

$column = $this->table->addColumn($this->getDatabasePlatform()->quoteSingleIdentifier($fieldName), $type);

if (($options['nullable'] ?? true) && $refType !== self::REF_TYPE_PRIMARY) {
$column->setNotnull(false);
}

if ($type === 'integer' && $refType !== self::REF_TYPE_NONE) {
if ($type === 'bigint' && $refType !== self::REF_TYPE_NONE) {
$column->setUnsigned(true);
}

// TODO remove, hack for createForeignKey so ID columns are unsigned
if ($type === 'integer' && str_ends_with($fieldName, '_id')) {
if ($type === 'bigint' && str_ends_with($fieldName, '_id')) {
$column->setUnsigned(true);
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Schema/MigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ public function testIntrospectTableToModelBasic(): void
];
}

// "integer" DBAL type in Migrator is mapped to "bigint"
$expectedFields['id']['type'] = 'bigint';
$expectedFields['bar']['type'] = 'bigint';

// TODO fix DBAL column comment type hint
// see PlatformFixColumnCommentTypeHintTrait trait used for MSSQL and Oracle platforms
if ($this->getDatabasePlatform() instanceof SQLitePlatform) {
Expand Down

0 comments on commit 74e1b74

Please sign in to comment.