From: David Barratt Date: Mon, 18 Jun 2018 14:26:20 +0000 (-0400) Subject: Make Schema changes for Partial Blocks X-Git-Tag: 1.34.0-rc.0~4160^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=c2bd4b12c7c3c1e9cecd87e7683d4acdb2b4697e;p=lhc%2Fweb%2Fwiklou.git Make Schema changes for Partial Blocks Update the database schema so a block can be switched between a sitewide and partial block. Also add the restrictions table for specifiying the partial blocks. Bug: T197144 Change-Id: I4a725312c4b980a1b14e5ca826069fa2278a5913 --- diff --git a/includes/installer/MssqlUpdater.php b/includes/installer/MssqlUpdater.php index 84427136cf..17b1d7e533 100644 --- a/includes/installer/MssqlUpdater.php +++ b/includes/installer/MssqlUpdater.php @@ -149,6 +149,8 @@ class MssqlUpdater extends DatabaseUpdater { [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ], [ 'addIndex', 'change_tag', 'change_tag_rc_tag_id', 'patch-change_tag-change_tag_rc_tag_id.sql' ], + [ 'addField', 'ipblocks', 'ipb_sitewide', 'patch-ipb_sitewide.sql' ], + [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ], ]; } diff --git a/includes/installer/MysqlUpdater.php b/includes/installer/MysqlUpdater.php index 8afec4a481..242363466b 100644 --- a/includes/installer/MysqlUpdater.php +++ b/includes/installer/MysqlUpdater.php @@ -369,6 +369,8 @@ class MysqlUpdater extends DatabaseUpdater { [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ], [ 'addIndex', 'change_tag', 'change_tag_rc_tag_id', 'patch-change_tag-change_tag_rc_tag_id.sql' ], + [ 'addField', 'ipblocks', 'ipb_sitewide', 'patch-ipb_sitewide.sql' ], + [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ], ]; } diff --git a/includes/installer/OracleUpdater.php b/includes/installer/OracleUpdater.php index 020c687b94..5833299e3f 100644 --- a/includes/installer/OracleUpdater.php +++ b/includes/installer/OracleUpdater.php @@ -160,6 +160,8 @@ class OracleUpdater extends DatabaseUpdater { [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ], [ 'addIndex', 'change_tag', 'change_tag_i03', 'patch-change_tag-change_tag_rc_tag_id.sql' ], + [ 'addField', 'ipblocks', 'ipb_sitewide', 'patch-ipb_sitewide.sql' ], + [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ], // KEEP THIS AT THE BOTTOM!! [ 'doRebuildDuplicateFunction' ], diff --git a/includes/installer/PostgresUpdater.php b/includes/installer/PostgresUpdater.php index 8336d6a91c..8fd5370367 100644 --- a/includes/installer/PostgresUpdater.php +++ b/includes/installer/PostgresUpdater.php @@ -595,6 +595,8 @@ class PostgresUpdater extends DatabaseUpdater { [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ], [ 'addIndex', 'change_tag', 'change_tag_rc_tag_id', 'patch-change_tag-change_tag_rc_tag_id.sql' ], + [ 'addPgField', 'ipblocks', 'ipb_sitewide', 'SMALLINT NOT NULL DEFAULT 1' ], + [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ], ]; } diff --git a/includes/installer/SqliteUpdater.php b/includes/installer/SqliteUpdater.php index e5e88aaf20..eb2d8c2040 100644 --- a/includes/installer/SqliteUpdater.php +++ b/includes/installer/SqliteUpdater.php @@ -234,6 +234,8 @@ class SqliteUpdater extends DatabaseUpdater { [ 'runMaintenance', PopulateChangeTagDef::class, 'maintenance/populateChangeTagDef.php' ], [ 'addIndex', 'change_tag', 'change_tag_rc_tag_id', 'patch-change_tag-change_tag_rc_tag_id.sql' ], + [ 'addField', 'ipblocks', 'ipb_sitewide', 'patch-ipb_sitewide.sql' ], + [ 'addTable', 'ipblocks_restrictions', 'patch-ipblocks_restrictions-table.sql' ], ]; } diff --git a/maintenance/archives/patch-ipb_sitewide.sql b/maintenance/archives/patch-ipb_sitewide.sql new file mode 100644 index 0000000000..c5060b6d0e --- /dev/null +++ b/maintenance/archives/patch-ipb_sitewide.sql @@ -0,0 +1,3 @@ +-- Adding ipb_sitewide for blocks +ALTER TABLE /*$wgDBprefix*/ipblocks + ADD ipb_sitewide bool NOT NULL default 1; diff --git a/maintenance/archives/patch-ipblocks_restrictions-table.sql b/maintenance/archives/patch-ipblocks_restrictions-table.sql new file mode 100644 index 0000000000..a9c90b4954 --- /dev/null +++ b/maintenance/archives/patch-ipblocks_restrictions-table.sql @@ -0,0 +1,11 @@ +-- For partial block restrictions -- + +CREATE TABLE /*_*/ipblocks_restrictions ( + ir_ipb_id int NOT NULL, + ir_type tinyint NOT NULL, + ir_value int NOT NULL, + PRIMARY KEY (ir_ipb_id, ir_type, ir_value) +) /*$wgDBTableOptions*/; + +-- Index to query restrictions by the page or namespace. +CREATE INDEX /*i*/ir_type_value ON /*_*/ipblocks_restrictions (ir_type, ir_value); diff --git a/maintenance/mssql/archives/patch-ipb_sitewide.sql b/maintenance/mssql/archives/patch-ipb_sitewide.sql new file mode 100644 index 0000000000..4f7ef8ef79 --- /dev/null +++ b/maintenance/mssql/archives/patch-ipb_sitewide.sql @@ -0,0 +1,3 @@ +-- Adding ipb_sitewide for blocks +ALTER TABLE /*$wgDBprefix*/ipblocks + ADD ipb_sitewide bit NOT NULL CONSTRAINT DF_ipb_sitewide DEFAULT 1; diff --git a/maintenance/mssql/archives/patch-ipblocks_restrictions-table.sql b/maintenance/mssql/archives/patch-ipblocks_restrictions-table.sql new file mode 100644 index 0000000000..e3095dd9ab --- /dev/null +++ b/maintenance/mssql/archives/patch-ipblocks_restrictions-table.sql @@ -0,0 +1,11 @@ +-- For partial block restrictions -- + +CREATE TABLE /*_*/ipblocks_restrictions ( + ir_ipb_id int NOT NULL CONSTRAINT FK_ir_ipb_id FOREIGN KEY REFERENCES /*_*/ipblocks(ipb_id) ON DELETE CASCADE, + ir_type tinyint NOT NULL, + ir_value int NOT NULL, + CONSTRAINT PK_ipblocks_restrictions PRIMARY KEY (ir_ipb_id, ir_type, ir_value) +) /*$wgDBTableOptions*/; + +-- Index to query restrictions by the page or namespace. +CREATE INDEX /*i*/ir_type_value ON /*_*/ipblocks_restrictions (ir_type, ir_value); diff --git a/maintenance/mssql/tables.sql b/maintenance/mssql/tables.sql index 91bd9413e4..2b95b435bd 100644 --- a/maintenance/mssql/tables.sql +++ b/maintenance/mssql/tables.sql @@ -698,8 +698,11 @@ CREATE TABLE /*_*/ipblocks ( -- Autoblocks set this to the original block -- so that the original block being deleted also -- deletes the autoblocks - ipb_parent_block_id int default NULL REFERENCES /*_*/ipblocks(ipb_id) + ipb_parent_block_id int default NULL REFERENCES /*_*/ipblocks(ipb_id), + -- Block user from editing any page on the site (other than their own user + -- talk page). + ipb_sitewide bit NOT NULL CONSTRAINT DF_ipb_sitewide DEFAULT 1 ); -- Unique index to support "user already blocked" messages @@ -712,6 +715,26 @@ CREATE INDEX /*i*/ipb_timestamp ON /*_*/ipblocks (ipb_timestamp); CREATE INDEX /*i*/ipb_expiry ON /*_*/ipblocks (ipb_expiry); CREATE INDEX /*i*/ipb_parent_block_id ON /*_*/ipblocks (ipb_parent_block_id); +-- +-- Partial Block Restrictions +-- +CREATE TABLE /*_*/ipblocks_restrictions ( + + -- The ipb_id from ipblocks + ir_ipb_id int NOT NULL CONSTRAINT FK_ir_ipb_id FOREIGN KEY REFERENCES /*_*/ipblocks(ipb_id) ON DELETE CASCADE, + + -- The restriction type id. + ir_type tinyint NOT NULL, + + -- The restriction id that corrposponds to the type. Typically a Page ID or a + -- Namespace ID. + ir_value int NOT NULL, + + CONSTRAINT PK_ipblocks_restrictions PRIMARY KEY (ir_ipb_id, ir_type, ir_value) +) /*$wgDBTableOptions*/; + +-- Index to query restrictions by the page or namespace. +CREATE INDEX /*i*/ir_type_value ON /*_*/ipblocks_restrictions (ir_type, ir_value); -- -- Uploaded images and other files. diff --git a/maintenance/oracle/archives/patch-ipb_sitewide.sql b/maintenance/oracle/archives/patch-ipb_sitewide.sql new file mode 100644 index 0000000000..e9affb906e --- /dev/null +++ b/maintenance/oracle/archives/patch-ipb_sitewide.sql @@ -0,0 +1,3 @@ +-- Adding ipb_sitewide for blocks +ALTER TABLE &mw_prefix.ipblocks + ADD ipb_sitewide CHAR(1) DEFAULT '1' NOT NULL; diff --git a/maintenance/oracle/archives/patch-ipblocks_restrictions-table.sql b/maintenance/oracle/archives/patch-ipblocks_restrictions-table.sql new file mode 100644 index 0000000000..d44417cd72 --- /dev/null +++ b/maintenance/oracle/archives/patch-ipblocks_restrictions-table.sql @@ -0,0 +1,12 @@ +-- For partial block restrictions -- + +CREATE TABLE &mw_prefix.ipblocks_restrictions ( + ir_ipb_id NUMBER NOT NULL, + ir_type NUMBER NOT NULL, + ir_value NUMBER NOT NULL +); + +ALTER TABLE &mw_prefix.ipblocks_restrictions ADD CONSTRAINT ipblocks_restrictions_pk PRIMARY KEY (ir_ipb_id, ir_type, ir_value); + +-- Index to query restrictions by the page or namespace. +CREATE INDEX &mw_prefix.ir_type_value ON &mw_prefix.ipblocks_restrictions (ir_type, ir_value); diff --git a/maintenance/oracle/tables.sql b/maintenance/oracle/tables.sql index b491b98b27..c3f0717672 100644 --- a/maintenance/oracle/tables.sql +++ b/maintenance/oracle/tables.sql @@ -511,6 +511,7 @@ CREATE TABLE &mw_prefix.ipblocks ( ipb_block_email CHAR(1) DEFAULT '0' NOT NULL, ipb_allow_usertalk CHAR(1) DEFAULT '0' NOT NULL, ipb_parent_block_id NUMBER DEFAULT NULL + ipb_sitewide CHAR(1) DEFAULT '1' NOT NULL ); ALTER TABLE &mw_prefix.ipblocks ADD CONSTRAINT &mw_prefix.ipblocks_pk PRIMARY KEY (ipb_id); ALTER TABLE &mw_prefix.ipblocks ADD CONSTRAINT &mw_prefix.ipblocks_fk1 FOREIGN KEY (ipb_user) REFERENCES &mw_prefix.mwuser(user_id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED; @@ -530,6 +531,14 @@ BEGIN END; /*$mw$*/ +CREATE TABLE &mw_prefix.ipblocks_restrictions ( + ir_ipb_id NUMBER NOT NULL, + ir_type NUMBER NOT NULL, + ir_value NUMBER NOT NULL +); +ALTER TABLE &mw_prefix.ipblocks_restrictions ADD CONSTRAINT ipblocks_restrictions_pk PRIMARY KEY (ir_ipb_id, ir_type, ir_value); +CREATE INDEX &mw_prefix.ir_type_value ON &mw_prefix.ipblocks_restrictions (ir_type, ir_value); + CREATE TABLE &mw_prefix.image ( img_name VARCHAR2(255) NOT NULL, img_size NUMBER DEFAULT 0 NOT NULL, diff --git a/maintenance/postgres/archives/patch-ipblocks_restrictions-table.sql b/maintenance/postgres/archives/patch-ipblocks_restrictions-table.sql new file mode 100644 index 0000000000..f3317cdf59 --- /dev/null +++ b/maintenance/postgres/archives/patch-ipblocks_restrictions-table.sql @@ -0,0 +1,11 @@ +-- For partial block restrictions -- + +CREATE TABLE ipblocks_restrictions ( + ir_ipb_id INTEGER NOT NULL REFERENCES ipblocks(ipb_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + ir_type SMALLINT NOT NULL, + ir_value INTEGER NOT NULL, + PRIMARY KEY (ir_ipb_id, ir_type, ir_value) +); + +-- Index to query restrictions by the page or namespace. +CREATE INDEX /*i*/ir_type_value ON /*_*/ipblocks_restrictions (ir_type, ir_value); diff --git a/maintenance/postgres/tables.sql b/maintenance/postgres/tables.sql index 942a05b957..003204dae3 100644 --- a/maintenance/postgres/tables.sql +++ b/maintenance/postgres/tables.sql @@ -423,7 +423,8 @@ CREATE TABLE ipblocks ( ipb_deleted SMALLINT NOT NULL DEFAULT 0, ipb_block_email SMALLINT NOT NULL DEFAULT 0, ipb_allow_usertalk SMALLINT NOT NULL DEFAULT 0, - ipb_parent_block_id INTEGER NULL REFERENCES ipblocks(ipb_id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED + ipb_parent_block_id INTEGER NULL REFERENCES ipblocks(ipb_id) ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED, + ipb_sitewide SMALLINT NOT NULL DEFAULT 1 ); ALTER SEQUENCE ipblocks_ipb_id_seq OWNED BY ipblocks.ipb_id; CREATE UNIQUE INDEX ipb_address_unique ON ipblocks (ipb_address,ipb_user,ipb_auto,ipb_anon_only); @@ -431,6 +432,14 @@ CREATE INDEX ipb_user ON ipblocks (ipb_user); CREATE INDEX ipb_range ON ipblocks (ipb_range_start,ipb_range_end); CREATE INDEX ipb_parent_block_id ON ipblocks (ipb_parent_block_id); +CREATE TABLE ipblocks_restrictions ( + ir_ipb_id INTEGER NOT NULL REFERENCES ipblocks(ipb_id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED, + ir_type SMALLINT NOT NULL, + ir_value INTEGER NOT NULL, + PRIMARY KEY (ir_ipb_id, ir_type, ir_value) +); +CREATE INDEX /*i*/ir_type_value ON /*_*/ipblocks_restrictions (ir_type, ir_value); + CREATE TABLE image ( img_name TEXT NOT NULL PRIMARY KEY, diff --git a/maintenance/tables.sql b/maintenance/tables.sql index 409fbd7173..8edc3c3f5e 100644 --- a/maintenance/tables.sql +++ b/maintenance/tables.sql @@ -1091,7 +1091,11 @@ CREATE TABLE /*_*/ipblocks ( -- Autoblocks set this to the original block -- so that the original block being deleted also -- deletes the autoblocks - ipb_parent_block_id int default NULL + ipb_parent_block_id int default NULL, + + -- Block user from editing any page on the site (other than their own user + -- talk page). + ipb_sitewide bool NOT NULL default 1 ) /*$wgDBTableOptions*/; @@ -1114,6 +1118,26 @@ CREATE INDEX /*i*/ipb_expiry ON /*_*/ipblocks (ipb_expiry); -- Index for removing autoblocks when a parent block is removed CREATE INDEX /*i*/ipb_parent_block_id ON /*_*/ipblocks (ipb_parent_block_id); +-- +-- Partial Block Restrictions +-- +CREATE TABLE /*_*/ipblocks_restrictions ( + + -- The ipb_id from ipblocks + ir_ipb_id int NOT NULL, + + -- The restriction type id. + ir_type tinyint(1) NOT NULL, + + -- The restriction id that corrposponds to the type. Typically a Page ID or a + -- Namespace ID. + ir_value int NOT NULL, + + PRIMARY KEY (ir_ipb_id, ir_type, ir_value) +) /*$wgDBTableOptions*/; + +-- Index to query restrictions by the page or namespace. +CREATE INDEX /*i*/ir_type_value ON /*_*/ipblocks_restrictions (ir_type, ir_value); -- -- Uploaded images and other files.