Skip to content

Commit 46baee4

Browse files
authored
Merge pull request #7 from giagara/main
Fix int(11) for mysql
2 parents ad10660 + 018f629 commit 46baee4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Resolvers/SchemaRulesResolverMySql.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,14 @@ protected function generateColumnRules(stdClass $column): array
9090
$columnRules[] = "integer";
9191
$sign = ($type->contains('unsigned')) ? 'unsigned' : 'signed' ;
9292
$intType = $type->before(' unsigned')->__toString();
93+
94+
// prevent int(xx) for mysql
95+
$intType = preg_replace("/\([^)]+\)/", "", $intType);
96+
97+
if(!array_key_exists($intType, self::$integerTypes)){
98+
$intType = "int";
99+
}
100+
93101
$columnRules[] = "min:".self::$integerTypes[$intType][$sign][0];
94102
$columnRules[] = "max:".self::$integerTypes[$intType][$sign][1];
95103

@@ -109,7 +117,7 @@ protected function generateColumnRules(stdClass $column): array
109117
$columnRules[] = 'in:'.implode(',', $matches[1]);
110118

111119
break;
112-
case $type == 'year':
120+
case $type->contains('year'):
113121
$columnRules[] = 'integer';
114122
$columnRules[] = 'min:1901';
115123
$columnRules[] = 'max:2155';

0 commit comments

Comments
 (0)