'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'),
'url' => array('type' => 'varchar', 'length' => 255, 'description' => 'URL of any attachment (image, video, bookmark, whatever)'),
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
- 'modified' => array('type' => 'timestamp', 'description' => 'date this record was modified'),
+ 'modified' => array('type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'),
'reply_to' => array('type' => 'int', 'description' => 'notice replied to (usually a guess)'),
'is_local' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'notice was generated by a user'),
'source' => array('type' => 'varchar', 'length' => 32, 'description' => 'source of comment, like "web", "im", or "clientname"'),
$schema['config'] = array(
'fields' => array(
- 'section' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'configuration section'),
- 'setting' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'configuration setting'),
+ 'section' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'default' => '', 'description' => 'configuration section'),
+ 'setting' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'default' => '', 'description' => 'configuration setting'),
'value' => array('type' => 'varchar', 'length' => 255, 'description' => 'configuration value'),
),
'primary key' => array('section', 'setting'),
// 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) {
$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?
$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';
}
* @param string $type
* @return array ($type, $size) -- $size may be null
*/
+ /*
protected function reverseMapType($type)
{
$type = strtolower($type);
return array($type, null);
}
}
+ */
function typeAndSize($column)
{
*/
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;
// 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;
}
return $this->buildCreateTable($tableName, $def);
}
- $old = $this->filterDef($old);
+ //$old = $this->filterDef($old);
$def = $this->filterDef($def);
// @fixme check if not present
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'];
*/
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);
}
}
if ($filter) {
- $old = $schema->filterDef($old);
+ //$old = $schema->filterDef($old);
$def = $schema->filterDef($def);
}