diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mysqlschema.php | 23 | ||||
-rw-r--r-- | lib/pgsqlschema.php | 4 | ||||
-rw-r--r-- | lib/schema.php | 24 |
3 files changed, 40 insertions, 11 deletions
diff --git a/lib/mysqlschema.php b/lib/mysqlschema.php index 400a7ee59..25f0e52f1 100644 --- a/lib/mysqlschema.php +++ b/lib/mysqlschema.php @@ -96,18 +96,21 @@ class MysqlSchema extends Schema // warning -- 'unsigned' attr on numbers isn't given in DATA_TYPE and friends. // It is stuck in on COLUMN_TYPE though (eg 'bigint(20) unsigned') + /* list($type, $size) = $this->reverseMapType($row['DATA_TYPE']); $field['type'] = $type; if ($size !== null) { $field['size'] = $size; } + */ + $field['type'] = $type = $row['DATA_TYPE']; if ($type == 'char' || $type == 'varchar') { if ($row['CHARACTER_MAXIMUM_LENGTH'] !== null) { $field['length'] = intval($row['CHARACTER_MAXIMUM_LENGTH']); } } - if ($type == 'numeric') { + if ($type == 'decimal') { // Other int types may report these values, but they're irrelevant. // Just ignore them! if ($row['NUMERIC_PRECISION'] !== null) { @@ -137,7 +140,7 @@ class MysqlSchema extends Schema $extra = $row['EXTRA']; if ($extra) { if (preg_match('/(^|\s)auto_increment(\s|$)/i', $extra)) { - $field['type'] = 'serial'; + $field['auto_increment'] = true; } // $row['EXTRA'] may contain 'on update CURRENT_TIMESTAMP' // ^ ...... how to specify? @@ -446,7 +449,8 @@ class MysqlSchema extends Schema $line = array(); $line[] = parent::columnSql($cd); - if ($cd['type'] == 'serial') { + // This'll have been added from our transform of 'serial' type + if (!empty($cd['auto_increment'])) { $line[] = 'auto_increment'; } @@ -489,6 +493,7 @@ class MysqlSchema extends Schema * @param string $type * @return array ($type, $size) -- $size may be null */ + /* protected function reverseMapType($type) { $type = strtolower($type); @@ -511,6 +516,7 @@ class MysqlSchema extends Schema return array($type, null); } } + */ function typeAndSize($column) { @@ -535,6 +541,17 @@ class MysqlSchema extends Schema */ function filterDef(array $tableDef) { + foreach ($tableDef['fields'] as $name => &$col) { + if ($col['type'] == 'serial') { + $col['type'] = 'int'; + $col['auto_increment'] = true; + } + if ($col['type'] == 'datetime' && isset($col['default']) && $col['default'] == 'CURRENT_TIMESTAMP') { + $col['type'] = 'timestamp'; + } + $col['type'] = $this->mapType($col); + unset($col['size']); + } // @fixme add foreign-key support for MySQL unset($tableDef['foreign keys']); return $tableDef; diff --git a/lib/pgsqlschema.php b/lib/pgsqlschema.php index 4fde80b55..ca1853494 100644 --- a/lib/pgsqlschema.php +++ b/lib/pgsqlschema.php @@ -421,12 +421,16 @@ class PgsqlSchema extends Schema // No convenient support for field descriptions unset($col['description']); + /* if (isset($col['size'])) { // Don't distinguish between tinyint and int. if ($col['size'] == 'tiny' && $col['type'] == 'int') { unset($col['size']); } } + */ + $col['type'] = $this->mapType($col); + unset($col['size']); } return $tableDef; } diff --git a/lib/schema.php b/lib/schema.php index c9a0fb434..16fb50225 100644 --- a/lib/schema.php +++ b/lib/schema.php @@ -485,7 +485,7 @@ class Schema return $this->buildCreateTable($tableName, $def); } - $old = $this->filterDef($old); + //$old = $this->filterDef($old); $def = $this->filterDef($def); // @fixme check if not present @@ -749,15 +749,17 @@ class Schema function typeAndSize($column) { - $type = $this->mapType($column); + //$type = $this->mapType($column); + $type = $column['type']; + if (isset($column['size'])) { + $type = $column['size'] . $type; + } $lengths = array(); - if ($column['type'] == 'numeric') { - if (isset($column['precision'])) { - $lengths[] = $column['precision']; - if (isset($column['scale'])) { - $lengths[] = $column['scale']; - } + if (isset($column['precision'])) { + $lengths[] = $column['precision']; + if (isset($column['scale'])) { + $lengths[] = $column['scale']; } } else if (isset($column['length'])) { $lengths[] = $column['length']; @@ -778,6 +780,12 @@ class Schema */ protected function reverseMapType($type) { + $sizes = array('tiny', 'small', 'medium', 'big'); + foreach ($sizes as $prefix) { + if (substr($type, 0, strlen($prefix)) == $prefix) { + return array(substr($type, strlen($prefix)), $prefix); + } + } return array($type, null); } |