| 1 |
-- SQL to create the initial tables for the MediaWiki database. |
| 2 |
-- This is read and executed by the install script; you should |
| 3 |
-- not have to run it by itself unless doing a manual install. |
| 4 |
-- This is the PostgreSQL version. |
| 5 |
-- For information about each table, please see the notes in maintenance/tables.sql |
| 6 |
-- Please make sure all dollar-quoting uses $mw$ at the start of the line |
| 7 |
-- TODO: Change CHAR/SMALLINT to BOOL (still used in a non-bool fashion in PHP code) |
| 8 |
|
| 9 |
BEGIN; |
| 10 |
SET client_min_messages = 'ERROR'; |
| 11 |
|
| 12 |
-- Tsearch2 2 stuff. Will fail if we don't have proper access to the tsearch2 tables |
| 13 |
-- Make sure you also change patch-tsearch2funcs.sql if the funcs below change. |
| 14 |
ALTER TABLE page ADD titlevector tsvector; |
| 15 |
CREATE FUNCTION ts2_page_title() RETURNS TRIGGER LANGUAGE plpgsql AS |
| 16 |
$mw$ |
| 17 |
BEGIN |
| 18 |
IF TG_OP = 'INSERT' THEN |
| 19 |
NEW.titlevector = to_tsvector(REPLACE(NEW.page_title,'/',' ')); |
| 20 |
ELSIF NEW.page_title != OLD.page_title THEN |
| 21 |
NEW.titlevector := to_tsvector(REPLACE(NEW.page_title,'/',' ')); |
| 22 |
END IF; |
| 23 |
RETURN NEW; |
| 24 |
END; |
| 25 |
$mw$; |
| 26 |
|
| 27 |
CREATE TRIGGER ts2_page_title BEFORE INSERT OR UPDATE ON page |
| 28 |
FOR EACH ROW EXECUTE PROCEDURE ts2_page_title(); |
| 29 |
|
| 30 |
|
| 31 |
ALTER TABLE text ADD textvector tsvector; |
| 32 |
CREATE FUNCTION ts2_page_text() RETURNS TRIGGER LANGUAGE plpgsql AS |
| 33 |
$mw$ |
| 34 |
BEGIN |
| 35 |
IF TG_OP = 'INSERT' THEN |
| 36 |
NEW.textvector = to_tsvector(NEW.old_text); |
| 37 |
ELSIF NEW.old_text != OLD.old_text THEN |
| 38 |
NEW.textvector := to_tsvector(NEW.old_text); |
| 39 |
END IF; |
| 40 |
RETURN NEW; |
| 41 |
END; |
| 42 |
$mw$; |
| 43 |
|
| 44 |
CREATE TRIGGER ts2_page_text BEFORE INSERT OR UPDATE ON text |
| 45 |
FOR EACH ROW EXECUTE PROCEDURE ts2_page_text(); |
| 46 |
|
| 47 |
CREATE INDEX ts2_page_title ON page USING gin(titlevector); |
| 48 |
CREATE INDEX ts2_page_text ON text USING gin(textvector); |