-- Postgres version
-- @author: Sebastian Fiedler <basti@unix-solution.de>
-- last change: 2013-11-29

--- SET RIGHTS below !!

-- set Schemata
SET search_path = mediawiki;

CREATE TABLE "Comments"
(
  commentid SERIAL NOT NULL,
  Comment_Page_ID integer NOT NULL DEFAULT 0,
  Comment_user_id integer NOT NULL DEFAULT 0,
  Comment_Username varchar(200) NOT NULL DEFAULT '',
  Comment_Text text NOT NULL,
  Comment_Date timestamp without time zone NOT NULL,
  Comment_Parent_ID integer NOT NULL DEFAULT 0,
  Comment_IP varchar(45) NOT NULL DEFAULT '',
  Comment_Plus_Count integer NOT NULL DEFAULT 0,
  Comment_Minus_Count integer NOT NULL DEFAULT 0,
  CONSTRAINT comments_pkey PRIMARY KEY (commentid)
);

CREATE TABLE "Comments_Vote"
(
  comment_vote_id SERIAL PRIMARY KEY,
  Comment_Vote_user_id integer NOT NULL DEFAULT 0,
  Comment_Vote_Username varchar(200) NOT NULL DEFAULT '',
  Comment_Vote_Score integer NOT NULL DEFAULT 0,
  Comment_Vote_Date timestamp without time zone NOT NULL,
  Comment_Vote_IP varchar(45) NOT NULL DEFAULT ''
);

CREATE TABLE "Comments_block" (
  cb_id SERIAL PRIMARY KEY,
  cb_user_id integer NOT NULL default '0',
  cb_user_name varchar(255) NOT NULL default '',
  cb_user_id_blocked integer default NULL,
  cb_user_name_blocked varchar(255) NOT NULL default '',
  cb_date timestamp without time zone NOT NULL
);

-- set rights to the wikiuser, replace my_wikiuser with your defined database username

ALTER TABLE mediawiki."Comments"
  OWNER TO my_wikiuser;

ALTER TABLE mediawiki."Comments_Vote"
  OWNER TO my_wikiuser;

ALTER TABLE mediawiki."Comments_block"
  OWNER TO my_wikiuser;

-- maybe some more mysqlcompat functions are needed
-- http://pgfoundry.org/projects/mysqlcompat/
-- or http://okbob.blogspot.de/2009/08/mysql-functions-for-postgresql.html

CREATE OR REPLACE FUNCTION mediawiki.unix_timestamp(timestamp without time zone)
  RETURNS double precision AS
$BODY$
SELECT EXTRACT(epoch FROM $1)
$BODY$
  LANGUAGE sql VOLATILE
  COST 100;
ALTER FUNCTION mediawiki.unix_timestamp(timestamp without time zone)
  OWNER TO wikiuser;
