BEGIN TRANSACTION;

CREATE TABLE /*$wgDBprefix*/user (
  user_id			int		NOT NULL PRIMARY KEY IDENTITY(0,1),
  user_name			varchar(255)	NOT NULL, /* unique */
  user_real_name		varchar(255)	NULL,
  user_password			varchar(max)		NULL,
  user_newpassword		varchar(max)		NULL,
  user_newpass_time		datetime	NULL,
  user_email			varchar(max)		NULL,
  user_options			varchar(max)		NULL,
  user_touched			datetime	NULL,
  user_token			varchar(32)	NULL,
  user_email_authenticated	datetime	NULL,
  user_email_token		varchar(32)	NULL,
  user_email_token_expires	datetime	NULL,
  user_registration		datetime	NOT NULL,
  user_editcount		int		NULL
);
CREATE INDEX /*$wgDBprefix*/user_email_token_idx ON /*$wgDBprefix*/user (user_email_token);

-- Create a dummy user to satisfy fk contraints especially with revisions
INSERT INTO /*$wgDBprefix*/user
  VALUES ('Anonymous','',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,GETDATE(),GETDATE(),NULL);

CREATE TABLE /*$wgDBprefix*/user_groups (
  ug_user	int		NOT NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE CASCADE, 
  ug_group	varchar(16)	NOT NULL
);
CREATE UNIQUE INDEX /*$wgDBprefix*/user_groups_unique ON /*$wgDBprefix*/user_groups (ug_user, ug_group);

CREATE TABLE /*$wgDBprefix*/user_newtalk (
  user_id		int		NOT NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE CASCADE,
  user_ip		varchar(40)	NULL,
  user_last_timestamp	datetime	NOT NULL,
);
CREATE INDEX /*$wgDBprefix*/user_newtalk_id_idx ON /*$wgDBprefix*/user_newtalk (user_id);
CREATE INDEX /*$wgDBprefix*/user_newtalk_ip_idx ON /*$wgDBprefix*/user_newtalk (user_ip);

CREATE TABLE /*$wgDBprefix*/page (
  page_id		int		NOT NULL PRIMARY KEY IDENTITY(1,1),
  page_namespace	int		NOT NULL,
  page_title		varchar(255)	NOT NULL,
  page_restrictions	varchar(max)		NULL,
  page_counter		bigint		NOT NULL default 0,
  page_is_redirect	tinyint		NOT NULL default 0,
  page_is_new		tinyint		NOT NULL default 0,
  page_random		real		NOT NULL,
  page_touched		datetime	NULL,
  page_latest		int		NOT NULL,
  page_len		int		NOT NULL
);
CREATE UNIQUE INDEX /*$wgDBprefix*/page_unique_name ON /*$wgDBprefix*/page (page_namespace, page_title);
-- Indexes with WHERE clauses require SQL server 2008
--CREATE INDEX /*$wgDBprefix*/page_main_title         ON /*$wgDBprefix*/page (page_title) WHERE page_namespace = 0;
--CREATE INDEX /*$wgDBprefix*/page_talk_title         ON /*$wgDBprefix*/page (page_title) WHERE page_namespace = 1;
--CREATE INDEX /*$wgDBprefix*/page_user_title         ON /*$wgDBprefix*/page (page_title) WHERE page_namespace = 2;
--CREATE INDEX /*$wgDBprefix*/page_utalk_title        ON /*$wgDBprefix*/page (page_title) WHERE page_namespace = 3;
--CREATE INDEX /*$wgDBprefix*/page_project_title      ON /*$wgDBprefix*/page (page_title) WHERE page_namespace = 4;
CREATE INDEX /*$wgDBprefix*/page_ns_title      ON /*$wgDBprefix*/page (page_namespace, page_title);
CREATE INDEX /*$wgDBprefix*/page_random_idx         ON /*$wgDBprefix*/page (page_random);
CREATE INDEX /*$wgDBprefix*/page_len_idx            ON /*$wgDBprefix*/page (page_len);

CREATE TABLE /*$wgDBprefix*/revision (
  rev_id		int		NOT NULL UNIQUE IDENTITY(1,1),
  rev_page		int		NULL REFERENCES /*$wgDBprefix*/page (page_id) ON DELETE CASCADE,
  rev_text_id		int		NOT NULL,
  rev_comment		varchar(max)		NULL,
  rev_user		int		NOT NULL REFERENCES /*$wgDBprefix*/user(user_id),
  rev_user_text		varchar(255)	NOT NULL,
  rev_timestamp		datetime	NOT NULL,
  rev_minor_edit	tinyint		NOT NULL default 0,
  rev_deleted		tinyint		NOT NULL default 0,
  rev_len		int		NULL,
  rev_parent_id		int		NULL
);

CREATE UNIQUE INDEX /*$wgDBprefix*/revision_unique ON /*$wgDBprefix*/revision (rev_page, rev_id);
CREATE INDEX /*$wgDBprefix*/rev_text_id_idx        ON /*$wgDBprefix*/revision (rev_text_id);
CREATE INDEX /*$wgDBprefix*/rev_timestamp_idx      ON /*$wgDBprefix*/revision (rev_timestamp);
CREATE INDEX /*$wgDBprefix*/rev_user_idx           ON /*$wgDBprefix*/revision (rev_user);
CREATE INDEX /*$wgDBprefix*/rev_user_text_idx      ON /*$wgDBprefix*/revision (rev_user_text);

CREATE TABLE /*$wgDBprefix*/text (
  old_id	int	NOT NULL PRIMARY KEY IDENTITY(1,1),
  old_text	varchar(max)	NULL,
  old_flags	varchar(max)	NULL
);

CREATE TABLE /*$wgDBprefix*/archive (
  ar_namespace	int		NOT NULL,
  ar_title	varchar(255)	NOT NULL,
  ar_text	varchar(max)		NULL,
  ar_comment	varchar(max)		NULL,
  ar_user	int		NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE SET NULL,
  ar_user_text	varchar(255)	NOT NULL,
  ar_timestamp	datetime	NOT NULL,
  ar_minor_edit	tinyint		NOT NULL default 0,
  ar_flags	varchar(max)		NULL,
  ar_rev_id	int		NULL,
  ar_text_id	int		NULL,
  ar_deleted	tinyint		NOT NULL default 0,
  ar_len	int		NULL,
  ar_page_id	int		NULL,
  ar_parent_id	int		NULL
);
CREATE INDEX /*$wgDBprefix*/archive_name_title_timestamp ON /*$wgDBprefix*/archive (ar_namespace,ar_title,ar_timestamp);
CREATE INDEX /*$wgDBprefix*/archive_user_text            ON /*$wgDBprefix*/archive (ar_user_text);

CREATE TABLE /*$wgDBprefix*/pagelinks (
  pl_from	int		NOT NULL REFERENCES /*$wgDBprefix*/page(page_id) ON DELETE CASCADE,
  pl_namespace	int		NOT NULL,
  pl_title	varchar(255)	NOT NULL
);
CREATE UNIQUE INDEX /*$wgDBprefix*/pagelink_unique ON /*$wgDBprefix*/pagelinks (pl_from,pl_namespace,pl_title);


CREATE TABLE /*$wgDBprefix*/templatelinks (
  tl_from	int		NOT NULL REFERENCES /*$wgDBprefix*/page(page_id) ON DELETE CASCADE,
  tl_namespace	int		NOT NULL,
  tl_title	varchar(255)	NOT NULL
);
CREATE UNIQUE INDEX /*$wgDBprefix*/templatelinks_unique ON /*$wgDBprefix*/templatelinks (tl_namespace,tl_title,tl_from);


CREATE TABLE /*$wgDBprefix*/imagelinks (
  il_from	int		NOT NULL REFERENCES /*$wgDBprefix*/page(page_id) ON DELETE CASCADE,
  il_to		varchar(255)	NOT NULL
);
CREATE UNIQUE INDEX /*$wgDBprefix*/il_from ON /*$wgDBprefix*/imagelinks (il_to,il_from);

CREATE TABLE /*$wgDBprefix*/categorylinks (
  cl_from	int		NOT NULL REFERENCES /*$wgDBprefix*/page(page_id) ON DELETE CASCADE,
  cl_to		varchar(255)	NOT NULL,
  cl_sortkey	varchar(70)	NULL,
  cl_timestamp	datetime	NOT NULL
);
CREATE UNIQUE INDEX /*$wgDBprefix*/cl_from ON /*$wgDBprefix*/categorylinks (cl_from, cl_to);
CREATE INDEX /*$wgDBprefix*/cl_sortkey     ON /*$wgDBprefix*/categorylinks (cl_to, cl_sortkey, cl_from);

CREATE TABLE /*$wgDBprefix*/category (
  cat_id	int		NOT NULL PRIMARY KEY IDENTITY(1,1),
  cat_title	varchar(255)	NOT NULL,
  cat_pages	int		NOT NULL default 0,
  cat_subcats	int		NOT NULL default 0,
  cat_files	int		NOT NULL default 0,
  cat_hidden	tinyint		NOT NULL default 0
);
CREATE UNIQUE INDEX /*$wgDBprefix*/category_title ON /*$wgDBprefix*/category(cat_title);
CREATE INDEX /*$wgDBprefix*/category_pages ON /*$wgDBprefix*/category(cat_pages);

CREATE TABLE /*$wgDBprefix*/externallinks (
  el_from	int	NOT NULL  REFERENCES /*$wgDBprefix*/page(page_id) ON DELETE CASCADE,
  el_to		varchar(max)	NOT NULL,
  el_index	varchar(max)	NOT NULL
);
-- CREATE INDEX /*$wgDBprefix*/externallinks_from_to ON /*$wgDBprefix*/externallinks (el_from,el_to);
-- CREATE INDEX /*$wgDBprefix*/externallinks_index   ON /*$wgDBprefix*/externallinks (el_index);

CREATE TABLE /*$wgDBprefix*/langlinks (
  ll_from	int		NOT NULL REFERENCES /*$wgDBprefix*/page (page_id) ON DELETE CASCADE,
  ll_lang	varchar(20)	NULL,
  ll_title	varchar(255)	NULL,
);
CREATE UNIQUE INDEX /*$wgDBprefix*/langlinks_unique ON /*$wgDBprefix*/langlinks (ll_from,ll_lang);
CREATE INDEX /*$wgDBprefix*/langlinks_lang_title    ON /*$wgDBprefix*/langlinks (ll_lang,ll_title);

CREATE TABLE /*$wgDBprefix*/site_stats (
  ss_row_id		int	NOT NULL,
  ss_total_views	bigint	NOT NULL default 0,
  ss_total_edits	bigint	NOT NULL default 0,
  ss_good_articles	bigint	NOT NULL default 0,
  ss_active_users	bigint  NOT NULL default -1,
  ss_total_pages	bigint	NOT NULL default -1,
  ss_users		bigint	NOT NULL default -1,
  ss_admins		int	NOT NULL default -1,
  ss_images		int	NOT NULL default 0
);

CREATE TABLE /*$wgDBprefix*/hitcounter (
  hc_id		int	NOT NULL
);

CREATE TABLE /*$wgDBprefix*/ipblocks (
  ipb_id		int		NOT NULL PRIMARY KEY IDENTITY(1,1),
  ipb_address		varchar(255)	NULL,
  ipb_user		int		NULL, --  REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE CASCADE,
  ipb_by		int		NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE SET NULL,
  ipb_by_text		varchar(255)	NOT NULL,
  ipb_reason		varchar(max)		NOT NULL,
  ipb_timestamp		datetime	NOT NULL,
  ipb_auto		bit		NOT NULL default 0,
  ipb_anon_only		bit		NOT NULL default 0,
  ipb_create_account	bit		NOT NULL default 1,
  ipb_enable_autoblock	bit		NOT NULL default '1',
  ipb_expiry		datetime	NOT NULL,
  ipb_range_start	varchar(255)	NULL,
  ipb_range_end		varchar(255)	NULL,
  ipb_deleted		bit		NOT NULL default 0,
  ipb_block_email	bit		NOT NULL default 0,
  ipb_allow_usertalk	bit		NOT NULL default 0
);
CREATE UNIQUE INDEX /*$wgDBprefix*/ipb_address_unique ON /*$wgDBprefix*/ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only);
CREATE INDEX /*$wgDBprefix*/ipb_user    ON /*$wgDBprefix*/ipblocks (ipb_user);
CREATE INDEX /*$wgDBprefix*/ipb_range   ON /*$wgDBprefix*/ipblocks (ipb_range_start,ipb_range_end);

CREATE TABLE /*$wgDBprefix*/image (
  img_name		varchar(255)	NOT NULL PRIMARY KEY,
  img_size		int		NOT NULL,
  img_width		int		NOT NULL,
  img_height		int		NOT NULL,
  img_metadata		varchar(max)		NULL,
  img_bits		int		NOT NULL,
  img_media_type	varchar(max)		NULL,
  img_major_mime	varchar(max)		NOT NULL default 'unknown',
  img_minor_mime	varchar(32)	NOT NULL default 'unknown',
  img_description	varchar(255)	NULL,
  img_user		int		NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE SET NULL,
  img_user_text		varchar(255)	NOT NULL,
  img_timestamp		datetime	NOT NULL,
  img_sha1		varchar(32)	NOT NULL default ''
);
CREATE INDEX /*$wgDBprefix*/img_size_idx      ON /*$wgDBprefix*/image (img_size);
CREATE INDEX /*$wgDBprefix*/img_timestamp_idx ON /*$wgDBprefix*/image (img_timestamp);
CREATE INDEX /*$wgDBprefix*/img_sha1          ON /*$wgDBprefix*/image (img_sha1);

CREATE TABLE /*$wgDBprefix*/oldimage (
  oi_name		varchar(255)	NOT NULL,
  oi_archive_name	varchar(255)	NOT NULL,
  oi_size		int		NOT NULL,
  oi_width		int		NOT NULL,
  oi_height		int		NOT NULL,
  oi_bits		int		NOT NULL,
  oi_description	varchar(max)		NULL,
  oi_user		int		NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE SET NULL,
  oi_user_text		varchar(255)	NOT NULL,
  oi_timestamp		datetime	NOT NULL,
  oi_metadata		varchar(max)		NULL,
  oi_media_type		varchar(max)		NULL,
  oi_major_mime		varchar(max)		NOT NULL default 'unknown',
  oi_minor_mime		varchar(32)	NOT NULL default 'unknown',
  oi_deleted		tinyint		NOT NULL default 0,
  oi_sha1		varchar(32)	NOT NULL default ''
);
ALTER TABLE /*$wgDBprefix*/oldimage ADD CONSTRAINT /*$wgDBprefix*/oldimage_oi_name_fkey_cascade FOREIGN KEY (oi_name) REFERENCES /*$wgDBprefix*/image(img_name) ON DELETE CASCADE;
CREATE INDEX /*$wgDBprefix*/oi_name_timestamp    ON /*$wgDBprefix*/oldimage (oi_name,oi_timestamp);
CREATE INDEX /*$wgDBprefix*/oi_name_archive_name ON /*$wgDBprefix*/oldimage (oi_name,oi_archive_name);
CREATE INDEX /*$wgDBprefix*/oi_sha1              ON /*$wgDBprefix*/oldimage (oi_sha1);

CREATE TABLE /*$wgDBprefix*/filearchive (
  fa_id			int		NOT NULL PRIMARY KEY IDENTITY(1,1),
  fa_name		varchar(255)	NOT NULL,
  fa_archive_name	varchar(255)	NULL,
  fa_storage_group	varchar(16)	NULL,
  fa_storage_key	varchar(64)	NULL,
  fa_deleted_user	int		NULL, --REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE SET NULL,
  fa_deleted_timestamp	datetime	NULL,
  fa_deleted_reason	varchar(max)		NULL,
  fa_size		int		NOT NULL,
  fa_width		int		NOT NULL,
  fa_height		int		NOT NULL,
  fa_metadata		varchar(max)		NULL,
  fa_bits		int		NULL,
  fa_media_type		varchar(max)		NULL,
  fa_major_mime		varchar(max)		NOT NULL default 'unknown',
  fa_minor_mime		varchar(32)	NOT NULL default 'unknown',
  fa_description	varchar(max)		NULL,
  fa_user		int		NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE SET NULL,
  fa_user_text		varchar(255)	NULL,
  fa_timestamp		datetime	NULL,
  fa_deleted		tinyint		NOT NULL default 0
);
CREATE INDEX /*$wgDBprefix*/fa_name_time ON /*$wgDBprefix*/filearchive (fa_name, fa_timestamp);
CREATE INDEX /*$wgDBprefix*/fa_dupe      ON /*$wgDBprefix*/filearchive (fa_storage_group, fa_storage_key);
CREATE INDEX /*$wgDBprefix*/fa_notime    ON /*$wgDBprefix*/filearchive (fa_deleted_timestamp);
CREATE INDEX /*$wgDBprefix*/fa_nouser    ON /*$wgDBprefix*/filearchive (fa_deleted_user);

CREATE TABLE /*$wgDBprefix*/recentchanges (
  rc_id			int		NOT NULL PRIMARY KEY IDENTITY(1,1),
  rc_timestamp		datetime	NOT NULL,
  rc_cur_time		datetime	NOT NULL,
  rc_user		int		NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE SET NULL,
  rc_user_text		varchar(255)	NOT NULL,
  rc_namespace		int		NOT NULL,
  rc_title		varchar(255)	NOT NULL,
  rc_comment		varchar(255)	NULL,
  rc_minor		tinyint		NOT NULL default 0,
  rc_bot		tinyint		NOT NULL default 0,
  rc_new		tinyint		NOT NULL default 0,
  rc_cur_id		int		NULL REFERENCES /*$wgDBprefix*/page(page_id) ON DELETE SET NULL,
  rc_this_oldid		int		NOT NULL,
  rc_last_oldid		int		NOT NULL,
  rc_type		tinyint		NOT NULL default 0,
  rc_moved_to_ns	tinyint		NULL,
  rc_moved_to_title	varchar(255)	NULL,
  rc_patrolled		tinyint		NOT NULL default 0,
  rc_ip			varchar(40)	NULL,
  rc_old_len		int		NULL,
  rc_new_len		int		NULL,
  rc_deleted		tinyint		NOT NULL default 0,
  rc_logid		int		NOT NULL default 0,
  rc_log_type		varchar(255)	NULL,
  rc_log_action		varchar(255)	NULL,
  rc_params		varchar(max)	NULL
);
CREATE INDEX /*$wgDBprefix*/rc_timestamp       ON /*$wgDBprefix*/recentchanges (rc_timestamp);
CREATE INDEX /*$wgDBprefix*/rc_namespace_title ON /*$wgDBprefix*/recentchanges (rc_namespace, rc_title);
CREATE INDEX /*$wgDBprefix*/rc_cur_id          ON /*$wgDBprefix*/recentchanges (rc_cur_id);
CREATE INDEX /*$wgDBprefix*/new_name_timestamp ON /*$wgDBprefix*/recentchanges (rc_new, rc_namespace, rc_timestamp);
CREATE INDEX /*$wgDBprefix*/rc_ip              ON /*$wgDBprefix*/recentchanges (rc_ip);

CREATE TABLE /*$wgDBprefix*/watchlist (
  wl_user			int		NOT NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE CASCADE,
  wl_namespace			int		NOT NULL,
  wl_title			varchar(255)	NOT NULL,
  wl_notificationtimestamp	datetime	NULL
);
CREATE INDEX /*$wgDBprefix*/wl_user ON /*$wgDBprefix*/watchlist (wl_user);

CREATE TABLE /*$wgDBprefix*/math (
  math_inputhash		varchar(16)	NOT NULL UNIQUE,
  math_outputhash		varchar(16)	NOT NULL,
  math_html_conservativeness	tinyint		NOT NULL,
  math_html			varchar(max)		NULL,
  math_mathml			varchar(max)		NULL
);

CREATE TABLE /*$wgDBprefix*/searchindex (
  si_page	int		NOT NULL,
  si_title	varchar(255)	NOT NULL,
  si_text	varchar(max)		NULL
);

CREATE TABLE /*$wgDBprefix*/interwiki (
  iw_prefix	varchar(32)	NOT NULL UNIQUE,
  iw_url	varchar(max)		NOT NULL,
  iw_local	bit		NOT NULL,
  iw_trans	tinyint		NOT NULL default 0
);

CREATE TABLE /*$wgDBprefix*/querycache (
  qc_type	varchar(32)	NOT NULL,
  qc_value	int		NOT NULL,
  qc_namespace	int		NOT NULL,
  qc_title	varchar(255)	NOT NULL
);
CREATE INDEX /*$wgDBprefix*/querycache_type_value ON /*$wgDBprefix*/querycache (qc_type, qc_value);

CREATE TABLE /*$wgDBprefix*/objectcache (
  keyname	varchar(255)	NOT NULL UNIQUE,
  value		varchar(max)		NULL,
  exptime	datetime	NOT NULL
);
CREATE INDEX /*$wgDBprefix*/objectcacache_exptime ON /*$wgDBprefix*/objectcache (exptime);

CREATE TABLE /*$wgDBprefix*/transcache (
  tc_url	varchar(255)	NOT NULL UNIQUE,
  tc_contents	varchar(max)		NULL,
  tc_time	int		NOT NULL
);

CREATE TABLE /*$wgDBprefix*/logging (
  log_id	int		NOT NULL PRIMARY KEY IDENTITY(1,1),
  log_type	varchar(10)	NOT NULL,
  log_action	varchar(10)	NOT NULL,
  log_timestamp	datetime	NOT NULL,
  log_user	int		NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE SET NULL,
  log_namespace	int		NOT NULL,
  log_title	varchar(255)	NOT NULL,
  log_comment	varchar(255)	NOT NULL,
  log_params	varchar(max)		NULL,
  log_deleted	tinyint		NOT NULL default 0
);
CREATE INDEX /*$wgDBprefix*/logging_type_name ON /*$wgDBprefix*/logging (log_type, log_timestamp);
CREATE INDEX /*$wgDBprefix*/logging_user_time ON /*$wgDBprefix*/logging (log_timestamp, log_user);
CREATE INDEX /*$wgDBprefix*/logging_page_time ON /*$wgDBprefix*/logging (log_namespace, log_title, log_timestamp);

CREATE TABLE /*$wgDBprefix*/trackbacks (
  tb_id		int		NOT NULL PRIMARY KEY IDENTITY(1,1),
  tb_page	int		REFERENCES /*$wgDBprefix*/page(page_id) ON DELETE CASCADE,
  tb_title	varchar(255)	NOT NULL,
  tb_url	varchar(max)		NOT NULL,
  tb_ex		varchar(max)		NULL,
  tb_name	varchar(255)	NULL
);
CREATE INDEX /*$wgDBprefix*/trackback_page ON /*$wgDBprefix*/trackbacks (tb_page);

CREATE TABLE /*$wgDBprefix*/job (
  job_id	int		NOT NULL PRIMARY KEY IDENTITY(1,1),
  job_cmd	varchar(60)	NOT NULL,
  job_namespace int		NOT NULL,
  job_title	varchar(255)	NOT NULL,
  job_params	varchar(max)		NULL
);
CREATE INDEX /*$wgDBprefix*/job_cmd_namespace_title ON /*$wgDBprefix*/job (job_cmd, job_namespace, job_title);

CREATE TABLE /*$wgDBprefix*/querycache_info (
  qci_type	varchar(32)	NULL,
  qci_timestamp	datetime	NULL
);

CREATE TABLE /*$wgDBprefix*/redirect (
  rd_from	int		NOT NULL REFERENCES /*$wgDBprefix*/page(page_id) ON DELETE CASCADE,
  rd_namespace	int		NOT NULL,
  rd_title	varchar(255)	NOT NULL
);
CREATE INDEX /*$wgDBprefix*/redirect_ns_title ON /*$wgDBprefix*/redirect (rd_namespace,rd_title,rd_from);

CREATE TABLE /*$wgDBprefix*/querycachetwo (
  qcc_type		varchar(32)	NOT NULL,
  qcc_value		int		NOT NULL default 0,
  qcc_namespace		int		NOT NULL default 0,
  qcc_title		varchar(255)	NOT NULL default '',
  qcc_namespacetwo	int		NOT NULL default 0,
  qcc_titletwo		varchar(255)	NOT NULL default ''
);
CREATE INDEX /*$wgDBprefix*/querycachetwo_type_value ON /*$wgDBprefix*/querycachetwo (qcc_type, qcc_value);
CREATE INDEX /*$wgDBprefix*/querycachetwo_title      ON /*$wgDBprefix*/querycachetwo (qcc_type,qcc_namespace,qcc_title);
CREATE INDEX /*$wgDBprefix*/querycachetwo_titletwo   ON /*$wgDBprefix*/querycachetwo (qcc_type,qcc_namespacetwo,qcc_titletwo);

CREATE TABLE /*$wgDBprefix*/page_restrictions (
  pr_id		int		NOT NULL UNIQUE IDENTITY(1,1),
  pr_page	int		NOT NULL REFERENCES /*$wgDBprefix*/page (page_id) ON DELETE CASCADE,
  pr_type	varchar(60)	NOT NULL,
  pr_level	varchar(60)	NOT NULL,
  pr_cascade	tinyint		NOT NULL,
  pr_user	int		NULL,
  pr_expiry	datetime	NULL
);
ALTER TABLE /*$wgDBprefix*/page_restrictions ADD CONSTRAINT /*$wgDBprefix*/page_restrictions_pk PRIMARY KEY (pr_page,pr_type);

CREATE TABLE /*$wgDBprefix*/protected_titles (
  pt_namespace		int		NOT NULL,
  pt_title		varchar(255)	NOT NULL,
  pt_user		int		NULL REFERENCES /*$wgDBprefix*/user(user_id) ON DELETE SET NULL,
  pt_reason		varchar(max)		NULL,
  pt_timestamp		datetime	NOT NULL,
  pt_expiry		datetime	NULL,
  pt_create_perm	varchar(60)	NOT NULL,
);
CREATE UNIQUE INDEX /*$wgDBprefix*/protected_titles_unique ON /*$wgDBprefix*/protected_titles(pt_namespace, pt_title);

CREATE TABLE /*$wgDBprefix*/page_props (
  pp_page	int		NOT NULL REFERENCES /*$wgDBprefix*/page (page_id) ON DELETE CASCADE,
  pp_propname	varchar(60)	NOT NULL,
  pp_value	varchar(max)		NULL
);
ALTER TABLE /*$wgDBprefix*/page_props ADD CONSTRAINT /*$wgDBprefix*/page_props_pk PRIMARY KEY (pp_page,pp_propname);
CREATE INDEX /*$wgDBprefix*/page_props_propname ON /*$wgDBprefix*/page_props (pp_propname);

CREATE TABLE /*$wgDBprefix*/updatelog (
  ul_key	varchar(255)	NOT NULL PRIMARY KEY
);

COMMIT TRANSACTION;
