r53046 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53045‎ | r53046 | r53047 >
Date:13:02, 10 July 2009
Author:werdna
Status:deferred
Tags:
Comment:
War on backwards-incompatibility!
* Rename migration script, and change it from a crappy hack to a total solution for running database and lazy updates.
* Organise, comment, rename and update schema change scripts.
* Fix schema change scripts to work with table prefixes.
* Mark one schema change script as unsafe. It's totally insane and unsafe to run unless you know what you're doing.
* Add lazy update for threads misplaced under the subject instead of the talk page. Might cause weirdness if you suddenly disable liquidthreads for a subject-space.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/LqtThread.php (modified) (history)
  • /trunk/extensions/LiquidThreads/migrateDatabase.php (added) (history)
  • /trunk/extensions/LiquidThreads/migrateFromPre51021.php (deleted) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/index-summary_page.sql (added) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-1.sql (deleted) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-2.sql (deleted) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-3.sql (deleted) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-4.sql (deleted) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-5.sql (deleted) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-6.sql (deleted) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-thread_summary.sql (deleted) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/move-namespaces-UNSAFE.sql (added) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/normalise-ancestry.sql (added) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/split-thread_article.sql (added) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/split-timestamps.sql (added) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/store-editedness.sql (added) (history)
  • /trunk/extensions/LiquidThreads/schema-changes/store_subject-author.sql (added) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/migrateFromPre51021.php
@@ -1,21 +0,0 @@
2 -<?php
3 -
4 -// Utility script to fix your database to work with breaking changes made in r51021 of
5 -// the LiquidThreads extension.
6 -
7 -// NOTE: This script may not work properly if you have taken advantage of the features made
8 -// possible by that revision (i.e. if you have set $wgLqtPages).
9 -
10 -require_once ( getenv('MW_INSTALL_PATH') !== false
11 - ? getenv('MW_INSTALL_PATH')."/maintenance/commandLine.inc"
12 - : dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' );
13 -
14 -$db = wfGetDB( DB_MASTER );
15 -
16 -do {
17 - $db->update( 'thread',
18 - array( 'thread_article_namespace=thread_article_namespace+1' ),
19 - array( 'thread_article_namespace mod 2 = 0'),
20 - __METHOD__,
21 - array( 'LIMIT' => 500 ) );
22 -} while ( $db->affectedRows() > 0 );
Index: trunk/extensions/LiquidThreads/migrateDatabase.php
@@ -0,0 +1,64 @@
 2+<?php
 3+
 4+// Utility script to update your LiquidThreads installation by batch-running lazy updates
 5+// normally done on-demand when a thread is loaded. Also runs any necessary database updates.
 6+
 7+require_once ( getenv('MW_INSTALL_PATH') !== false
 8+ ? getenv('MW_INSTALL_PATH')."/maintenance/commandLine.inc"
 9+ : dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' );
 10+
 11+$db = wfGetDB( DB_MASTER );
 12+
 13+// Do database updates
 14+$threadFieldUpdates = array('thread_article_namespace' => 'split-thread_article.sql',
 15+ 'thread_article_title' => 'split-thread_article.sql',
 16+ 'thread_ancestor' => 'normalise-ancestry.sql',
 17+ 'thread_parent' => 'normalise-ancestry.sql',
 18+ 'thread_modified' => 'split-timestamps.sql',
 19+ 'thread_created' => 'split-timestamps.sql',
 20+ 'thread_editedness' => 'store-editedness.sql',
 21+ 'thread_subject' => 'lqt-schema-change-thread_summary.sql',
 22+ 'thread_author_id' => 'store_subject-author.sql',
 23+ 'thread_author_name' => 'store_subject-author.sql',
 24+ );
 25+$threadIndexUpdates = array('thread_summary_page' => 'index-summary_page.sql');
 26+
 27+foreach( $threadFieldUpdates as $field => $patch ) {
 28+ if (!$db->fieldExists( 'thread', $field, 'lqt-update-script' ) ) {
 29+ dbsource( dirname( __FILE__ ).'/schema-changes/'.$patch );
 30+ }
 31+}
 32+
 33+foreach( $threadIndexUpdates as $index => $patch ) {
 34+ if (!$db->indexExists( 'thread', $index, 'lqt-update-script' ) ) {
 35+ dbsource( dirname( __FILE__ ).'/schema-changes/'.$patch );
 36+ }
 37+}
 38+
 39+
 40+// Batch lazy updates
 41+$upTo = $lastUpTo = 0;
 42+
 43+do {
 44+ $lastUpTo = $upTo;
 45+
 46+ $db->begin();
 47+
 48+ // Read 500 rows
 49+ $res = $db->select( 'thread', '*', array( 'thread_id>'.$db->addQuotes($upTo ) ),
 50+ 'lqt-update-script', array( 'LIMIT' => 500, 'FOR UPDATE',
 51+ 'ORDER BY' => 'thread_id asc' ) );
 52+
 53+ $threads = Threads::loadFromResult( $res );
 54+
 55+ foreach( $threads as $thread ) {
 56+ $thread->doLazyUpdates();
 57+
 58+ if ( $thread->id() > $upTo ) {
 59+ $upTo = $thread->id();
 60+ }
 61+ }
 62+
 63+ $db->commit();
 64+
 65+} while ( $lastUpTo != $upTo );
Property changes on: trunk/extensions/LiquidThreads/migrateDatabase.php
___________________________________________________________________
Name: svn:eol-style
166 + native
Index: trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-3.sql
@@ -1,13 +0,0 @@
2 -alter table thread add column thread_ancestor int(8) unsigned not null;
3 -alter table thread add column thread_parent int(8) unsigned null;
4 -alter table thread add index thread_ancestor (thread_ancestor);
5 -
6 -update thread set thread_ancestor = substring_index(thread_path, ".", 1),
7 - thread_parent = substring_index(substring_index(thread_path, ".", -2), ".", 1 )
8 -where locate(".", thread_path) != 0;
9 -
10 -update thread set thread_ancestor = substring_index(thread_path, ".", 1),
11 - thread_parent = null
12 -where locate(".", thread_path) = 0;
13 -
14 -alter table thread drop column thread_path;
Index: trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-4.sql
@@ -1,4 +0,0 @@
2 -alter table thread change thread_timestamp thread_modified char(14) binary NOT NULL default '';
3 -alter table thread add column thread_created char(14) binary NOT NULL default '';
4 -update thread set thread_created = thread_modified;
5 -alter table thread add index thread_created (thread_created);
Index: trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-5.sql
@@ -1,13 +0,0 @@
2 -alter table thread add column thread_editedness int(1) NOT NULL default 0;
3 -
4 -update thread join thread as child on child.thread_parent = thread.thread_id set thread.thread_editedness = 1;
5 -
6 -create temporary table counts ( thread_id int(8) unsigned, revision_count int(8) unsigned, author_count int(8) unsigned, rev_user int(8) unsigned );
7 -
8 -insert into counts (thread_id, revision_count, author_count, rev_user) select thread_id, count(thread_id), count(distinct rev_user), rev_user from thread join revision on rev_page = thread_root group by thread_id;
9 -
10 -update thread join counts on thread.thread_id = counts.thread_id set thread_editedness = 2 where revision_count > 1;
11 -
12 -update thread join counts on thread.thread_id = counts.thread_id set thread_editedness = 3 where author_count > 1 or (rev_user = 0 and revision_count > 1);
13 -
14 -drop table counts;
Index: trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-thread_summary.sql
@@ -1,5 +0,0 @@
2 -
3 -ALTER TABLE /*_*/thread add column thread_subject varchar(255) NULL;
4 -ALTER TABLE /*_*/thread add column thread_author_id int unsigned NULL;
5 -ALTER TABLE /*_*/thread add column thread_author_name varchar(255) NULL;
Index: trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-6.sql
@@ -1 +0,0 @@
2 -alter table thread add index thread_summary_page (thread_summary_page);
Index: trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-1.sql
@@ -1,5 +0,0 @@
2 -update thread, page set thread_article_title=page_title, thread_article_namespace=page_namespace where page_id=thread_article and thread_article is not null and thread_article != 0;
3 -
4 -alter table thread drop column thread_article;
5 -alter table thread modify thread_article_namespace not null;
6 -alter table thread modify thread_article_title varchar(255) binary not null;
Index: trunk/extensions/LiquidThreads/schema-changes/lqt-schema-change-2.sql
@@ -1,4 +0,0 @@
2 -update page set page_namespace=90 where page_namespace=16;
3 -update page set page_namespace=91 where page_namespace=17;
4 -update page set page_namespace=92 where page_namespace=18;
5 -update page set page_namespace=93 where page_namespace=19;
Index: trunk/extensions/LiquidThreads/schema-changes/store-editedness.sql
@@ -0,0 +1,29 @@
 2+-- Schema change 5 — adds and populates 'editedness' field
 3+-- for performantly determining if a thread has been edited.
 4+
 5+alter table /*_*/thread add column thread_editedness int(1) NOT NULL default 0;
 6+
 7+update /*_*/thread join /*_*/thread as child on child.thread_parent = /*_*/thread.thread_id
 8+ set thread.thread_editedness = 1;
 9+
 10+create temporary table /*_*/counts (
 11+ thread_id int(8) unsigned,
 12+ revision_count int(8) unsigned,
 13+ author_count int(8) unsigned,
 14+ rev_user int(8) unsigned
 15+);
 16+
 17+insert into /*_*/counts (thread_id, revision_count, author_count, rev_user)
 18+ select thread_id, count(thread_id), count(distinct rev_user), rev_user
 19+ from /*_*/thread join /*_*/revision on rev_page = thread_root
 20+ group by thread_id;
 21+
 22+update /*_*/thread join /*_*/counts on /*_*/thread.thread_id = /*_*/counts.thread_id
 23+ set thread_editedness = 2
 24+ where revision_count > 1;
 25+
 26+update /*_*/thread join counts on /*_*/thread.thread_id = /*_*/counts.thread_id
 27+ set thread_editedness = 3
 28+ where author_count > 1 or (rev_user = 0 and revision_count > 1);
 29+
 30+drop table /*_*/counts;
Property changes on: trunk/extensions/LiquidThreads/schema-changes/store-editedness.sql
___________________________________________________________________
Name: svn:eol-style
131 + native
Index: trunk/extensions/LiquidThreads/schema-changes/move-namespaces-UNSAFE.sql
@@ -0,0 +1,8 @@
 2+-- This schema change is seriously scary. Don't run it unless you know what you're doing!
 3+-- It assumes that the LiquidThreads namespaces are namespaces 16-19, and that you want
 4+-- to move your data from those ones to namespaces 90-93.
 5+
 6+update page set page_namespace=90 where page_namespace=16;
 7+update page set page_namespace=91 where page_namespace=17;
 8+update page set page_namespace=92 where page_namespace=18;
 9+update page set page_namespace=93 where page_namespace=19;
Property changes on: trunk/extensions/LiquidThreads/schema-changes/move-namespaces-UNSAFE.sql
___________________________________________________________________
Name: svn:eol-style
110 + native
Index: trunk/extensions/LiquidThreads/schema-changes/split-thread_article.sql
@@ -0,0 +1,12 @@
 2+-- Schema change 1 — replaces thread_article with thread_article_namespace/title tuple
 3+
 4+update /*_*/thread, /*_*/page
 5+ set thread_article_title=page_title,
 6+ thread_article_namespace=page_namespace
 7+ where page_id=thread_article and
 8+ thread_article is not null and
 9+ thread_article != 0;
 10+
 11+alter table /*_*/thread drop column thread_article;
 12+alter table /*_*/thread modify thread_article_namespace not null;
 13+alter table /*_*/thread modify thread_article_title varchar(255) binary not null;
Property changes on: trunk/extensions/LiquidThreads/schema-changes/split-thread_article.sql
___________________________________________________________________
Name: svn:eol-style
114 + native
Index: trunk/extensions/LiquidThreads/schema-changes/store_subject-author.sql
@@ -0,0 +1,5 @@
 2+-- Schema change 7 — add thread subject to the thread table.
 3+
 4+ALTER TABLE /*_*/thread add column thread_subject varchar(255) NULL;
 5+ALTER TABLE /*_*/thread add column thread_author_id int unsigned NULL;
 6+ALTER TABLE /*_*/thread add column thread_author_name varchar(255) NULL;
Property changes on: trunk/extensions/LiquidThreads/schema-changes/store_subject-author.sql
___________________________________________________________________
Name: svn:eol-style
17 + native
Index: trunk/extensions/LiquidThreads/schema-changes/index-summary_page.sql
@@ -0,0 +1,3 @@
 2+-- Schema change 6, adds thread_summary_page index.
 3+
 4+alter table /*_*/thread add index thread_summary_page (thread_summary_page);
Property changes on: trunk/extensions/LiquidThreads/schema-changes/index-summary_page.sql
___________________________________________________________________
Name: svn:eol-style
15 + native
Index: trunk/extensions/LiquidThreads/schema-changes/normalise-ancestry.sql
@@ -0,0 +1,16 @@
 2+-- Schema change 3 — replaces thread_path field with a tuple of ancestor/parent for
 3+-- more normalised reply tracking.
 4+
 5+alter table /*_*/thread add column thread_ancestor int(8) unsigned not null;
 6+alter table /*_*/thread add column thread_parent int(8) unsigned null;
 7+alter table /*_*/thread add index thread_ancestor (thread_ancestor);
 8+
 9+update /*_*/thread set thread_ancestor = substring_index(thread_path, ".", 1),
 10+ thread_parent = substring_index(substring_index(thread_path, ".", -2), ".", 1 )
 11+where locate(".", thread_path) != 0;
 12+
 13+update /*_*/thread set thread_ancestor = substring_index(thread_path, ".", 1),
 14+ thread_parent = null
 15+where locate(".", thread_path) = 0;
 16+
 17+alter table /*_*/thread drop column thread_path;
Property changes on: trunk/extensions/LiquidThreads/schema-changes/normalise-ancestry.sql
___________________________________________________________________
Name: svn:eol-style
118 + native
Index: trunk/extensions/LiquidThreads/schema-changes/split-timestamps.sql
@@ -0,0 +1,7 @@
 2+-- Schema change 4 — Replaces thread_timestamp with thread_modified and thread_created
 3+-- Also adds a thread_created index.
 4+
 5+alter table /*_*/thread change thread_timestamp thread_modified char(14) binary NOT NULL default '';
 6+alter table /*_*/thread add column thread_created char(14) binary NOT NULL default '';
 7+update /*_*/thread set thread_created = thread_modified where thread_created='';
 8+alter /*_*/table thread add index /*i*/thread_created (thread_created);
Property changes on: trunk/extensions/LiquidThreads/schema-changes/split-timestamps.sql
___________________________________________________________________
Name: svn:eol-style
19 + native
Index: trunk/extensions/LiquidThreads/classes/LqtThread.php
@@ -445,6 +445,25 @@
446446 $set['thread_author_id'] = $this->authorId;
447447 }
448448
 449+ //Check for article being in subject, not talk namespace.
 450+ //If the page is non-LiquidThreads and it's in subject-space, we'll assume it's meant
 451+ // to be on the corresponding talk page, but only if the talk-page is a LQT page.
 452+ //(Previous versions stored the subject page, for some totally bizarre reason)
 453+ $articleTitle = $this->article()->getTitle();
 454+ if ( !LqtDispatch::isLqtPage( $articleTitle ) && !$articleTitle->isTalkPage() &&
 455+ LqtDispatch::isLqtPage( $articleTitle->getTalkPage() ) ) {
 456+ $newTitle = $articleTitle->getTalkPage();
 457+ $newArticle = new Article( $newTitle );
 458+
 459+ $set['thread_article_namespace'] = $newTitle->getNamespace();
 460+ $set['thread_article_title'] = $newTitle->getTitle();
 461+
 462+ $this->articleNamespace = $newTitle->getNamespace();
 463+ $this->articleTitle = $newTitle->getDbKey();
 464+
 465+ $this->article = $newArticle;
 466+ }
 467+
449468 // Check for article corruption from incomplete thread moves.
450469 // (thread moves only updated this on immediate replies, not replies to replies etc)
451470 if (! $ancestor->article()->getTitle()->equals( $this->article()->getTitle() ) ) {

Status & tagging log