Commit 345b7d33 authored by Brion Vibber's avatar Brion Vibber

some sorta vaguely working bits

parent 9ced8af8
This diff is collapsed.
......@@ -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) {
......@@ -251,7 +256,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';
}
/**
......@@ -287,14 +301,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';
......
......@@ -581,7 +581,7 @@ class Schema
$this->appendAlterAddForeign($phrase, $keyName, $def['foreign keys'][$keyName]);
}
$this->appendAlterExtras($phrase, $tableName);
$this->appendAlterExtras($phrase, $tableName, $def);
if (count($phrase) > 0) {
$sql = 'ALTER TABLE ' . $tableName . ' ' . implode(",\n", $phrase);
......@@ -702,7 +702,7 @@ class Schema
$phrase[] = 'DROP FOREIGN KEY ' . $keyName;
}
function appendAlterExtras(array &$phrase, $tableName)
function appendAlterExtras(array &$phrase, $tableName, array $def)
{
// no-op
}
......
......@@ -37,7 +37,6 @@ class SchemaUpdater
public function __construct($schema)
{
$this->schema = $schema;
$this->conn = $conn;
$this->checksums = $this->getChecksums();
}
......@@ -51,13 +50,15 @@ class SchemaUpdater
}
/**
* Go ping em!
*
* @fixme handle tables that belong on different database servers...?
*/
public function checkTables()
public function checkSchema()
{
$checksums = $this->checksums;
foreach ($this->tables as $table => $def) {
$checksum = $this->tableChecksum($def);
$checksum = $this->checksum($def);
if (empty($checksums[$table])) {
common_log(LOG_DEBUG, "No previous schema_version for $table: updating to $checksum");
} else if ($checksums[$table] == $checksum) {
......@@ -66,10 +67,10 @@ class SchemaUpdater
} else {
common_log(LOG_DEBUG, "Last schema_version for $table is {$checksums[$table]}: updating to $checksum");
}
$this->conn->query('BEGIN');
//$this->conn->query('BEGIN');
$this->schema->ensureTable($table, $def);
$this->saveChecksum($table, $checksum);
$this->conn->commit();
//$this->conn->commit();
}
}
......
......@@ -27,4 +27,18 @@ END_OF_CHECKSCHEMA_HELP;
require_once INSTALLDIR.'/scripts/commandline.inc';
function tableDefs()
{
$schema = array();
require INSTALLDIR.'/db/core.php';
return $schema;
}
$schema = Schema::get();
$schemaUpdater = new SchemaUpdater($schema);
foreach (tableDefs() as $table => $def) {
$schemaUpdater->register($table, $def);
}
$schemaUpdater->checkSchema();
Event::handle('CheckSchema');
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment