Make Schema changes for Partial Blocks
authorDavid Barratt <dbarratt@wikimedia.org>
Mon, 18 Jun 2018 14:26:20 +0000 (10:26 -0400)
committerRoan Kattouw <roan.kattouw@gmail.com>
Fri, 7 Sep 2018 22:25:49 +0000 (15:25 -0700)
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

16 files changed:
includes/installer/MssqlUpdater.php
includes/installer/MysqlUpdater.php
includes/installer/OracleUpdater.php
includes/installer/PostgresUpdater.php
includes/installer/SqliteUpdater.php
maintenance/archives/patch-ipb_sitewide.sql [new file with mode: 0644]
maintenance/archives/patch-ipblocks_restrictions-table.sql [new file with mode: 0644]
maintenance/mssql/archives/patch-ipb_sitewide.sql [new file with mode: 0644]
maintenance/mssql/archives/patch-ipblocks_restrictions-table.sql [new file with mode: 0644]
maintenance/mssql/tables.sql
maintenance/oracle/archives/patch-ipb_sitewide.sql [new file with mode: 0644]
maintenance/oracle/archives/patch-ipblocks_restrictions-table.sql [new file with mode: 0644]
maintenance/oracle/tables.sql
maintenance/postgres/archives/patch-ipblocks_restrictions-table.sql [new file with mode: 0644]
maintenance/postgres/tables.sql
maintenance/tables.sql

index 8442713..17b1d7e 100644 (file)
@@ -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' ],
                ];
        }
 
index 8afec4a..2423634 100644 (file)
@@ -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' ],
                ];
        }
 
index 020c687..5833299 100644 (file)
@@ -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' ],
index 8336d6a..8fd5370 100644 (file)
@@ -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' ],
                ];
        }
 
index e5e88aa..eb2d8c2 100644 (file)
@@ -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 (file)
index 0000000..c5060b6
--- /dev/null
@@ -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 (file)
index 0000000..a9c90b4
--- /dev/null
@@ -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 (file)
index 0000000..4f7ef8e
--- /dev/null
@@ -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 (file)
index 0000000..e3095dd
--- /dev/null
@@ -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);
index 91bd941..2b95b43 100644 (file)
@@ -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 (file)
index 0000000..e9affb9
--- /dev/null
@@ -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 (file)
index 0000000..d44417c
--- /dev/null
@@ -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);
index b491b98..c3f0717 100644 (file)
@@ -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 (file)
index 0000000..f3317cd
--- /dev/null
@@ -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);
index 942a05b..003204d 100644 (file)
@@ -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,
index 409fbd7..8edc3c3 100644 (file)
@@ -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.