function handleCreateTable(&$schema, &$input, &$line)
{
    if (preg_match('/^CREATE\\ TABLE\\ ([a-z]*\\.)?([a-z_]+)$/', $line, $match) == 1) {
        $tabName = $match[2];
        // eat (
        getNextLine($input);
        $lastcolumn = false;
        while ($line = getNextLine($input)) {
            $comment = false;
            while ($commentLine = getComment($line)) {
                $comment = $comment . "\n" . $commentLine;
                $line = getNextLine($input);
            }
            $column = getColumnName($line);
            if ($column) {
                $lastcolumn = $column;
            }
            if (!isset($schema[$tabName]['fields'][$lastcolumn])) {
                $schema[$tabName]['fields'][$lastcolumn] = array('description' => "No description for column {$lastcolumn} available, please fix");
            }
            if ($comment) {
                $schema[$tabName]['fields'][$lastcolumn]['description'] = $comment;
            }
            if (getColumnType($schema[$tabName], $lastcolumn, $line)) {
                continue;
            }
            if (preg_match('/^\\) WITHOUT OIDS;/', $line)) {
                continue;
            }
            if ($uniqueconstraints = getUniqueConstraints($line)) {
                $keyname = $uniqueconstraints['name'];
                $schema[$tabName]['unique keys'][$keyname] = $uniqueconstraints['keys'];
                continue;
            }
            if ($primaryKey = getPrimaryKey($line)) {
                $schema[$tabName]['primary key'] = $primaryKey;
                continue;
            }
            fwrite(STDERR, "Unknown statements within CREATE TABLE: {$line}\n");
        }
        return true;
    }
    return false;
}
Exemple #2
0
if ($db->get_type() == DB::MYSQL && checkIfTableExists($db, "reputation") && getColumnType($db, 'reputation', 'charid') != 'bigint(20)') {
    upgrade($db, "ALTER TABLE reputation CHANGE COLUMN charid charid BIGINT NOT NULL");
}
if ($db->get_type() == DB::MYSQL && checkIfTableExists($db, "reputation") && getColumnType($db, 'reputation', 'by_charid') != 'bigint(20)') {
    upgrade($db, "ALTER TABLE reputation CHANGE COLUMN by_charid by_charid BIGINT NOT NULL");
}
if ($db->get_type() == DB::MYSQL && checkIfTableExists($db, "tracked_users_<myname>") && getColumnType($db, 'tracked_users_<myname>', 'uid') != 'bigint(20)') {
    upgrade($db, "ALTER TABLE tracked_users_<myname> CHANGE COLUMN uid uid BIGINT NOT NULL");
}
if ($db->get_type() == DB::MYSQL && checkIfTableExists($db, "tracking_<myname>") && getColumnType($db, 'tracking_<myname>', 'uid') != 'bigint(20)') {
    upgrade($db, "ALTER TABLE tracking_<myname> CHANGE COLUMN uid uid BIGINT NOT NULL");
}
if ($db->get_type() == DB::MYSQL && checkIfTableExists($db, "name_history") && getColumnType($db, 'name_history', 'charid') != 'bigint(20)') {
    upgrade($db, "ALTER TABLE name_history CHANGE COLUMN charid charid BIGINT NOT NULL");
}
// update guild ids that are blank to be 0
if ($db->get_type() == DB::SQLITE && checkIfTableExists($db, "players")) {
    upgrade($db, "UPDATE players SET guild_id = 0 WHERE guild_id = ''");
}
// update prof_title from varchar(20) to varchar(50)
if ($db->get_type() == DB::MYSQL && checkIfTableExists($db, "players") && getColumnType($db, 'players', 'prof_title') != 'varchar(50)') {
    upgrade($db, "ALTER TABLE players CHANGE COLUMN prof_title prof_title VARCHAR(50) NOT NULL DEFAULT ''");
}
// update cmd_alias.cmd from varchar(25) to varchar(255)
if ($db->get_type() == DB::MYSQL && checkIfTableExists($db, "cmd_alias_<myname>") && getColumnType($db, 'cmd_alias_<myname>', 'cmd') != 'varchar(255)') {
    upgrade($db, "ALTER TABLE cmd_alias_<myname> CHANGE COLUMN cmd cmd VARCHAR(255) NOT NULL");
}
// add timers.alerts column
if (!checkIfColumnExists($db, "timers_<myname>", 'alerts')) {
    upgrade($db, "ALTER TABLE timers_<myname> ADD COLUMN alerts TEXT");
}