diff --git a/composer.json b/composer.json index c92574995..98ba7833b 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/extension.json b/extension.json index 1e0ff4a87..1822f322b 100644 --- a/extension.json +++ b/extension.json @@ -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" }, diff --git a/includes/Hooks/InstallerHooks.php b/includes/Hooks/InstallerHooks.php new file mode 100644 index 000000000..71eb55456 --- /dev/null +++ b/includes/Hooks/InstallerHooks.php @@ -0,0 +1,34 @@ +getDB()->getType(); + + $updater->addExtensionTable( + 'discussiontools_subscription', + "$base/../sql/$type/discussiontools_subscription.sql" + ); + } +} diff --git a/sql/discussiontools_subscription.json b/sql/discussiontools_subscription.json new file mode 100644 index 000000000..ae07dd9ad --- /dev/null +++ b/sql/discussiontools_subscription.json @@ -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" + ] + } +] diff --git a/sql/mysql/discussiontools_subscription.sql b/sql/mysql/discussiontools_subscription.sql new file mode 100644 index 000000000..5a36b8863 --- /dev/null +++ b/sql/mysql/discussiontools_subscription.sql @@ -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*/; diff --git a/sql/postgres/discussiontools_subscription.sql b/sql/postgres/discussiontools_subscription.sql new file mode 100644 index 000000000..112f7dde5 --- /dev/null +++ b/sql/postgres/discussiontools_subscription.sql @@ -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); diff --git a/sql/sqlite/discussiontools_subscription.sql b/sql/sqlite/discussiontools_subscription.sql new file mode 100644 index 000000000..58b0cd52f --- /dev/null +++ b/sql/sqlite/discussiontools_subscription.sql @@ -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);