r15791 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r15790‎ | r15791 | r15792 >
Date:02:04, 23 July 2006
Author:greg
Status:old
Tags:
Comment:
Change reserved word table names "user" and "text"
Modified paths:
  • /trunk/phase3/includes/DatabasePostgres.php (modified) (history)
  • /trunk/phase3/includes/SearchPostgres.php (modified) (history)
  • /trunk/phase3/maintenance/postgres/tables.sql (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/postgres/tables.sql
@@ -11,7 +11,7 @@
1212 SET client_min_messages = 'ERROR';
1313
1414 CREATE SEQUENCE user_user_id_seq MINVALUE 0 START WITH 0;
15 -CREATE TABLE "user" (
 15+CREATE TABLE mwuser ( -- replace reserved word 'user'
1616 user_id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('user_user_id_seq'),
1717 user_name TEXT NOT NULL UNIQUE,
1818 user_real_name TEXT,
@@ -26,20 +26,20 @@
2727 user_touched TIMESTAMPTZ,
2828 user_registration TIMESTAMPTZ
2929 );
30 -CREATE INDEX user_email_token_idx ON "user" (user_email_token);
 30+CREATE INDEX user_email_token_idx ON mwuser (user_email_token);
3131
3232 -- Create a dummy user to satisfy fk contraints especially with revisions
33 -INSERT INTO "user"
 33+INSERT INTO mwuser
3434 VALUES (DEFAULT,'Anonymous','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,now(),now());
3535
3636 CREATE TABLE user_groups (
37 - ug_user INTEGER NULL REFERENCES "user"(user_id) ON DELETE CASCADE,
 37+ ug_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE CASCADE,
3838 ug_group TEXT NOT NULL
3939 );
4040 CREATE UNIQUE INDEX user_groups_unique ON user_groups (ug_user, ug_group);
4141
4242 CREATE TABLE user_newtalk (
43 - user_id INTEGER NOT NULL REFERENCES "user"(user_id) ON DELETE CASCADE,
 43+ user_id INTEGER NOT NULL REFERENCES mwuser(user_id) ON DELETE CASCADE,
4444 user_ip CIDR NULL
4545 );
4646 CREATE INDEX user_newtalk_id_idx ON user_newtalk (user_id);
@@ -86,7 +86,7 @@
8787 rev_page INTEGER NULL REFERENCES page (page_id) ON DELETE CASCADE,
8888 rev_text_id INTEGER NULL, -- FK
8989 rev_comment TEXT,
90 - rev_user INTEGER NOT NULL REFERENCES "user"(user_id),
 90+ rev_user INTEGER NOT NULL REFERENCES mwuser(user_id),
9191 rev_user_text TEXT NOT NULL,
9292 rev_timestamp TIMESTAMPTZ NOT NULL,
9393 rev_minor_edit CHAR NOT NULL DEFAULT '0',
@@ -99,7 +99,7 @@
100100
101101
102102 CREATE SEQUENCE text_old_id_val;
103 -CREATE TABLE "text" (
 103+CREATE TABLE pagecontent ( -- replaces reserved word 'text'
104104 old_id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('text_old_id_val'),
105105 old_text TEXT,
106106 old_flags TEXT
@@ -111,7 +111,7 @@
112112 ar_title TEXT NOT NULL,
113113 ar_text TEXT,
114114 ar_comment TEXT,
115 - ar_user INTEGER NULL REFERENCES "user"(user_id) ON DELETE SET NULL,
 115+ ar_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
116116 ar_user_text TEXT NOT NULL,
117117 ar_timestamp TIMESTAMPTZ NOT NULL,
118118 ar_minor_edit CHAR NOT NULL DEFAULT '0',
@@ -203,8 +203,8 @@
204204 CREATE TABLE ipblocks (
205205 ipb_id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('ipblocks_ipb_id_val'),
206206 ipb_address CIDR NULL,
207 - ipb_user INTEGER NULL REFERENCES "user"(user_id) ON DELETE SET NULL,
208 - ipb_by INTEGER NOT NULL REFERENCES "user"(user_id) ON DELETE CASCADE,
 207+ ipb_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
 208+ ipb_by INTEGER NOT NULL REFERENCES mwuser(user_id) ON DELETE CASCADE,
209209 ipb_reason TEXT NOT NULL,
210210 ipb_timestamp TIMESTAMPTZ NOT NULL,
211211 ipb_auto CHAR NOT NULL DEFAULT '0',
@@ -230,7 +230,7 @@
231231 img_major_mime TEXT DEFAULT 'unknown',
232232 img_minor_mime TEXT DEFAULT 'unknown',
233233 img_description TEXT NOT NULL,
234 - img_user INTEGER NULL REFERENCES "user"(user_id) ON DELETE SET NULL,
 234+ img_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
235235 img_user_text TEXT NOT NULL,
236236 img_timestamp TIMESTAMPTZ
237237 );
@@ -245,7 +245,7 @@
246246 oi_height SMALLINT NOT NULL,
247247 oi_bits SMALLINT NOT NULL,
248248 oi_description TEXT,
249 - oi_user INTEGER NULL REFERENCES "user"(user_id) ON DELETE SET NULL,
 249+ oi_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
250250 oi_user_text TEXT NOT NULL,
251251 oi_timestamp TIMESTAMPTZ NOT NULL
252252 );
@@ -258,7 +258,7 @@
259259 fa_archive_name TEXT,
260260 fa_storage_group VARCHAR(16),
261261 fa_storage_key CHAR(64),
262 - fa_deleted_user INTEGER NULL REFERENCES "user"(user_id) ON DELETE SET NULL,
 262+ fa_deleted_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
263263 fa_deleted_timestamp TIMESTAMPTZ NOT NULL,
264264 fa_deleted_reason TEXT,
265265 fa_size SMALLINT NOT NULL,
@@ -270,7 +270,7 @@
271271 fa_major_mime TEXT DEFAULT 'unknown',
272272 fa_minor_mime TEXT DEFAULT 'unknown',
273273 fa_description TEXT NOT NULL,
274 - fa_user INTEGER NULL REFERENCES "user"(user_id) ON DELETE SET NULL,
 274+ fa_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
275275 fa_user_text TEXT NOT NULL,
276276 fa_timestamp TIMESTAMPTZ
277277 );
@@ -285,7 +285,7 @@
286286 rc_id INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('rc_rc_id_seq'),
287287 rc_timestamp TIMESTAMPTZ NOT NULL,
288288 rc_cur_time TIMESTAMPTZ NOT NULL,
289 - rc_user INTEGER NULL REFERENCES "user"(user_id) ON DELETE SET NULL,
 289+ rc_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
290290 rc_user_text TEXT NOT NULL,
291291 rc_namespace SMALLINT NOT NULL,
292292 rc_title TEXT NOT NULL,
@@ -310,7 +310,7 @@
311311
312312
313313 CREATE TABLE watchlist (
314 - wl_user INTEGER NOT NULL REFERENCES "user"(user_id) ON DELETE CASCADE,
 314+ wl_user INTEGER NOT NULL REFERENCES mwuser(user_id) ON DELETE CASCADE,
315315 wl_namespace SMALLINT NOT NULL DEFAULT 0,
316316 wl_title TEXT NOT NULL,
317317 wl_notificationtimestamp TIMESTAMPTZ
@@ -366,7 +366,7 @@
367367 log_type TEXT NOT NULL,
368368 log_action TEXT NOT NULL,
369369 log_timestamp TIMESTAMPTZ NOT NULL,
370 - log_user INTEGER REFERENCES "user"(user_id) ON DELETE SET NULL,
 370+ log_user INTEGER REFERENCES mwuser(user_id) ON DELETE SET NULL,
371371 log_namespace SMALLINT NOT NULL,
372372 log_title TEXT NOT NULL,
373373 log_comment TEXT,
@@ -418,8 +418,8 @@
419419 FOR EACH ROW EXECUTE PROCEDURE ts2_page_title();
420420
421421
422 -ALTER TABLE text ADD textvector tsvector;
423 -CREATE INDEX ts2_page_text ON text USING gist(textvector);
 422+ALTER TABLE pagecontent ADD textvector tsvector;
 423+CREATE INDEX ts2_page_text ON pagecontent USING gist(textvector);
424424 CREATE FUNCTION ts2_page_text() RETURNS TRIGGER LANGUAGE plpgsql AS
425425 $mw$
426426 BEGIN
@@ -432,7 +432,7 @@
433433 END;
434434 $mw$;
435435
436 -CREATE TRIGGER ts2_page_text BEFORE INSERT OR UPDATE ON text
 436+CREATE TRIGGER ts2_page_text BEFORE INSERT OR UPDATE ON pagecontent
437437 FOR EACH ROW EXECUTE PROCEDURE ts2_page_text();
438438
439439 CREATE FUNCTION add_interwiki (TEXT,INT,CHAR) RETURNS INT LANGUAGE SQL AS
Index: trunk/phase3/includes/SearchPostgres.php
@@ -98,8 +98,8 @@
9999 $match = $this->parseQuery( $filteredTerm, $fulltext );
100100
101101 $query = "SELECT page_id, page_namespace, page_title, old_text AS page_text ".
102 - "FROM page p, revision r, text t WHERE p.page_latest = r.rev_id " .
103 - "AND r.rev_text_id = t.old_id AND $fulltext @@ to_tsquery('$match')";
 102+ "FROM page p, revision r, pagecontent c WHERE p.page_latest = r.rev_id " .
 103+ "AND r.rev_text_id = c.old_id AND $fulltext @@ to_tsquery('$match')";
104104
105105 ## Redirects
106106 if (! $this->showRedirects)
Index: trunk/phase3/includes/DatabasePostgres.php
@@ -378,16 +378,12 @@
379379 }
380380
381381 function tableName( $name ) {
382 - # Replace backticks into double quotes
383 - $name = strtr($name,'`','"');
384 -
385 - # Now quote PG reserved keywords
 382+ # Replace reserved words with better ones
386383 switch( $name ) {
387384 case 'user':
388 - case 'old':
389 - case 'group':
390 - return '"' . $name . '"';
391 -
 385+ return 'mwuser';
 386+ case 'text':
 387+ return 'pagecontent';
392388 default:
393389 return $name;
394390 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r113838Follow-up to r15791: Rename "user" and "text" when upgrading on PostgreSQL...saper20:20, 14 March 2012