r81439 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81438‎ | r81439 | r81440 >
Date:04:06, 3 February 2011
Author:mah
Status:resolved (Comments)
Tags:
Comment:
Results of my work on new-installer and Pg.

* NOTE: this commit removes any semblence of tsearch compatibility with pre-8.3 PostgreSQL
* Make new-installer work against PostgreSQL
* Remove SearchPostgres.php's call to pg_fetch_result. I think this is the only one outside of the vestigtial old installer code.
Modified paths:
  • /trunk/phase3/includes/installer/PostgresInstaller.php (modified) (history)
  • /trunk/phase3/includes/search/SearchPostgres.php (modified) (history)
  • /trunk/phase3/maintenance/postgres/tables.sql (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/postgres/tables.sql
@@ -9,6 +9,21 @@
1010 BEGIN;
1111 SET client_min_messages = 'ERROR';
1212
 13+DROP SEQUENCE IF EXISTS user_user_id_seq;
 14+DROP SEQUENCE IF EXISTS page_page_id_seq;
 15+DROP SEQUENCE IF EXISTS revision_rev_id_seq;
 16+DROP SEQUENCE IF EXISTS page_restrictions_id_seq;
 17+DROP SEQUENCE IF EXISTS ipblocks_ipb_id_seq;
 18+DROP SEQUENCE IF EXISTS recentchanges_rc_id_seq;
 19+DROP SEQUENCE IF EXISTS logging_log_id_seq;
 20+DROP SEQUENCE IF EXISTS trackbacks_tb_id_seq;
 21+DROP SEQUENCE IF EXISTS job_job_id_seq;
 22+DROP SEQUENCE IF EXISTS category_cat_id_seq;
 23+DROP FUNCTION IF EXISTS page_deleted();
 24+DROP FUNCTION IF EXISTS ts2_page_title();
 25+DROP FUNCTION IF EXISTS ts2_page_text();
 26+DROP FUNCTION IF EXISTS add_interwiki(TEXT,INT,SMALLINT);
 27+
1328 CREATE SEQUENCE user_user_id_seq MINVALUE 0 START WITH 0;
1429 CREATE TABLE mwuser ( -- replace reserved word 'user'
1530 user_id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('user_user_id_seq'),
@@ -495,7 +510,7 @@
496511 CREATE INDEX job_cmd_namespace_title ON job (job_cmd, job_namespace, job_title);
497512
498513 -- Tsearch2 2 stuff. Will fail if we don't have proper access to the tsearch2 tables
 514+-- Version 8.3 or higher only. Previous versions would need another parmeter for to_tsvector.
499515 -- Make sure you also change patch-tsearch2funcs.sql if the funcs below change.
500516
501517 ALTER TABLE page ADD titlevector tsvector;
@@ -503,9 +518,9 @@
504519 $mw$
505520 BEGIN
506521 IF TG_OP = 'INSERT' THEN
507 - NEW.titlevector = to_tsvector('default',REPLACE(NEW.page_title,'/',' '));
 522+ NEW.titlevector = to_tsvector(REPLACE(NEW.page_title,'/',' '));
508523 ELSIF NEW.page_title != OLD.page_title THEN
509 - NEW.titlevector := to_tsvector('default',REPLACE(NEW.page_title,'/',' '));
 524+ NEW.titlevector := to_tsvector(REPLACE(NEW.page_title,'/',' '));
510525 END IF;
511526 RETURN NEW;
512527 END;
@@ -520,9 +535,9 @@
521536 $mw$
522537 BEGIN
523538 IF TG_OP = 'INSERT' THEN
524 - NEW.textvector = to_tsvector('default',NEW.old_text);
 539+ NEW.textvector = to_tsvector(NEW.old_text);
525540 ELSIF NEW.old_text != OLD.old_text THEN
526 - NEW.textvector := to_tsvector('default',NEW.old_text);
 541+ NEW.textvector := to_tsvector(NEW.old_text);
527542 END IF;
528543 RETURN NEW;
529544 END;
Index: trunk/phase3/includes/search/SearchPostgres.php
@@ -151,7 +151,8 @@
152152 ## TODO: Better output (example to catch: one 'two)
153153 die ("Sorry, that was not a valid search string. Please go back and try again");
154154 }
155 - $top = pg_fetch_result($res,0,0);
 155+ $top = $res->fetchRow();
 156+ $top = $top[0];
156157
157158 if ($top === "") { ## e.g. if only stopwords are used XXX return something better
158159 $query = "SELECT page_id, page_namespace, page_title, 0 AS score ".
Index: trunk/phase3/includes/installer/PostgresInstaller.php
@@ -70,7 +70,7 @@
7171 }
7272
7373 // Try to connect
74 - $status->merge( $this->getConnection() );
 74+ $status->merge( $this->getConnection( 'template1' ) );
7575 if ( !$status->isOK() ) {
7676 return $status;
7777 }
@@ -107,8 +107,32 @@
108108 return $status;
109109 }
110110
 111+ function getConnection($database = null) {
 112+ $status = Status::newGood();
 113+
 114+ if( is_null( $database ) ) {
 115+ $dbname = $this->getVar( 'wgDBname' );
 116+ $dbuser = $this->getVar( 'wgDBuser' );
 117+ $dbpass = $this->getVar( 'wgDBpassword' );
 118+ } else {
 119+ $dbname = $database;
 120+ $dbuser = $this->getVar( '_InstallUser' );
 121+ $dbpass = $this->getVar( '_InstallPassword' );
 122+ }
 123+
 124+ try {
 125+ $this->db = new DatabasePostgres(
 126+ $this->getVar( 'wgDBserver' ),
 127+ $dbuser, $dbpass, $dbname );
 128+ $status->value = $this->db;
 129+ } catch ( DBConnectionError $e ) {
 130+ $status->fatal( 'config-connection-error', $e->getMessage() );
 131+ }
 132+ return $status;
 133+ }
 134+
111135 protected function canCreateAccounts() {
112 - $status = $this->getConnection();
 136+ $status = $this->getConnection( 'template1' );
113137 if ( !$status->isOK() ) {
114138 return false;
115139 }
@@ -200,7 +224,7 @@
201225 }
202226
203227 function setupDatabase() {
204 - $status = $this->getConnection();
 228+ $status = $this->getConnection( 'template1' );
205229 if ( !$status->isOK() ) {
206230 return $status;
207231 }
@@ -265,7 +289,7 @@
266290 return Status::newGood();
267291 }
268292
269 - $status = $this->getConnection();
 293+ $status = $this->getConnection( 'template1' );
270294 if ( !$status->isOK() ) {
271295 return $status;
272296 }
@@ -273,13 +297,19 @@
274298 $db = $this->getVar( 'wgDBname' );
275299 $this->db->selectDB( $db );
276300 $safeuser = $this->db->addIdentifierQuotes( $this->getVar( 'wgDBuser' ) );
 301+ $safeusercheck = $this->db->addQuotes( $this->getVar( 'wgDBuser' ) );
277302 $safepass = $this->db->addQuotes( $this->getVar( 'wgDBpassword' ) );
 303+
 304+ $rows = $this->db->numRows(
 305+ $this->db->query( "SELECT 1 FROM pg_catalog.pg_shadow WHERE usename = $safeusercheck" )
 306+ );
 307+ if ( $rows < 1 ) {
278308 $res = $this->db->query( "CREATE USER $safeuser NOCREATEDB PASSWORD $safepass", __METHOD__ );
279 - return $status;
280309
281 - if ( $res !== true ) {
282 - $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ) );
 310+ if ( $res !== true && !( $res instanceOf ResultWrapper ) ) {
 311+ $status->fatal( 'config-install-user-failed', $this->getVar( 'wgDBuser' ), $res );
283312 }
 313+ }
284314
285315 return $status;
286316 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r81440Follow-up to r81439, works up to installing the admin user then dies with:...overlordq05:17, 3 February 2011
r89824Fixed complete breakage of editing in PG, including the default main page whi...tstarling12:59, 10 June 2011

Comments

#Comment by 😂 (talk | contribs)   14:25, 4 February 2011

Like Tim says in bug 26612, we can't assume we'll always be able to connect to template1. This needs to catch that error condition and pass it back to the user.

The logic you added to getConnection() should really be in openConnection(), but OverlordQ already resolved that in the followup.

#Comment by 😂 (talk | contribs)   21:03, 5 February 2011

Getting this on a fresh install:

ERROR: cannot drop sequence user_user_id_seq because other objects depend on it DETAIL: default for table mwuser column user_id depends on sequence user_user_id_seq HINT: Use DROP ... CASCADE to drop the dependent objects too. 
#Comment by MarkAHershberger (talk | contribs)   22:16, 5 February 2011

You would get this if you hit the back button after an initial failure. I think the drop statements can be taken out, though.

#Comment by 😂 (talk | contribs)   22:20, 5 February 2011

Yes, if I had hit back. But I hadn't. This time we failed with a public schema containing tables, no mediawiki schema.

I hate Postgres...

#Comment by MarkAHershberger (talk | contribs)   22:21, 5 February 2011

Fixed it instead by adding CASCADE since you would get similar problems if you the DROP was just removed.

#Comment by 😂 (talk | contribs)   18:02, 27 March 2011

This has been pretty much superseded, marking resolved.

Status & tagging log