]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/mysqlschema.php
"Notice posted" message in Ajax title for NewnoticeAction
[quix0rs-gnu-social.git] / lib / mysqlschema.php
index b21008518bfea250cb4ef9403b303a4248f7ebc9..435ba4e3a95f57f3ca0ba314db4fb483d0ca0b83 100644 (file)
@@ -117,9 +117,14 @@ class MysqlSchema extends Schema
                 $field['not null'] = true;
             }
             if ($row['COLUMN_DEFAULT'] !== null) {
-                $field['default'] = $row['COLUMN_DEFAULT'];
-                if ($this->isNumericType($type)) {
-                    $field['default'] = intval($field['default']);
+                // Hack for timestamp cols
+                if ($type == 'timestamp' && $row['COLUMN_DEFAULT'] == 'CURRENT_TIMESTAMP') {
+                    // skip
+                } else {
+                    $field['default'] = $row['COLUMN_DEFAULT'];
+                    if ($this->isNumericType($type)) {
+                        $field['default'] = intval($field['default']);
+                    }
                 }
             }
             if ($row['COLUMN_KEY'] !== null) {
@@ -239,6 +244,20 @@ class MysqlSchema extends Schema
         return $this->fetchQueryData($sql);
     }
 
+    /**
+     * Append an SQL statement with an index definition for a full-text search
+     * index over one or more columns on a table.
+     *
+     * @param array $statements
+     * @param string $table
+     * @param string $name
+     * @param array $def
+     */
+    function appendCreateFulltextIndex(array &$statements, $table, $name, array $def)
+    {
+        $statements[] = "CREATE FULLTEXT INDEX $name ON $table " . $this->buildIndexList($def);
+    }
+
     /**
      * Close out a 'create table' SQL statement.
      *
@@ -251,7 +270,16 @@ class MysqlSchema extends Schema
      */
     function endCreateTable($name, array $def)
     {
-        return ") ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_bin";
+        $engine = $this->preferredEngine($def);
+        return ") ENGINE=$engine CHARACTER SET utf8 COLLATE utf8_bin";
+    }
+    
+    function preferredEngine($def)
+    {
+        if (!empty($def['fulltext indexes'])) {
+            return 'MyISAM';
+        }
+        return 'InnoDB';
     }
 
     /**
@@ -270,6 +298,16 @@ class MysqlSchema extends Schema
         return "{$tableName}_{$columnName}_idx";
     }
 
+    /**
+     * MySQL doesn't take 'DROP CONSTRAINT', need to treat primary keys as
+     * if they were indexes here, but can use 'PRIMARY KEY' special name.
+     *
+     * @param array $phrase
+     */
+    function appendAlterDropPrimary(array &$phrase)
+    {
+        $phrase[] = 'DROP PRIMARY KEY';
+    }
 
     /**
      * MySQL doesn't take 'DROP CONSTRAINT', need to treat unique keys as
@@ -287,14 +325,15 @@ class MysqlSchema extends Schema
      * Throw some table metadata onto the ALTER TABLE if we have a mismatch
      * in expected type, collation.
      */
-    function appendAlterExtras(array &$phrase, $tableName)
+    function appendAlterExtras(array &$phrase, $tableName, array $def)
     {
         // Check for table properties: make sure we're using a sane
         // engine type and charset/collation.
         // @fixme make the default engine configurable?
         $oldProps = $this->getTableProperties($tableName, array('ENGINE', 'TABLE_COLLATION'));
-        if (strtolower($oldProps['ENGINE']) != 'innodb') {
-            $phrase[] = 'ENGINE=InnoDB';
+        $engine = $this->preferredEngine($def);
+        if (strtolower($oldProps['ENGINE']) != strtolower($engine)) {
+            $phrase[] = "ENGINE=$engine";
         }
         if (strtolower($oldProps['TABLE_COLLATION']) != 'utf8_bin') {
             $phrase[] = 'DEFAULT CHARSET=utf8';
@@ -372,7 +411,14 @@ class MysqlSchema extends Schema
             $vals = array_map(array($this, 'quote'), $column['enum']);
             return 'enum(' . implode(',', $vals) . ')';
         } else if ($this->_isString($column)) {
-            return parent::typeAndSize($column) . ' CHARSET utf8';
+            $col = parent::typeAndSize($column);
+            if (!empty($column['charset'])) {
+                $col .= ' CHARSET ' . $column['charset'];
+            }
+            if (!empty($column['collate'])) {
+                $col .= ' COLLATE ' . $column['collate'];
+            }
+            return $col;
         } else {
             return parent::typeAndSize($column);
         }
@@ -400,8 +446,9 @@ class MysqlSchema extends Schema
             $col['type'] = $this->mapType($col);
             unset($col['size']);
         }
-        // @fixme add foreign-key support for MySQL
-        unset($tableDef['foreign keys']);
+        if (!common_config('db', 'mysql_foreign_keys')) {
+            unset($tableDef['foreign keys']);
+        }
         return $tableDef;
     }
 }