-- Postgres Version
-- author: Sebastian Fiedler <basti@unix-solution.de>
-- date: 2013-11-29
-- https://github.com/svn2github/wikia/blob/master/extensions/RandomFeaturedUser/

CREATE TABLE mediawiki.user_points_archive
(
  up_id serial NOT NULL,
  up_period integer NOT NULL DEFAULT 0,
  up_date timestamp without time zone NOT NULL,
  up_user_id integer NOT NULL DEFAULT 0,
  up_user_name character varying(255) NOT NULL,
  up_points double precision NOT NULL DEFAULT 0::double precision,
  CONSTRAINT user_points_archive_pkey PRIMARY KEY (up_id )
);

ALTER TABLE mediawiki.user_points_archive
  OWNER TO wikiuser;

CREATE INDEX up_user_id_archive
  ON mediawiki.user_points_archive
  USING btree
  (up_user_id );

CREATE TABLE mediawiki.user_points_monthly
(
  up_id serial NOT NULL,
  up_user_id integer NOT NULL DEFAULT 0,
  up_user_name character varying(255) NOT NULL DEFAULT ''::character varying,
  up_points double precision NOT NULL DEFAULT 0::double precision,
  CONSTRAINT user_points_monthly_pkey PRIMARY KEY (up_id )
);

ALTER TABLE mediawiki.user_points_monthly
  OWNER TO wikiuser;

CREATE INDEX up_user_id_mon
  ON mediawiki.user_points_monthly
  USING btree
  (up_user_id );

CREATE TABLE mediawiki.user_points_weekly
(
  up_id serial NOT NULL,
  up_user_id integer NOT NULL DEFAULT 0,
  up_user_name character varying(255) NOT NULL DEFAULT ''::character varying,
  up_points double precision NOT NULL DEFAULT 0::double precision,
  CONSTRAINT user_points_weekly_pkey PRIMARY KEY (up_id )
);

ALTER TABLE mediawiki.user_points_weekly
  OWNER TO wikiuser;

CREATE INDEX up_user_id
  ON mediawiki.user_points_weekly
  USING btree
  (up_user_id );


-- part of http://pgfoundry.org/projects/mysqlcompat/

CREATE FUNCTION mediawiki.ifnull(anyelement, anyelement)
  RETURNS anyelement AS
$BODY$
  SELECT COALESCE($1, $2)
$BODY$
  LANGUAGE sql IMMUTABLE
  COST 100;
ALTER FUNCTION mediawiki.ifnull(anyelement, anyelement)
  OWNER TO wikiuser;

