forked from GNUsocial/gnu-social
some more tweaking to do the mappings during filterDef; not totally sure I like it
This commit is contained in:
parent
fa50ab2a94
commit
eb93bdbb03
@ -182,7 +182,7 @@ $schema['notice'] = array(
|
|||||||
'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'),
|
'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)'),
|
'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'),
|
'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)'),
|
'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'),
|
'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"'),
|
'source' => array('type' => 'varchar', 'length' => 32, 'description' => 'source of comment, like "web", "im", or "clientname"'),
|
||||||
@ -871,8 +871,8 @@ $schema['deleted_notice'] = array(
|
|||||||
|
|
||||||
$schema['config'] = array(
|
$schema['config'] = array(
|
||||||
'fields' => array(
|
'fields' => array(
|
||||||
'section' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'configuration section'),
|
'section' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'default' => '', 'description' => 'configuration section'),
|
||||||
'setting' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'configuration setting'),
|
'setting' => array('type' => 'varchar', 'length' => 32, 'not null' => true, 'default' => '', 'description' => 'configuration setting'),
|
||||||
'value' => array('type' => 'varchar', 'length' => 255, 'description' => 'configuration value'),
|
'value' => array('type' => 'varchar', 'length' => 255, 'description' => 'configuration value'),
|
||||||
),
|
),
|
||||||
'primary key' => array('section', 'setting'),
|
'primary key' => array('section', 'setting'),
|
||||||
|
@ -96,18 +96,21 @@ class MysqlSchema extends Schema
|
|||||||
|
|
||||||
// warning -- 'unsigned' attr on numbers isn't given in DATA_TYPE and friends.
|
// 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')
|
// It is stuck in on COLUMN_TYPE though (eg 'bigint(20) unsigned')
|
||||||
|
/*
|
||||||
list($type, $size) = $this->reverseMapType($row['DATA_TYPE']);
|
list($type, $size) = $this->reverseMapType($row['DATA_TYPE']);
|
||||||
$field['type'] = $type;
|
$field['type'] = $type;
|
||||||
if ($size !== null) {
|
if ($size !== null) {
|
||||||
$field['size'] = $size;
|
$field['size'] = $size;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
$field['type'] = $type = $row['DATA_TYPE'];
|
||||||
|
|
||||||
if ($type == 'char' || $type == 'varchar') {
|
if ($type == 'char' || $type == 'varchar') {
|
||||||
if ($row['CHARACTER_MAXIMUM_LENGTH'] !== null) {
|
if ($row['CHARACTER_MAXIMUM_LENGTH'] !== null) {
|
||||||
$field['length'] = intval($row['CHARACTER_MAXIMUM_LENGTH']);
|
$field['length'] = intval($row['CHARACTER_MAXIMUM_LENGTH']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($type == 'numeric') {
|
if ($type == 'decimal') {
|
||||||
// Other int types may report these values, but they're irrelevant.
|
// Other int types may report these values, but they're irrelevant.
|
||||||
// Just ignore them!
|
// Just ignore them!
|
||||||
if ($row['NUMERIC_PRECISION'] !== null) {
|
if ($row['NUMERIC_PRECISION'] !== null) {
|
||||||
@ -137,7 +140,7 @@ class MysqlSchema extends Schema
|
|||||||
$extra = $row['EXTRA'];
|
$extra = $row['EXTRA'];
|
||||||
if ($extra) {
|
if ($extra) {
|
||||||
if (preg_match('/(^|\s)auto_increment(\s|$)/i', $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'
|
// $row['EXTRA'] may contain 'on update CURRENT_TIMESTAMP'
|
||||||
// ^ ...... how to specify?
|
// ^ ...... how to specify?
|
||||||
@ -446,7 +449,8 @@ class MysqlSchema extends Schema
|
|||||||
$line = array();
|
$line = array();
|
||||||
$line[] = parent::columnSql($cd);
|
$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';
|
$line[] = 'auto_increment';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -489,6 +493,7 @@ class MysqlSchema extends Schema
|
|||||||
* @param string $type
|
* @param string $type
|
||||||
* @return array ($type, $size) -- $size may be null
|
* @return array ($type, $size) -- $size may be null
|
||||||
*/
|
*/
|
||||||
|
/*
|
||||||
protected function reverseMapType($type)
|
protected function reverseMapType($type)
|
||||||
{
|
{
|
||||||
$type = strtolower($type);
|
$type = strtolower($type);
|
||||||
@ -511,6 +516,7 @@ class MysqlSchema extends Schema
|
|||||||
return array($type, null);
|
return array($type, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
function typeAndSize($column)
|
function typeAndSize($column)
|
||||||
{
|
{
|
||||||
@ -535,6 +541,17 @@ class MysqlSchema extends Schema
|
|||||||
*/
|
*/
|
||||||
function filterDef(array $tableDef)
|
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
|
// @fixme add foreign-key support for MySQL
|
||||||
unset($tableDef['foreign keys']);
|
unset($tableDef['foreign keys']);
|
||||||
return $tableDef;
|
return $tableDef;
|
||||||
|
@ -421,12 +421,16 @@ class PgsqlSchema extends Schema
|
|||||||
// No convenient support for field descriptions
|
// No convenient support for field descriptions
|
||||||
unset($col['description']);
|
unset($col['description']);
|
||||||
|
|
||||||
|
/*
|
||||||
if (isset($col['size'])) {
|
if (isset($col['size'])) {
|
||||||
// Don't distinguish between tinyint and int.
|
// Don't distinguish between tinyint and int.
|
||||||
if ($col['size'] == 'tiny' && $col['type'] == 'int') {
|
if ($col['size'] == 'tiny' && $col['type'] == 'int') {
|
||||||
unset($col['size']);
|
unset($col['size']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
$col['type'] = $this->mapType($col);
|
||||||
|
unset($col['size']);
|
||||||
}
|
}
|
||||||
return $tableDef;
|
return $tableDef;
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ class Schema
|
|||||||
return $this->buildCreateTable($tableName, $def);
|
return $this->buildCreateTable($tableName, $def);
|
||||||
}
|
}
|
||||||
|
|
||||||
$old = $this->filterDef($old);
|
//$old = $this->filterDef($old);
|
||||||
$def = $this->filterDef($def);
|
$def = $this->filterDef($def);
|
||||||
|
|
||||||
// @fixme check if not present
|
// @fixme check if not present
|
||||||
@ -749,15 +749,17 @@ class Schema
|
|||||||
|
|
||||||
function typeAndSize($column)
|
function typeAndSize($column)
|
||||||
{
|
{
|
||||||
$type = $this->mapType($column);
|
//$type = $this->mapType($column);
|
||||||
|
$type = $column['type'];
|
||||||
|
if (isset($column['size'])) {
|
||||||
|
$type = $column['size'] . $type;
|
||||||
|
}
|
||||||
$lengths = array();
|
$lengths = array();
|
||||||
|
|
||||||
if ($column['type'] == 'numeric') {
|
if (isset($column['precision'])) {
|
||||||
if (isset($column['precision'])) {
|
$lengths[] = $column['precision'];
|
||||||
$lengths[] = $column['precision'];
|
if (isset($column['scale'])) {
|
||||||
if (isset($column['scale'])) {
|
$lengths[] = $column['scale'];
|
||||||
$lengths[] = $column['scale'];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (isset($column['length'])) {
|
} else if (isset($column['length'])) {
|
||||||
$lengths[] = $column['length'];
|
$lengths[] = $column['length'];
|
||||||
@ -778,6 +780,12 @@ class Schema
|
|||||||
*/
|
*/
|
||||||
protected function reverseMapType($type)
|
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);
|
return array($type, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ function dumpDiff($tableName, $filter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($filter) {
|
if ($filter) {
|
||||||
$old = $schema->filterDef($old);
|
//$old = $schema->filterDef($old);
|
||||||
$def = $schema->filterDef($def);
|
$def = $schema->filterDef($def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user