Create table for topic subscriptions

Bug: T264885
Change-Id: I92d0362eac80ae1ae70839e26e2c084003862a5f
This commit is contained in:
David Lynch 2021-01-30 13:35:44 -06:00 committed by Bartosz Dziewoński
parent f702e094a8
commit 5b8646f73f
7 changed files with 209 additions and 0 deletions

View file

@ -16,6 +16,11 @@
"minus-x fix .",
"phpcbf"
],
"dbschema": [
"php ../../maintenance/generateSchemaSql.php --json sql/discussiontools_subscription.json --sql sql/mysql/discussiontools_subscription.sql --type mysql",
"php ../../maintenance/generateSchemaSql.php --json sql/discussiontools_subscription.json --sql sql/postgres/discussiontools_subscription.sql --type postgres",
"php ../../maintenance/generateSchemaSql.php --json sql/discussiontools_subscription.json --sql sql/sqlite/discussiontools_subscription.sql --type sqlite"
],
"phan": "phan -d . --long-progress-bar"
}
}

View file

@ -350,6 +350,7 @@
"discussiontoolsedit": "MediaWiki\\Extension\\DiscussionTools\\ApiDiscussionToolsEdit"
},
"Hooks": {
"LoadExtensionSchemaUpdates": "installer",
"ArticleParserOptions": "parser",
"ParserAfterTidy": "parser",
"ParserOptionsRegister": "parser",
@ -363,6 +364,9 @@
"RecentChange_save": "tags"
},
"HookHandlers": {
"installer": {
"class": "MediaWiki\\Extension\\DiscussionTools\\Hooks\\InstallerHooks"
},
"page": {
"class": "MediaWiki\\Extension\\DiscussionTools\\Hooks\\PageHooks"
},

View file

@ -0,0 +1,34 @@
<?php
/**
* DiscussionTools installer hooks
*
* @file
* @ingroup Extensions
* @license MIT
*/
namespace MediaWiki\Extension\DiscussionTools\Hooks;
use DatabaseUpdater;
use MediaWiki\Installer\Hook\LoadExtensionSchemaUpdatesHook;
class InstallerHooks implements
LoadExtensionSchemaUpdatesHook
{
/**
* Implements the LoadExtensionSchemaUpdates hook, to create database tables when
* update.php runs
*
* @param DatabaseUpdater $updater
* @return bool|void
*/
public function onLoadExtensionSchemaUpdates( $updater ) {
$base = dirname( __DIR__ );
$type = $updater->getDB()->getType();
$updater->addExtensionTable(
'discussiontools_subscription',
"$base/../sql/$type/discussiontools_subscription.sql"
);
}
}

View file

@ -0,0 +1,109 @@
[
{
"name": "discussiontools_subscription",
"columns": [
{
"name": "sub_id",
"type": "integer",
"options": {
"autoincrement": true,
"unsigned": true,
"notnull": true
}
},
{
"name": "sub_item",
"comment": "Internal name used to identify this item across all pages and revisions where it might appear, see CommentParser::computeName()",
"type": "string",
"options": {
"notnull": true,
"length": 255
}
},
{
"name": "sub_namespace",
"comment": "Namespace of the page where this item appeared when the user subscribed to it",
"type": "integer",
"options": {
"notnull": true,
"default": 0
}
},
{
"name": "sub_title",
"comment": "Title of the page where this item appeared when the user subscribed to it",
"type": "string",
"options": {
"notnull": true,
"length": 255
}
},
{
"name": "sub_section",
"comment": "Section of the page where this item appeared when the user subscribed to it",
"type": "string",
"options": {
"notnull": true,
"length": 255
}
},
{
"name": "sub_state",
"comment": "0: unsubscribed; 1: subscribed",
"type": "integer",
"options": {
"notnull": true,
"default": 1,
"length": 1
}
},
{
"name": "sub_user",
"comment": "User who is subscribed, key to user.user_id",
"type": "integer",
"options": {
"unsigned": true,
"notnull": true
}
},
{
"name": "sub_created",
"comment": "Time when this subscription was created",
"type": "mwtimestamp",
"options": {
"notnull": true
}
},
{
"name": "sub_notified",
"comment": "Time when a notification about the item was last sent",
"type": "mwtimestamp",
"options": {
"notnull": false
}
}
],
"indexes": [
{
"name": "discussiontools_subscription_itemuser",
"comment": "Index for finding all users subscribed to an item, or a specific subscription",
"columns": [
"sub_item",
"sub_user"
],
"unique": true
},
{
"name": "discussiontools_subscription_user",
"comment": "Index for finding all subscriptions of the user",
"columns": [
"sub_user"
],
"unique": false
}
],
"pk": [
"sub_id"
]
}
]

View file

@ -0,0 +1,18 @@
-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: sql/discussiontools_subscription.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE /*_*/discussiontools_subscription (
sub_id INT UNSIGNED AUTO_INCREMENT NOT NULL,
sub_item VARCHAR(255) NOT NULL,
sub_namespace INT DEFAULT 0 NOT NULL,
sub_title VARCHAR(255) NOT NULL,
sub_section VARCHAR(255) NOT NULL,
sub_state INT DEFAULT 1 NOT NULL,
sub_user INT UNSIGNED NOT NULL,
sub_created BINARY(14) NOT NULL,
sub_notified BINARY(14) DEFAULT NULL,
UNIQUE INDEX discussiontools_subscription_itemuser (sub_item, sub_user),
INDEX discussiontools_subscription_user (sub_user),
PRIMARY KEY(sub_id)
) /*$wgDBTableOptions*/;

View file

@ -0,0 +1,20 @@
-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: sql/discussiontools_subscription.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE discussiontools_subscription (
sub_id SERIAL NOT NULL,
sub_item VARCHAR(255) NOT NULL,
sub_namespace INT DEFAULT 0 NOT NULL,
sub_title VARCHAR(255) NOT NULL,
sub_section VARCHAR(255) NOT NULL,
sub_state INT DEFAULT 1 NOT NULL,
sub_user INT NOT NULL,
sub_created TIMESTAMPTZ NOT NULL,
sub_notified TIMESTAMPTZ DEFAULT NULL,
PRIMARY KEY(sub_id)
);
CREATE UNIQUE INDEX discussiontools_subscription_itemuser ON discussiontools_subscription (sub_item, sub_user);
CREATE INDEX discussiontools_subscription_user ON discussiontools_subscription (sub_user);

View file

@ -0,0 +1,19 @@
-- This file is automatically generated using maintenance/generateSchemaSql.php.
-- Source: sql/discussiontools_subscription.json
-- Do not modify this file directly.
-- See https://www.mediawiki.org/wiki/Manual:Schema_changes
CREATE TABLE /*_*/discussiontools_subscription (
sub_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
sub_item VARCHAR(255) NOT NULL,
sub_namespace INTEGER DEFAULT 0 NOT NULL,
sub_title VARCHAR(255) NOT NULL,
sub_section VARCHAR(255) NOT NULL,
sub_state INTEGER DEFAULT 1 NOT NULL,
sub_user INTEGER UNSIGNED NOT NULL,
sub_created BLOB NOT NULL,
sub_notified BLOB DEFAULT NULL
);
CREATE UNIQUE INDEX discussiontools_subscription_itemuser ON /*_*/discussiontools_subscription (sub_item, sub_user);
CREATE INDEX discussiontools_subscription_user ON /*_*/discussiontools_subscription (sub_user);