Gergő Tisza has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/255492

Change subject: Drop duplicate SQL files
......................................................................

Drop duplicate SQL files

With minimal exception, SQL files for MySQL and SQLite support are
the same. Prevent code duplication by falling back to the generic
version an SQL-dialect-specific version is not available.

This mirrors how patchfiles are handled in core.

Bug: T110267
Change-Id: I6853be84d212bf4738a1def3365f2676a3d36676
---
M backend/schema/MWOAuthUpdater.hooks.php
R backend/schema/OAuth.sql
R backend/schema/callback_is_prefix.sql
R backend/schema/developer_agreement.sql
D backend/schema/sqlite/OAuth.sql
D backend/schema/sqlite/developer_agreement.sql
6 files changed, 19 insertions(+), 89 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OAuth 
refs/changes/92/255492/1

diff --git a/backend/schema/MWOAuthUpdater.hooks.php 
b/backend/schema/MWOAuthUpdater.hooks.php
index 611b508..0df3c57 100644
--- a/backend/schema/MWOAuthUpdater.hooks.php
+++ b/backend/schema/MWOAuthUpdater.hooks.php
@@ -14,20 +14,19 @@
                if ( !MWOAuthUtils::isCentralWiki() ) {
                        return true; // no tables to add
                }
-               $base = dirname( __FILE__ );
 
                $dbType = $updater->getDB()->getType();
 
                if ( $dbType == 'mysql' or $dbType == 'sqlite' ) {
-                       $base = "$base/$dbType";
 
-                       $updater->addExtensionTable( 
'oauth_registered_consumer', "$base/OAuth.sql" );
+                       $updater->addExtensionTable( 
'oauth_registered_consumer',
+                               self::getPath( 'OAuth.sql', $dbType ) );
 
                        $updater->addExtensionUpdate( array(
                                'addField',
                                'oauth_registered_consumer',
                                'oarc_callback_is_prefix',
-                               "$base/callback_is_prefix.sql",
+                               self::getPath( 'callback_is_prefix.sql', 
$dbType ),
                                true
                        ) );
 
@@ -35,15 +34,28 @@
                                'addField',
                                'oauth_registered_consumer',
                                'oarc_developer_agreement',
-                               "$base/developer_agreement.sql",
+                               self::getPath( 'developer_agreement.sql', 
$dbType ),
                                true
                        ) );
 
                } elseif ( $dbType == 'postgres' ) {
-                       //$base = "$base/postgres";
-
                        // @TODO
                }
                return true;
        }
+
+       /**
+        * @param string $filename Name of the patch file (without path).
+        *    The file should be in the backend/schema/<dbtype>/ directory
+        *    or the backend/schema directory.
+        * @param string $dbType 'mysql' or 'sqlite'
+        * @return string
+        */
+       protected static function getPath( $filename, $dbType ) {
+               $base = dirname( __FILE__ );
+               if ( file_exists( "$base/$dbType/$filename" ) ) {
+                       return "$base/$dbType/$filename";
+               }
+               return "$base/$filename";
+       }
 }
diff --git a/backend/schema/mysql/OAuth.sql b/backend/schema/OAuth.sql
similarity index 100%
rename from backend/schema/mysql/OAuth.sql
rename to backend/schema/OAuth.sql
diff --git a/backend/schema/sqlite/callback_is_prefix.sql 
b/backend/schema/callback_is_prefix.sql
similarity index 100%
rename from backend/schema/sqlite/callback_is_prefix.sql
rename to backend/schema/callback_is_prefix.sql
diff --git a/backend/schema/mysql/developer_agreement.sql 
b/backend/schema/developer_agreement.sql
similarity index 100%
rename from backend/schema/mysql/developer_agreement.sql
rename to backend/schema/developer_agreement.sql
diff --git a/backend/schema/sqlite/OAuth.sql b/backend/schema/sqlite/OAuth.sql
deleted file mode 100644
index a043a2e..0000000
--- a/backend/schema/sqlite/OAuth.sql
+++ /dev/null
@@ -1,81 +0,0 @@
--- (c) Aaron Schulz, 2013
-
--- Replace /*_*/ with the proper prefix
-
--- These tables should belong in one central DB per wiki-farm
-
--- Client consumers (proposed as well as and accepted)
-CREATE TABLE IF NOT EXISTS /*_*/oauth_registered_consumer (
-    -- Immutable fields below:
-    -- Consumer ID (1:1 with oarc_consumer_key)
-    oarc_id integer unsigned NOT NULL PRIMARY KEY auto_increment,
-    -- OAuth consumer key and secret (or RSA key)
-    oarc_consumer_key varbinary(32) NOT NULL,
-    -- Name of the application
-    oarc_name varchar(128) binary NOT NULL,
-    -- Key to the user who proposed the application
-    oarc_user_id integer unsigned NOT NULL,
-    -- Version of the application
-    oarc_version varbinary(32) NOT NULL,
-    -- Callback URL
-    oarc_callback_url blob NOT NULL,
-    -- Application description
-    oarc_description blob NOT NULL,
-    -- Contact email address
-    oarc_email varchar(255) binary NOT NULL,
-    -- Confirmation of contact email address
-    oarc_email_authenticated varbinary(14) NULL,
-    -- What wiki this is allowed on (a single wiki or '*' for all)
-    oarc_wiki varbinary(32) NOT NULL,
-    -- Grants needed for client consumers
-    oarc_grants blob NOT NULL,
-    -- Timestamp of consumer proposal
-    oarc_registration varbinary(14) NOT NULL,
-
-    -- Mutable fields below:
-    oarc_secret_key varbinary(32) NULL,
-    oarc_rsa_key blob NULL,
-    -- JSON blob of allowed IP ranges
-    oarc_restrictions blob NOT NULL,
-    -- Stage in registration pipeline:
-    -- (0=proposed, 1=approved, 2=rejected, 3=expired, 4=disabled)
-    oarc_stage tinyint unsigned NOT NULL DEFAULT 0,
-    -- Timestamp of the last stage change
-    oarc_stage_timestamp varbinary(14) NOT NULL,
-    -- Whether this consumer is suppressed (hidden)
-    oarc_deleted tinyint unsigned NOT NULL DEFAULT 0
-) /*$wgDBTableOptions*/;
-
-CREATE UNIQUE INDEX /*i*/oarc_consumer_key
-    ON /*_*/oauth_registered_consumer (oarc_consumer_key);
-CREATE UNIQUE INDEX /*i*/oarc_name_version_user
-    ON /*_*/oauth_registered_consumer (oarc_name,oarc_user_id,oarc_version);
-CREATE INDEX /*i*/oarc_user_id ON /*_*/oauth_registered_consumer 
(oarc_user_id);
-CREATE INDEX /*i*/oarc_stage_timestamp
-    ON /*_*/oauth_registered_consumer (oarc_stage,oarc_stage_timestamp);
-
--- Grant approvals by users for consumers
-CREATE TABLE IF NOT EXISTS /*_*/oauth_accepted_consumer (
-    oaac_id integer unsigned NOT NULL PRIMARY KEY auto_increment,
-    -- The name of a wiki or "*"
-    oaac_wiki varchar(255) binary NOT NULL,
-    -- Key to the user who approved the consumer (on the central wiki)
-    oaac_user_id integer unsigned NOT NULL,
-    -- Key to the consumer
-    oaac_consumer_id integer unsigned NOT NULL,
-    -- Tokens for the consumer to act on behave of the user
-    oaac_access_token varbinary(32) NOT NULL,
-    oaac_access_secret varbinary(32) NOT NULL,
-    -- JSON blob of actually accepted grants
-    oaac_grants blob NOT NULL,
-    -- Timestamp of grant approval by the user
-    oaac_accepted varbinary(14) NOT NULL
-) /*$wgDBTableOptions*/;
-
-CREATE UNIQUE INDEX /*i*/oaac_access_token
-    ON /*_*/oauth_accepted_consumer (oaac_access_token);
-CREATE UNIQUE INDEX /*i*/oaac_user_consumer_wiki
-    ON /*_*/oauth_accepted_consumer (oaac_user_id,oaac_consumer_id,oaac_wiki);
-CREATE INDEX /*i*/oaac_consumer_user
-    ON /*_*/oauth_accepted_consumer (oaac_consumer_id,oaac_user_id);
-CREATE INDEX /*i*/oaac_user_id ON /*_*/oauth_accepted_consumer 
(oaac_user_id,oaac_id);
diff --git a/backend/schema/sqlite/developer_agreement.sql 
b/backend/schema/sqlite/developer_agreement.sql
deleted file mode 100644
index 000bede..0000000
--- a/backend/schema/sqlite/developer_agreement.sql
+++ /dev/null
@@ -1 +0,0 @@
-ALTER TABLE /*_*/oauth_registered_consumer ADD COLUMN 
`oarc_developer_agreement` tinyint NOT NULL DEFAULT 0;

-- 
To view, visit https://gerrit.wikimedia.org/r/255492
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6853be84d212bf4738a1def3365f2676a3d36676
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OAuth
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to