AndyRussG has uploaded a new change for review. https://gerrit.wikimedia.org/r/117825
Change subject: WIP Schema change: create tables ...................................................................... WIP Schema change: create tables Change-Id: I6ae2151ad9ec34a2708560705515308baecbaa76 --- M Campaigns.hooks.php M Campaigns.php A sql/CampaignsCampaignTable.sql A sql/CampaignsParticipationTable.sql 4 files changed, 95 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Campaigns refs/changes/25/117825/1 diff --git a/Campaigns.hooks.php b/Campaigns.hooks.php index e9c8d83..90102c3 100644 --- a/Campaigns.hooks.php +++ b/Campaigns.hooks.php @@ -2,12 +2,39 @@ namespace Campaigns; +use \DatabaseUpdater; + /** * Static methods for hooks. */ class Hooks { /** + * Update database schema to add Campaigns tables. + * + * @see https://www.mediawiki.org/wiki/Manual:Hooks/LoadExtensionSchemaUpdates + * + * @param DatabaseUpdater $updater + * @return bool + */ + public static function onLoadExtensionSchemaUpdate( DatabaseUpdater $updater ) { + + $sqlDir = __DIR__ . '/sql'; + + $updater->addExtensionTable( + 'campaigns_campaign', + $sqlDir . '/CampaignsCampaignTable.sql' + ); + + $updater->addExtensionTable( + 'campaigns_participation', + $sqlDir . '/CampaignsParticipationTable.sql' + ); + + return true; + } + + /** * If there's a ?campaign=someName in the query string and the user is not * logged in, send JavaScript with the page to process campaign. * diff --git a/Campaigns.php b/Campaigns.php index bffe0ec..c26527d 100644 --- a/Campaigns.php +++ b/Campaigns.php @@ -37,6 +37,7 @@ $wgHooks['UserCreateForm'][] = 'Campaigns\Hooks::onUserCreateForm'; $wgHooks['AddNewAccount'][] = 'Campaigns\Hooks::onAddNewAccount'; $wgHooks['UserLoginForm'][] = 'Campaigns\Hooks::onUserLoginForm'; +$wgHooks['LoadExtensionSchemaUpdates'][] = 'Campaigns\Hooks::onLoadExtensionSchemaUpdate'; // Modules diff --git a/sql/CampaignsCampaignTable.sql b/sql/CampaignsCampaignTable.sql new file mode 100644 index 0000000..852ab13 --- /dev/null +++ b/sql/CampaignsCampaignTable.sql @@ -0,0 +1,34 @@ +-- Table for information about campaigns +CREATE TABLE IF NOT EXISTS /*_*/campaigns_campaign ( + + -- Auto-increment id + campaign_id int unsigned NOT NULL PRIMARY KEY auto_increment, + + -- Time the campaign was created + campaign_time_created varbinary(14) NOT NULL, + + -- A string to identify the campaign in URLs + campaign_url_id varchar(255) NOT NULL UNIQUE, + + -- Name of the campaign + campaign_name varchar(255) NOT NULL UNIQUE, + + -- ID of a page about the campaign, foreign key on page.page_id + campaign_wikipage_id int unsigned, + + -- Flag to use only legacy features for participations in this campaign + -- (i.e., just log via EventLogging when an account is created with the + -- campaign's URL ID in the URL) + campaign_legacy boolean NOT NULL default false + +) /*$wgDBTableOptions*/; + +-- Indexes +CREATE UNIQUE INDEX /*i*/campaigns_campaign_id ON + /*_*/campaigns_campaign (campaign_id); + +CREATE UNIQUE INDEX /*i*/campaigns_campaign_url_id ON + /*_*/campaigns_campaign (campaign_url_id); + +CREATE UNIQUE INDEX /*i*/campaigns_campaign_name ON + /*_*/campaigns_campaign (campaign_name); diff --git a/sql/CampaignsParticipationTable.sql b/sql/CampaignsParticipationTable.sql new file mode 100644 index 0000000..24434cf --- /dev/null +++ b/sql/CampaignsParticipationTable.sql @@ -0,0 +1,33 @@ +-- Table for participations in a campaign +CREATE TABLE IF NOT EXISTS /*_*/campaigns_participation ( + + -- Auto-increment id + participation_id int unsigned NOT NULL PRIMARY KEY auto_increment, + + -- User ID, foreign key on user.user_id + participation_user_id INT unsigned NOT NULL, + + -- Campaign ID, foreign key on campaigns_campaign.campaign_id + participation_campaign_id INT unsigned NOT NULL, + + -- Time the user joined the campaign + participation_time_joined varbinary(14) NOT NULL, + + -- Time the user left the campaign + participation_time_left varbinary(14), + + -- Flag for campaign organizers + particiption_organizer boolean NOT NULL default false + +) /*$wgDBTableOptions*/; + +-- Indexes +CREATE UNIQUE INDEX /*i*/campaigns_participation_id ON + /*_*/campaigns_participation (participation_id); + +CREATE INDEX /*i*/campaigns_participation_camp_id_org_active ON + /*_*/campaigns_participation (participation_campaign_id, + particiption_organizer, participation_time_left); + +CREATE INDEX /*i*/campaigns_participation_user_id ON + /*_*/campaigns_participation (participation_user_id); \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/117825 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6ae2151ad9ec34a2708560705515308baecbaa76 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Campaigns Gerrit-Branch: master Gerrit-Owner: AndyRussG <andrew.green...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits