From: Dereckson Date: Tue, 15 Oct 2013 19:46:39 +0000 (+0200) Subject: Add DROP INDEX support to DatabaseSqlite::replaceVars method X-Git-Tag: 1.31.0-rc.0~18291^2 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=60596ab27ed238b0adae839781f0867446fc6652;p=lhc%2Fweb%2Fwiklou.git Add DROP INDEX support to DatabaseSqlite::replaceVars method DROP INDEX is database-wide (and not table-specific) in SQLite, so we need to add a rule in our MySQL to SQLite schema convert. "DROP INDEX foo ON bar" becomes "DROP INDEX foo". Change-Id: Ie10784d166ed5a7f6ea52cf4f3a812fb7878a744 --- diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index a8270bf4b3..aff33d3344 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -794,6 +794,9 @@ class DatabaseSqlite extends DatabaseBase { $s = preg_replace( '/\(\d+\)/', '', $s ); // No FULLTEXT $s = preg_replace( '/\bfulltext\b/i', '', $s ); + } elseif ( preg_match( '/^\s*DROP INDEX/i', $s ) ) { + // DROP INDEX is database-wide, not table-specific, so no ON clause. + $s = preg_replace( '/\sON\s+[^\s]*/i', '', $s ); } return $s; } diff --git a/tests/phpunit/includes/db/DatabaseSqliteTest.php b/tests/phpunit/includes/db/DatabaseSqliteTest.php index 91ab33a722..36e8d4b551 100644 --- a/tests/phpunit/includes/db/DatabaseSqliteTest.php +++ b/tests/phpunit/includes/db/DatabaseSqliteTest.php @@ -141,6 +141,14 @@ class DatabaseSqliteTest extends MediaWikiTestCase { $this->assertEquals( "ALTER TABLE foo ADD COLUMN foo_bar INTEGER DEFAULT 42", $this->replaceVars( "ALTER TABLE foo\nADD COLUMN foo_bar int(10) unsigned DEFAULT 42" ) ); + + $this->assertEquals( "DROP INDEX foo", + $this->replaceVars( "DROP INDEX /*i*/foo ON /*_*/bar" ) + ); + + $this->assertEquals( "DROP INDEX foo -- dropping index", + $this->replaceVars( "DROP INDEX /*i*/foo ON /*_*/bar -- dropping index" ) + ); } public function testTableName() {