Add default for revision.rev_text_id where missing
authoraddshore <addshorewiki@gmail.com>
Mon, 12 Mar 2018 16:21:02 +0000 (16:21 +0000)
committeraddshore <addshorewiki@gmail.com>
Mon, 19 Mar 2018 18:20:27 +0000 (18:20 +0000)
This adds a default of 0 for:
 - Mssql
 - Mysql
 - Sqlite

The field is already NULLable in:
 - Oracle
 - Postgres

Bug: T188741
Change-Id: Ibe1cc363d21fb96f38c263181bf30a429a1c7b45

includes/installer/MssqlUpdater.php
includes/installer/MysqlUpdater.php
includes/installer/SqliteUpdater.php
maintenance/archives/patch-rev_text_id-default.sql [new file with mode: 0644]
maintenance/mssql/archives/patch-rev_text_id-default.sql [new file with mode: 0644]
maintenance/mssql/tables.sql
maintenance/sqlite/archives/patch-rev_text_id-default.sql [new file with mode: 0644]
maintenance/tables.sql

index 38a9ede..1d9991f 100644 (file)
@@ -118,6 +118,7 @@ class MssqlUpdater extends DatabaseUpdater {
                        [ 'migrateArchiveText' ],
                        [ 'addTable', 'actor', 'patch-actor-table.sql' ],
                        [ 'migrateActors' ],
+                       [ 'modifyField', 'revision', 'rev_text_id', 'patch-rev_text_id-default.sql' ],
                ];
        }
 
index bce4690..1d1f500 100644 (file)
@@ -338,6 +338,7 @@ class MysqlUpdater extends DatabaseUpdater {
                        [ 'migrateArchiveText' ],
                        [ 'addTable', 'actor', 'patch-actor-table.sql' ],
                        [ 'migrateActors' ],
+                       [ 'modifyField', 'revision', 'rev_text_id', 'patch-rev_text_id-default.sql' ],
                ];
        }
 
index 3a755b6..112b517 100644 (file)
@@ -202,6 +202,7 @@ class SqliteUpdater extends DatabaseUpdater {
                        [ 'migrateArchiveText' ],
                        [ 'addTable', 'actor', 'patch-actor-table.sql' ],
                        [ 'migrateActors' ],
+                       [ 'modifyField', 'revision', 'rev_text_id', 'patch-rev_text_id-default.sql' ],
                ];
        }
 
diff --git a/maintenance/archives/patch-rev_text_id-default.sql b/maintenance/archives/patch-rev_text_id-default.sql
new file mode 100644 (file)
index 0000000..dc6e4c6
--- /dev/null
@@ -0,0 +1,10 @@
+--
+-- Adds a default value to the rev_text_id field in the revision table.
+-- This is to allow the Multi Content Revisions migration to happen where
+-- rows will have to be added to the revision table with no rev_text_id.
+--
+-- 2018-03-12
+--
+
+ALTER TABLE /*$wgDBprefix*/revision
+  ALTER COLUMN rev_text_id SET DEFAULT 0;
\ No newline at end of file
diff --git a/maintenance/mssql/archives/patch-rev_text_id-default.sql b/maintenance/mssql/archives/patch-rev_text_id-default.sql
new file mode 100644 (file)
index 0000000..0c9d48a
--- /dev/null
@@ -0,0 +1,10 @@
+--
+-- Adds a default value to the rev_text_id field in the revision table.
+-- This is to allow the Multi Content Revisions migration to happen where
+-- rows will have to be added to the revision table with no rev_text_id.
+--
+-- 2018-03-12
+--
+
+ALTER TABLE /*_*/revision
+  ADD CONSTRAINT DF_rev_text_id DEFAULT 0 FOR rev_text_id;
\ No newline at end of file
index 5348c47..dbdcb24 100644 (file)
@@ -191,7 +191,7 @@ INSERT INTO /*_*/page (page_namespace, page_title, page_restrictions, page_lates
 CREATE TABLE /*_*/revision (
    rev_id INT NOT NULL UNIQUE IDENTITY(0,1),
    rev_page INT NOT NULL REFERENCES /*_*/page(page_id) ON DELETE CASCADE,
-   rev_text_id INT  NOT NULL, -- FK added later
+   rev_text_id INT NOT NULL CONSTRAINT DF_rev_text_id DEFAULT 0, -- FK added later
    rev_comment NVARCHAR(255) NOT NULL CONSTRAINT DF_rev_comment DEFAULT '',
    rev_user INT REFERENCES /*_*/mwuser(user_id) ON DELETE SET NULL,
    rev_user_text NVARCHAR(255) NOT NULL DEFAULT '',
diff --git a/maintenance/sqlite/archives/patch-rev_text_id-default.sql b/maintenance/sqlite/archives/patch-rev_text_id-default.sql
new file mode 100644 (file)
index 0000000..c8e032b
--- /dev/null
@@ -0,0 +1,53 @@
+--
+-- Adds a default value to the rev_text_id field in the revision table.
+-- This is to allow the Multi Content Revisions migration to happen where
+-- rows will have to be added to the revision table with no rev_text_id.
+--
+-- 2018-03-12
+--
+
+BEGIN TRANSACTION;
+
+DROP TABLE IF EXISTS /*_*/revision_tmp;
+
+CREATE TABLE /*_*/revision_tmp (
+  rev_id int unsigned NOT NULL PRIMARY KEY AUTO_INCREMENT,
+  rev_page int unsigned NOT NULL,
+  rev_text_id int unsigned NOT NULL default 0,
+  rev_comment varbinary(767) NOT NULL default '',
+  rev_user int unsigned NOT NULL default 0,
+  rev_user_text varchar(255) binary NOT NULL default '',
+  rev_timestamp binary(14) NOT NULL default '',
+  rev_minor_edit tinyint unsigned NOT NULL default 0,
+  rev_deleted tinyint unsigned NOT NULL default 0,
+  rev_len int unsigned,
+  rev_parent_id int unsigned default NULL,
+  rev_sha1 varbinary(32) NOT NULL default '',
+  rev_content_model varbinary(32) DEFAULT NULL,
+  rev_content_format varbinary(64) DEFAULT NULL
+
+) /*$wgDBTableOptions*/ MAX_ROWS=10000000 AVG_ROW_LENGTH=1024;
+
+INSERT OR IGNORE INTO /*_*/revision_tmp (
+    rev_id, rev_page, rev_text_id, rev_comment, rev_user, rev_user_text,
+    rev_timestamp, rev_minor_edit, rev_deleted, rev_len, rev_parent_id,
+    rev_sha1, rev_content_model, rev_content_format
+    )
+    SELECT
+    rev_id, rev_page, rev_text_id, rev_comment, rev_user, rev_user_text,
+    rev_timestamp, rev_minor_edit, rev_deleted, rev_len, rev_parent_id,
+    rev_sha1, rev_content_model, rev_content_format
+    FROM /*_*/revision;
+
+DROP TABLE /*_*/revision;
+
+ALTER TABLE /*_*/revision_tmp RENAME TO /*_*/revision;
+
+CREATE INDEX /*i*/rev_page_id ON /*_*/revision (rev_page, rev_id);
+CREATE INDEX /*i*/rev_timestamp ON /*_*/revision (rev_timestamp);
+CREATE INDEX /*i*/page_timestamp ON /*_*/revision (rev_page,rev_timestamp);
+CREATE INDEX /*i*/user_timestamp ON /*_*/revision (rev_user,rev_timestamp);
+CREATE INDEX /*i*/usertext_timestamp ON /*_*/revision (rev_user_text,rev_timestamp);
+CREATE INDEX /*i*/page_user_timestamp ON /*_*/revision (rev_page,rev_user,rev_timestamp);
+
+COMMIT;
index 990ba3d..1ccc7ce 100644 (file)
@@ -365,7 +365,7 @@ CREATE TABLE /*_*/revision (
   -- It's possible for multiple revisions to use the same text,
   -- for instance revisions where only metadata is altered
   -- or a rollback to a previous version.
-  rev_text_id int unsigned NOT NULL,
+  rev_text_id int unsigned NOT NULL default 0,
 
   -- Text comment summarizing the change. Deprecated in favor of
   -- revision_comment_temp.revcomment_comment_id.