From 3387c848d0f278caceb0148391e61f6366a0ab0a Mon Sep 17 00:00:00 2001 From: Reedy Date: Sat, 22 Aug 2020 21:48:51 +0100 Subject: [PATCH] Convert Linter to abstract schema Bug: T259374 Change-Id: Ida866d45bc3daca6ed763df2b8c38d2b27c809aa --- includes/Hooks.php | 16 +++++++-- sql/linter.sql | 18 ---------- sql/postgres/tables-generated.sql | 20 +++++++++++ sql/sqlite/tables-generated.sql | 19 +++++++++++ sql/tables-generated.sql | 18 ++++++++++ sql/tables.json | 57 +++++++++++++++++++++++++++++++ 6 files changed, 128 insertions(+), 20 deletions(-) delete mode 100644 sql/linter.sql create mode 100644 sql/postgres/tables-generated.sql create mode 100644 sql/sqlite/tables-generated.sql create mode 100644 sql/tables-generated.sql create mode 100644 sql/tables.json diff --git a/includes/Hooks.php b/includes/Hooks.php index b27135f6..0e9d52b5 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -36,8 +36,20 @@ class Hooks { * @param DatabaseUpdater $updater */ public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { - $dir = dirname( __DIR__ ) . '/sql'; - $updater->addExtensionTable( 'linter', "$dir/linter.sql" ); + $dbType = $updater->getDB()->getType(); + if ( $dbType === 'mysql' ) { + $updater->addExtensionTable( 'linter', + dirname( __DIR__ ) . '/sql/tables-generated.sql' + ); + } elseif ( $dbType === 'sqlite' ) { + $updater->addExtensionTable( 'linter', + dirname( __DIR__ ) . '/sql/sqlite/tables-generated.sql' + ); + } elseif ( $dbType === 'postgres' ) { + $updater->addExtensionTable( 'linter', + dirname( __DIR__ ) . '/sql/postgres/tables-generated.sql' + ); + } } /** diff --git a/sql/linter.sql b/sql/linter.sql deleted file mode 100644 index 84ba5e28..00000000 --- a/sql/linter.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE TABLE /*_*/linter ( - -- primary key - linter_id int UNSIGNED PRIMARY KEY not null AUTO_INCREMENT, - -- page id - linter_page int UNSIGNED not null, - -- error category (see CategoryManager::$categoryIds) - linter_cat int UNSIGNED not null, - -- start and end positions of where the error is located - linter_start int UNSIGNED not null, - linter_end int UNSIGNED not null, - -- extra parameters about the error, JSON encoded - linter_params blob NOT NULL -) /*$wgDBTableOptions*/; - --- Query by page -CREATE INDEX /*i*/linter_page ON /*_*/linter (linter_page); --- Unique index for lint errors, also covers linter_cat for query by category -CREATE UNIQUE INDEX /*i*/linter_cat_page_position ON /*_*/linter (linter_cat, linter_page, linter_start, linter_end); diff --git a/sql/postgres/tables-generated.sql b/sql/postgres/tables-generated.sql new file mode 100644 index 00000000..6165bfc2 --- /dev/null +++ b/sql/postgres/tables-generated.sql @@ -0,0 +1,20 @@ +-- This file is automatically generated using maintenance/generateSchemaSql.php. +-- Source: ./tables.json +-- Do not modify this file directly. +-- See https://www.mediawiki.org/wiki/Manual:Schema_changes +CREATE TABLE linter ( + linter_id SERIAL NOT NULL, + linter_page INT NOT NULL, + linter_cat INT NOT NULL, + linter_start INT NOT NULL, + linter_end INT NOT NULL, + linter_params TEXT DEFAULT NULL, + PRIMARY KEY(linter_id) +); + +CREATE INDEX linter_page ON linter (linter_page); + +CREATE UNIQUE INDEX linter_cat_page_position ON linter ( + linter_cat, linter_page, linter_start, + linter_end +); diff --git a/sql/sqlite/tables-generated.sql b/sql/sqlite/tables-generated.sql new file mode 100644 index 00000000..7d6965d0 --- /dev/null +++ b/sql/sqlite/tables-generated.sql @@ -0,0 +1,19 @@ +-- This file is automatically generated using maintenance/generateSchemaSql.php. +-- Source: ./tables.json +-- Do not modify this file directly. +-- See https://www.mediawiki.org/wiki/Manual:Schema_changes +CREATE TABLE /*_*/linter ( + linter_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, + linter_page INTEGER UNSIGNED NOT NULL, + linter_cat INTEGER UNSIGNED NOT NULL, + linter_start INTEGER UNSIGNED NOT NULL, + linter_end INTEGER UNSIGNED NOT NULL, + linter_params BLOB DEFAULT NULL +); + +CREATE INDEX linter_page ON /*_*/linter (linter_page); + +CREATE UNIQUE INDEX linter_cat_page_position ON /*_*/linter ( + linter_cat, linter_page, linter_start, + linter_end +); diff --git a/sql/tables-generated.sql b/sql/tables-generated.sql new file mode 100644 index 00000000..17adaa39 --- /dev/null +++ b/sql/tables-generated.sql @@ -0,0 +1,18 @@ +-- This file is automatically generated using maintenance/generateSchemaSql.php. +-- Source: ./tables.json +-- Do not modify this file directly. +-- See https://www.mediawiki.org/wiki/Manual:Schema_changes +CREATE TABLE /*_*/linter ( + linter_id INT UNSIGNED AUTO_INCREMENT NOT NULL, + linter_page INT UNSIGNED NOT NULL, + linter_cat INT UNSIGNED NOT NULL, + linter_start INT UNSIGNED NOT NULL, + linter_end INT UNSIGNED NOT NULL, + linter_params BLOB DEFAULT NULL, + INDEX linter_page (linter_page), + UNIQUE INDEX linter_cat_page_position ( + linter_cat, linter_page, linter_start, + linter_end + ), + PRIMARY KEY(linter_id) +) /*$wgDBTableOptions*/; diff --git a/sql/tables.json b/sql/tables.json new file mode 100644 index 00000000..ef1e44eb --- /dev/null +++ b/sql/tables.json @@ -0,0 +1,57 @@ +[ + { + "name": "linter", + "columns": [ + { + "name": "linter_id", + "type": "integer", + "options": { "notnull": true, "unsigned": true, "autoincrement": true } + }, + { + "name": "linter_page", + "comment": "page id", + "type": "integer", + "options": { "notnull": true, "unsigned": true } + }, + { + "name": "linter_cat", + "comment": "error category (see CategoryManager::$categoryIds)", + "type": "integer", + "options": { "notnull": true, "unsigned": true } + }, + { + "name": "linter_start", + "comment": "end positions of where the error is located", + "type": "integer", + "options": { "notnull": true, "unsigned": true } + }, + { + "name": "linter_end", + "comment": "end positions of where the error is located", + "type": "integer", + "options": { "notnull": true, "unsigned": true } + }, + { + "name": "linter_params", + "comment": "extra parameters about the error, JSON encoded", + "type": "blob", + "options": { "length": 65530, "notnull": false } + } + ], + "indexes": [ + { + "name": "linter_page", + "comment": "Query by page", + "columns": [ "linter_page" ], + "unique": false + }, + { + "name": "linter_cat_page_position", + "comment": "Unique index for lint errors, also covers linter_cat for query by category", + "columns": [ "linter_cat", "linter_page", "linter_start", "linter_end" ], + "unique": true + } + ], + "pk": [ "linter_id" ] + } +]