Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore comment hint (useful for enumtype declaration) #6444

Open
wants to merge 5 commits into
base: 4.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Schema/AbstractSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use function array_map;
use function array_values;
use function count;
use function preg_match;
use function strtolower;

/**
Expand Down Expand Up @@ -129,6 +130,21 @@
);
}

/**
* Given a table comment this method tries to extract a typehint for Doctrine Type, or returns
* the type given as default.
*
* @internal This method should be only used from within the AbstractSchemaManager class hierarchy.
*/
public function extractDoctrineTypeFromComment(?string $comment, string $currentType): string
{
if ($comment !== null && preg_match('(\(DC2Type:(((?!\)).)+)\))', $comment, $match) === 1) {
return $match[1];

Check warning on line 142 in src/Schema/AbstractSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/AbstractSchemaManager.php#L142

Added line #L142 was not covered by tests
}

return $currentType;
}

/**
* Returns true if all the given tables exist.
*
Expand Down
1 change: 1 addition & 0 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
$precision = null;

$type = $this->platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'] ?? null, $type);

Check warning on line 136 in src/Schema/MySQLSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/MySQLSchemaManager.php#L136

Added line #L136 was not covered by tests

switch ($dbType) {
case 'char':
Expand Down
1 change: 1 addition & 0 deletions src/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
}

$type = $this->platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'] ?? null, $type);

Check warning on line 138 in src/Schema/OracleSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/OracleSchemaManager.php#L138

Added line #L138 was not covered by tests

switch ($dbType) {
case 'number':
Expand Down
1 change: 1 addition & 0 deletions src/Schema/PostgreSQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@
}

$type = $this->platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'] ?? null, $type);

Check warning on line 276 in src/Schema/PostgreSQLSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/PostgreSQLSchemaManager.php#L276

Added line #L276 was not covered by tests

switch ($dbType) {
case 'smallint':
Expand Down
1 change: 1 addition & 0 deletions src/Schema/SQLServerSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column
}

$type = $this->platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'] ?? null, $type);

$options = [
'fixed' => $fixed,
Expand Down
4 changes: 3 additions & 1 deletion src/Schema/SQLiteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@
$unsigned = true;
}

$type = $this->platform->getDoctrineTypeMapping($dbType);
$type = $this->platform->getDoctrineTypeMapping($dbType);
$type = $this->extractDoctrineTypeFromComment($tableColumn['comment'] ?? null, $type);

Check warning on line 245 in src/Schema/SQLiteSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/SQLiteSchemaManager.php#L244-L245

Added lines #L244 - L245 were not covered by tests

$default = $tableColumn['dflt_value'];
if ($default === 'NULL') {
$default = null;
Expand Down