diff --git a/src/Model/Table.php b/src/Model/Table.php index a84f877..65882b9 100644 --- a/src/Model/Table.php +++ b/src/Model/Table.php @@ -160,15 +160,12 @@ public function getColumn($name) public function getColumns() { $columns = $this->db->query("SHOW COLUMNS FROM $this->table;") ?: []; - // Sort current db colums by keys (do not use array_walk) - foreach ($columns as &$column) { + foreach ($columns as &$column){ ksort($column); - - if ($column['Default'] === 'CURRENT_TIMESTAMP') - $column['Default'] = 'current_timestamp()'; + $column = $this->validateValue($column); } - + return $columns ?: []; } @@ -277,4 +274,25 @@ public function changeCharset() ($column['Null'] == 'NO' ? 'NOT NULL;' : ';') ); } + + /** + * Validates the value of a column. + * + * @param array $column Column definition array. + * + * @return array The normalized column definition. + */ + public function validateValue($column){ + + if ($column['Default'] === 'CURRENT_TIMESTAMP') + $column['Default'] = 'current_timestamp()'; + + if ($column['Extra'] === 'DEFAULT_GENERATED') + $column['Extra'] = ''; + + if ($column['Type'] === 'int') + $column['Type'] = 'int(11)'; + + return $column; + } } \ No newline at end of file