Yurik has uploaded a new change for review. https://gerrit.wikimedia.org/r/195192
Change subject: Database schema for gather lists ...................................................................... Database schema for gather lists Partially based on Iec9ca32d430f634d20b02c35f08e997d12843a36 (by Rob Moen <rmoen at wikimedia org>) Adds two tables: * gather_list stores list ID (autoinc), user ID, and a blob for any other, yet undecided, options * gather_list_item stores list ID (FK), namespace+title, and item order This design should allow us to quickly move forward with various innovations without being restricted by the frequent schema changes. In case you want to drop the local tables (careful in production!!!), use mysql wiki < extensions/Gather/schema/uninstall.sql Change-Id: I1f28cc4f8f48e683709db86005534ea27577351d --- M Gather.php M extension.json A schema/Updater.hooks.php A schema/gather_list.sql A schema/gather_list_item.sql A schema/uninstall.sql 6 files changed, 78 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Gather refs/changes/92/195192/1 diff --git a/Gather.php b/Gather.php index 1b07e07..4c1c79c 100644 --- a/Gather.php +++ b/Gather.php @@ -32,6 +32,7 @@ // autoload extension classes $autoloadClasses = array( 'Gather\Hooks' => 'Gather.hooks', + 'Gather\UpdaterHooks' => 'schema/Updater.hooks', 'Gather\models\CollectionItem' => 'models/CollectionItem', 'Gather\models\CollectionBase' => 'models/CollectionBase', @@ -85,6 +86,9 @@ $wgHooks['MakeGlobalVariablesScript'][] = 'Gather\Hooks::onMakeGlobalVariablesScript'; $wgHooks['ResourceLoaderTestModules'][] = 'Gather\Hooks::onResourceLoaderTestModules'; +// Maintenance Hooks +$wgHooks['LoadExtensionSchemaUpdates'][] = 'Gather\UpdaterHooks::onLoadExtensionSchemaUpdates'; + // Api $wgAPIModules['gather'] = 'Gather\api\CollectionsListApi'; $wgAPIModules['editcollection'] = 'Gather\api\ApiEditCollection'; diff --git a/extension.json b/extension.json index 228bc49..0146f71 100644 --- a/extension.json +++ b/extension.json @@ -28,6 +28,7 @@ }, "AutoloadClasses": { "Gather\\Hooks": "includes/Gather.hooks.php", + "Gather\\UpdaterHooks": "schema/Updater.hooks.php", "Gather\\models\\CollectionItem": "includes/models/CollectionItem.php", "Gather\\models\\CollectionBase": "includes/models/CollectionBase.php", "Gather\\models\\CollectionInfo": "includes/models/CollectionInfo.php", @@ -211,6 +212,9 @@ ], "ResourceLoaderTestModules": [ "Gather\\Hooks::onResourceLoaderTestModules" + ], + "LoadExtensionSchemaUpdates": [ + "Gather\\UpdaterHooks::onLoadExtensionSchemaUpdates" ] } } diff --git a/schema/Updater.hooks.php b/schema/Updater.hooks.php new file mode 100644 index 0000000..a56d8f4 --- /dev/null +++ b/schema/Updater.hooks.php @@ -0,0 +1,18 @@ +<?php + +namespace Gather; +use DatabaseUpdater; + +/** + * Class containing updater functions for a Gather environment + */ +class UpdaterHooks { + public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $du ) { + $base = dirname( __FILE__ ); + + $du->addExtensionTable( 'gather_list', "$base/gather_list.sql", true ); + $du->addExtensionTable( 'gather_list_item', "$base/gather_list_item.sql", true ); + + return true; + } +} diff --git a/schema/gather_list.sql b/schema/gather_list.sql new file mode 100644 index 0000000..cb96fe4 --- /dev/null +++ b/schema/gather_list.sql @@ -0,0 +1,20 @@ +-- (c) Yuri Astrakhan <yuri at wikimedia org>, 2015, GPL 2 +-- Partially based on Iec9ca32d430f634d20b02c35f08e997d12843a36 by Rob Moen <rmoen at wikimedia org> +-- Replace /*_*/ with the proper prefix +-- Replace /*$wgDBTableOptions*/ with the correct options + + +CREATE TABLE /*_*/gather_list ( + -- Primary key + gl_id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + -- Key to user.user_id + gl_user_id INT UNSIGNED NOT NULL, + -- All other values are stored here to allow for rapid design changes. + -- At this point we do not foresee any value in using indexes + -- thus blob is a perfect storage medium. Stored as JSON blob. + gl_manifest blob NOT NULL +) /*$wgDBTableOptions*/; + + +CREATE UNIQUE INDEX /*i*/gl_id ON /*_*/gather_list (gl_id); +CREATE UNIQUE INDEX /*i*/gl_user_id ON /*_*/gather_list (gl_user_id, gl_id); diff --git a/schema/gather_list_item.sql b/schema/gather_list_item.sql new file mode 100644 index 0000000..c96f1e5 --- /dev/null +++ b/schema/gather_list_item.sql @@ -0,0 +1,25 @@ +-- (c) Yuri Astrakhan <yuri at wikimedia org>, 2015, GPL 2 +-- Partially based on Iec9ca32d430f634d20b02c35f08e997d12843a36 by Rob Moen <rmoen at wikimedia org> +-- Replace /*_*/ with the proper prefix +-- Replace /*$wgDBTableOptions*/ with the correct options + +CREATE TABLE /*_*/gather_list_item ( + -- Id of the gather_list + gli_gl_id INT UNSIGNED NOT NULL, + + -- Key to page_namespace/page_title + -- Note that users may watch pages which do not exist yet, + -- or existed in the past but have been deleted. + gli_namespace INT NOT NULL, + gli_title VARCHAR(255) BINARY NOT NULL, + + -- Sort order uses real to simplify item insertion + -- without modifying other items + gli_order REAL NOT NULL DEFAULT 0 +) /*$wgDBTableOptions*/; + + +-- Define clustered index (must be first unique) -- most common operations will enumerate in order +CREATE UNIQUE INDEX /*i*/gli_id_order_ns_title ON /*_*/gather_list_item (gli_gl_id, gli_order, gli_namespace, gli_title); +-- Prevent multiple titles per gl_id. Also used for quick dup checks when adding/removing +CREATE UNIQUE INDEX /*i*/gli_id_ns_title ON /*_*/gather_list_item (gli_gl_id, gli_namespace, gli_title); diff --git a/schema/uninstall.sql b/schema/uninstall.sql new file mode 100644 index 0000000..1cb85e5 --- /dev/null +++ b/schema/uninstall.sql @@ -0,0 +1,7 @@ +-- (c) Yuri Astrakhan <yuri at wikimedia org>, 2015, GPL 2 +-- Replace /*_*/ with the proper prefix +-- Replace /*$wgDBTableOptions*/ with the correct options + + +DROP TABLE IF EXISTS /*_*/gather_list_item; +DROP TABLE IF EXISTS /*_*/gather_list; -- To view, visit https://gerrit.wikimedia.org/r/195192 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1f28cc4f8f48e683709db86005534ea27577351d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Gather Gerrit-Branch: master Gerrit-Owner: Yurik <yu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits