-- For information about each table, please see the notes in maintenance/tables.sql
-- Please make sure all dollar-quoting uses $mw$ at the start of the line
-- We can't use SERIAL everywhere: the sequence names are hard-coded into the PHP
--- TODO: Change CHAR to BOOL (still needed as CHAR due to some PHP code)
+-- TODO: Change CHAR/SMALLINT to BOOL (still needed as CHAR due to some PHP code)
BEGIN;
SET client_min_messages = 'ERROR';
page_title TEXT NOT NULL,
page_restrictions TEXT,
page_counter BIGINT NOT NULL DEFAULT 0,
- page_is_redirect CHAR NOT NULL DEFAULT 0,
- page_is_new CHAR NOT NULL DEFAULT 0,
+ page_is_redirect SMALLINT NOT NULL DEFAULT 0,
+ page_is_new SMALLINT NOT NULL DEFAULT 0,
page_random NUMERIC(15,14) NOT NULL DEFAULT RANDOM(),
page_touched TIMESTAMPTZ,
page_latest INTEGER NOT NULL, -- FK?
rev_text_id INTEGER NULL, -- FK
rev_comment TEXT,
rev_user INTEGER NOT NULL REFERENCES mwuser(user_id) ON DELETE RESTRICT,
- rev_user_text TEXT NOT NULL,
- rev_timestamp TIMESTAMPTZ NOT NULL,
- rev_minor_edit CHAR NOT NULL DEFAULT '0',
+ rev_user_text TEXT NOT NULL,
+ rev_timestamp TIMESTAMPTZ NOT NULL,
+ rev_minor_edit SMALLINT NOT NULL DEFAULT 0,
rev_deleted SMALLINT NOT NULL DEFAULT 0,
rev_len INTEGER NULL,
rev_parent_id INTEGER NULL
ar_user INTEGER NULL REFERENCES mwuser(user_id) ON DELETE SET NULL,
ar_user_text TEXT NOT NULL,
ar_timestamp TIMESTAMPTZ NOT NULL,
- ar_minor_edit CHAR NOT NULL DEFAULT '0',
+ ar_minor_edit SMALLINT NOT NULL DEFAULT 0,
ar_flags TEXT,
ar_rev_id INTEGER,
ar_text_id INTEGER,
ipb_by INTEGER NOT NULL REFERENCES mwuser(user_id) ON DELETE CASCADE,
ipb_reason TEXT NOT NULL,
ipb_timestamp TIMESTAMPTZ NOT NULL,
- ipb_auto CHAR NOT NULL DEFAULT '0',
- ipb_anon_only CHAR NOT NULL DEFAULT '0',
- ipb_create_account CHAR NOT NULL DEFAULT '1',
- ipb_enable_autoblock CHAR NOT NULL DEFAULT '1',
+ ipb_auto SMALLINT NOT NULL DEFAULT 0,
+ ipb_anon_only SMALLINT NOT NULL DEFAULT 0,
+ ipb_create_account SMALLINT NOT NULL DEFAULT 1,
+ ipb_enable_autoblock SMALLINT NOT NULL DEFAULT 1,
ipb_expiry TIMESTAMPTZ NOT NULL,
ipb_range_start TEXT,
ipb_range_end TEXT,
ipb_deleted SMALLINT NOT NULL DEFAULT 0,
- ipb_block_email CHAR NOT NULL DEFAULT '0'
+ ipb_block_email SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX ipb_address ON ipblocks (ipb_address);
rc_namespace SMALLINT NOT NULL,
rc_title TEXT NOT NULL,
rc_comment TEXT,
- rc_minor CHAR NOT NULL DEFAULT '0',
- rc_bot CHAR NOT NULL DEFAULT '0',
- rc_new CHAR NOT NULL DEFAULT '0',
+ rc_minor SMALLINT NOT NULL DEFAULT 0,
+ rc_bot SMALLINT NOT NULL DEFAULT 0,
+ rc_new SMALLINT NOT NULL DEFAULT 0,
rc_cur_id INTEGER NULL REFERENCES page(page_id) ON DELETE SET NULL,
rc_this_oldid INTEGER NOT NULL,
rc_last_oldid INTEGER NOT NULL,
- rc_type CHAR NOT NULL DEFAULT '0',
+ rc_type SMALLINT NOT NULL DEFAULT 0,
rc_moved_to_ns SMALLINT,
rc_moved_to_title TEXT,
- rc_patrolled CHAR NOT NULL DEFAULT '0',
+ rc_patrolled SMALLINT NOT NULL DEFAULT 0,
rc_ip CIDR,
rc_old_len INTEGER,
rc_new_len INTEGER,
CREATE TABLE interwiki (
- iw_prefix TEXT NOT NULL UNIQUE,
- iw_url TEXT NOT NULL,
- iw_local CHAR NOT NULL,
- iw_trans CHAR NOT NULL DEFAULT '0'
+ iw_prefix TEXT NOT NULL UNIQUE,
+ iw_url TEXT NOT NULL,
+ iw_local SMALLINT NOT NULL,
+ iw_trans SMALLINT NOT NULL DEFAULT 0
);
CREATE INDEX ts2_page_title ON page USING gin(titlevector);
CREATE INDEX ts2_page_text ON pagecontent USING gin(textvector);
-CREATE FUNCTION add_interwiki (TEXT,INT,CHAR) RETURNS INT LANGUAGE SQL AS
+CREATE FUNCTION add_interwiki (TEXT,INT,SMALLINT) RETURNS INT LANGUAGE SQL AS
$mw$
INSERT INTO interwiki (iw_prefix, iw_url, iw_local) VALUES ($1,$2,$3);
SELECT 1;
);
- # table, column, desired type, USING clause if needed
+ # table, column, desired type, USING clause if needed (with new default if needed)
$typechanges = array(
array("archive", "ar_deleted", "smallint", ""),
+ array("archive", "ar_minor_edit", "smallint", "ar_minor_edit::smallint DEFAULT 0"),
array("filearchive", "fa_deleted", "smallint", ""),
array("filearchive", "fa_height", "integer", ""),
array("filearchive", "fa_metadata", "bytea", "decode(fa_metadata,'escape')"),
array("image", "img_size", "integer", ""),
array("image", "img_width", "integer", ""),
array("image", "img_height", "integer", ""),
+ array("interwiki", "iw_local", "smallint", "iw_local::smallint DEFAULT 0"),
+ array("interwiki", "iw_trans", "smallint", "iw_trans::smallint DEFAULT 0"),
+ array("ipblocks", "ipb_auto", "smallint", "ipb_auto::smallint DEFAULT 0"),
+ array("ipblocks", "ipb_anon_only", "smallint", "ipb_anon_only::smallint DEFAULT 0"),
+ array("ipblocks", "ipb_create_account", "smallint", "ipb_create_account::smallint DEFAULT 1"),
+ array("ipblocks", "ipb_enable_autoblock", "smallint", "ipb_enable_autoblock::smallint DEFAULT 1"),
+ array("ipblocks", "ipb_block_email", "smallint", "ipb_block_email::smallint DEFAULT 0"),
array("ipblocks", "ipb_address", "text", "ipb_address::text"),
array("ipblocks", "ipb_deleted", "smallint", ""),
array("math", "math_inputhash", "bytea", "decode(math_inputhash,'escape')"),
array("oldimage", "oi_height", "integer", ""),
array("oldimage", "oi_size", "integer", ""),
array("oldimage", "oi_width", "integer", ""),
+ array("page", "page_is_redirect","smallint", "page_is_redirect::smallint DEFAULT 0"),
+ array("page", "page_is_new", "smallint", "page_is_new::smallint DEFAULT 0"),
array("querycache", "qc_value", "integer", ""),
array("querycachetwo","qcc_value", "integer", ""),
+ array("recentchanges","rc_bot", "smallint", "rc_bot::smallint DEFAULT 0"),
array("recentchanges","rc_deleted", "smallint", ""),
+ array("recentchanges","rc_minor", "smallint", "rc_minor::smallint DEFAULT 0"),
+ array("recentchanges","rc_new", "smallint", "rc_new::smallint DEFAULT 0"),
+ array("recentchanges","rc_type", "smallint", "rc_type::smallint DEFAULT 0"),
+ array("recentchanges","rc_patrolled", "smallint", "rc_patrolled::smallint DEFAULT 0"),
+ array("revision", "rev_minor_edit", "smallint", "rev_minor_edit::smallint DEFAULT 0"),
array("templatelinks","tl_namespace", "smallint", "tl_namespace::smallint"),
array("user_newtalk", "user_ip", "text", "host(user_ip)"),
);
echo "Changing column type of \"$tc[0].$tc[1]\" from \"{$fi->type()}\" to \"$tc[2]\"\n";
$sql = "ALTER TABLE $tc[0] ALTER $tc[1] TYPE $tc[2]";
if (strlen($tc[3])) {
+ $default = array();
+ if (preg_match( '/DEFAULT (.+)/', $tc[3], $default)) {
+ $sqldef = "ALTER TABLE $tc[0] ALTER $tc[1] SET DEFAULT $default[1]";
+ $wgDatabase->query($sqldef);
+ $tc[3] = preg_replace( '/\s*DEFAULT .+/', '', $tc[3]);
+ }
$sql .= " USING $tc[3]";
}
$sql .= ";\nCOMMIT;\n";