Postgres updater stuff, needs review

* Move setup_database() from DatabasePostgres to PostgresInstaller
** Add install step after interwiki for the COMMIT
** Put the table creation test (should we abstract this?) in setupDatabase()
** The leftover stuff in initial_setup() also belongs in setupDatabase(), I think?
This commit is contained in:
Chad Horohoe 2010-11-10 16:06:16 +00:00
parent 9f867044f2
commit c7f9eaf626
4 changed files with 38 additions and 52 deletions

View file

@ -1275,57 +1275,6 @@ SQL;
return $sql;
}
function setup_database() {
global $wgDBmwschema, $wgDBuser;
// Make sure that we can write to the correct schema
// If not, Postgres will happily and silently go to the next search_path item
$ctest = 'mediawiki_test_table';
$safeschema = $this->quote_ident( $wgDBmwschema );
if ( $this->tableExists( $ctest, $wgDBmwschema ) ) {
$this->doQuery( "DROP TABLE $safeschema.$ctest" );
}
$SQL = "CREATE TABLE $safeschema.$ctest(a int)";
$olde = error_reporting( 0 );
$res = $this->doQuery( $SQL );
error_reporting( $olde );
if ( !$res ) {
print '<b>FAILED</b>. Make sure that the user "' . htmlspecialchars( $wgDBuser ) .
'" can write to the schema "' . htmlspecialchars( $wgDBmwschema ) . "\"</li>\n";
dieout( '' ); # Will close the main list <ul> and finish the page.
}
$this->doQuery( "DROP TABLE $safeschema.$ctest" );
$res = $this->sourceFile( "../maintenance/postgres/tables.sql" );
if ( $res === true ) {
print " done.</li>\n";
} else {
print " <b>FAILED</b></li>\n";
dieout( htmlspecialchars( $res ) );
}
echo '<li>Populating interwiki table... ';
# Avoid the non-standard "REPLACE INTO" syntax
$f = fopen( "../maintenance/interwiki.sql", 'r' );
if ( !$f ) {
print '<b>FAILED</b></li>';
dieout( 'Could not find the interwiki.sql file' );
}
# We simply assume it is already empty as we have just created it
$SQL = "INSERT INTO interwiki(iw_prefix,iw_url,iw_local) VALUES ";
while ( !feof( $f ) ) {
$line = fgets( $f, 1024 );
$matches = array();
if ( !preg_match( '/^\s*(\(.+?),(\d)\)/', $line, $matches ) ) {
continue;
}
$this->query( "$SQL $matches[1],$matches[2])" );
}
print " successfully populated.</li>\n";
$this->doQuery( 'COMMIT' );
}
function encodeBlob( $b ) {
return new Blob( pg_escape_bytea( $this->mConn, $b ) );
}

View file

@ -97,9 +97,10 @@ abstract class DatabaseInstaller {
/**
* Connect to the database using the administrative user/password currently
* defined in the session. On success, return the connection, on failure,
* return a Status object.
*
* This may be called multiple times, so the result should be cached.
*
* @return Status
*/
public abstract function getConnection();

View file

@ -461,6 +461,7 @@ Please proceed to the next page.",
'config-install-database' => 'Setting up database',
'config-install-pg-schema-failed' => 'Tables creation failed.
Make sure that the user "$1" can write to the schema "$2".',
'config-install-pg-commit' => 'Committing changes',
'config-install-user' => 'Creating database user',
'config-install-user-failed' => 'Granting permission to user "$1" failed: $2',
'config-install-tables' => 'Creating tables',

View file

@ -107,7 +107,42 @@ class PostgresInstaller extends DatabaseInstaller {
return $status;
}
public function preInstall() {
# Add our user callback to installSteps, right before the tables are created.
$callback = array(
'name' => 'pg-commit',
'callback' => array( $this, 'commitChanges' ),
);
$this->parent->addInstallStepFollowing( 'interwiki', $callback );
}
function setupDatabase() {
$status = $this->getConnection();
if ( !$status->isOK() ) {
return $status;
}
$conn = $status->value;
// Make sure that we can write to the correct schema
// If not, Postgres will happily and silently go to the next search_path item
$schema = $this->getVar( 'wgDBmwschema' );
$ctest = 'mediawiki_test_table';
$safeschema = $conn->quote_ident( $schema );
if ( $conn->tableExists( $ctest, $schema ) ) {
$conn->doQuery( "DROP TABLE $safeschema.$ctest" );
}
$res = $this->doQuery( "CREATE TABLE $safeschema.$ctest(a int)" );
if ( !$res ) {
$status->fatal( 'config-install-pg-schema-failed',
$this->getVar( 'wgDBuser'), $schema );
}
$conn->doQuery( "DROP TABLE $safeschema.$ctest" );
return $status;
}
protected function commitChanges() {
$this->db->query( 'COMMIT' );
}
function getLocalSettings() {