From bb40f4f2329fe129e8d65dca84c21f931285a084 Mon Sep 17 00:00:00 2001 From: Reedy Date: Fri, 26 Apr 2024 18:11:25 +0100 Subject: [PATCH] Convert to abstract schema Bug: T361920 Change-Id: I28f450a4f5c4e1784b4e7e8c8e1fa694bfac4d14 --- includes/GlobalUserrightsHooks.php | 16 ++++++++++++++-- sql/global_user_groups.sql | 16 ---------------- sql/mysql/tables-generated.sql | 12 ++++++++++++ sql/postgres/tables-generated.sql | 14 ++++++++++++++ sql/sqlite/tables-generated.sql | 14 ++++++++++++++ sql/tables.json | 30 ++++++++++++++++++++++++++++++ 6 files changed, 84 insertions(+), 18 deletions(-) delete mode 100644 sql/global_user_groups.sql create mode 100644 sql/mysql/tables-generated.sql create mode 100644 sql/postgres/tables-generated.sql create mode 100644 sql/sqlite/tables-generated.sql create mode 100644 sql/tables.json diff --git a/includes/GlobalUserrightsHooks.php b/includes/GlobalUserrightsHooks.php index 94879e1..a25401a 100644 --- a/includes/GlobalUserrightsHooks.php +++ b/includes/GlobalUserrightsHooks.php @@ -165,9 +165,21 @@ class GlobalUserrightsHooks { */ public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { $dir = __DIR__; - $updater->addExtensionTable( 'global_user_groups', $dir . '/../sql/global_user_groups.sql' ); - $dir .= '/../db_patches'; + $dbType = $updater->getDB()->getType(); + $dir = dirname( __DIR__ ) . '/sql/'; + + $updater->addExtensionTable( + 'global_user_groups', + "$dir/$dbType/tables-generated.sql" + ); + + $dir = dirname( __DIR__ ) . '/db_patches'; + + if ( $dbType === 'postgres' ) { + // Currently no schema changes with postgres, bail out + return; + } // Update the table with the new definitions // This ensures backwards compatibility diff --git a/sql/global_user_groups.sql b/sql/global_user_groups.sql deleted file mode 100644 index a8c9fa4..0000000 --- a/sql/global_user_groups.sql +++ /dev/null @@ -1,16 +0,0 @@ --- Additional table for the GlobalUserrights extension --- To be added to $wgSharedDB - -CREATE TABLE /*_*/global_user_groups ( - -- Key to user_id - gug_user int unsigned NOT NULL default 0, - -- Group name - gug_group varbinary(255) NOT NULL default '', - -- Expiry date - gug_expiry varbinary(14) NULL default NULL, - - PRIMARY KEY (gug_user, gug_group) -) /*$wgDBTableOptions*/; - -CREATE INDEX /*i*/gug_group ON /*_*/global_user_groups (gug_group); -CREATE INDEX /*i*/gug_expiry ON /*_*/global_user_groups (gug_expiry); \ No newline at end of file diff --git a/sql/mysql/tables-generated.sql b/sql/mysql/tables-generated.sql new file mode 100644 index 0000000..666b44c --- /dev/null +++ b/sql/mysql/tables-generated.sql @@ -0,0 +1,12 @@ +-- This file is automatically generated using maintenance/generateSchemaSql.php. +-- Source: /var/www/wiki/mediawiki/extensions/GlobalUserrights/sql/tables.json +-- Do not modify this file directly. +-- See https://www.mediawiki.org/wiki/Manual:Schema_changes +CREATE TABLE /*_*/global_user_groups ( + gug_user BIGINT UNSIGNED NOT NULL, + gug_group VARBINARY(255) DEFAULT '' NOT NULL, + gug_expiry BINARY(14) NOT NULL, + INDEX gug_group (gug_group), + INDEX gug_expiry (gug_expiry), + PRIMARY KEY(gug_user, gug_group) +) /*$wgDBTableOptions*/; diff --git a/sql/postgres/tables-generated.sql b/sql/postgres/tables-generated.sql new file mode 100644 index 0000000..1327c07 --- /dev/null +++ b/sql/postgres/tables-generated.sql @@ -0,0 +1,14 @@ +-- This file is automatically generated using maintenance/generateSchemaSql.php. +-- Source: /var/www/wiki/mediawiki/extensions/GlobalUserrights/sql/tables.json +-- Do not modify this file directly. +-- See https://www.mediawiki.org/wiki/Manual:Schema_changes +CREATE TABLE global_user_groups ( + gug_user BIGINT NOT NULL, + gug_group TEXT DEFAULT '' NOT NULL, + gug_expiry TIMESTAMPTZ NOT NULL, + PRIMARY KEY(gug_user, gug_group) +); + +CREATE INDEX gug_group ON global_user_groups (gug_group); + +CREATE INDEX gug_expiry ON global_user_groups (gug_expiry); diff --git a/sql/sqlite/tables-generated.sql b/sql/sqlite/tables-generated.sql new file mode 100644 index 0000000..5bb9aa4 --- /dev/null +++ b/sql/sqlite/tables-generated.sql @@ -0,0 +1,14 @@ +-- This file is automatically generated using maintenance/generateSchemaSql.php. +-- Source: /var/www/wiki/mediawiki/extensions/GlobalUserrights/sql/tables.json +-- Do not modify this file directly. +-- See https://www.mediawiki.org/wiki/Manual:Schema_changes +CREATE TABLE /*_*/global_user_groups ( + gug_user BIGINT UNSIGNED NOT NULL, + gug_group BLOB DEFAULT '' NOT NULL, + gug_expiry BLOB NOT NULL, + PRIMARY KEY(gug_user, gug_group) +); + +CREATE INDEX gug_group ON /*_*/global_user_groups (gug_group); + +CREATE INDEX gug_expiry ON /*_*/global_user_groups (gug_expiry); diff --git a/sql/tables.json b/sql/tables.json new file mode 100644 index 0000000..dce219a --- /dev/null +++ b/sql/tables.json @@ -0,0 +1,30 @@ +[ + { + "name": "global_user_groups", + "columns": [ + { + "name": "gug_user", + "comment": "Key to user_id", + "type": "bigint", + "options": { "unsigned": true, "notnull": true, "autoincrement": false } + }, + { + "name": "gug_group", + "comment": "Group name", + "type": "binary", + "options": { "length": 255, "default": "", "notnull": false } + }, + { + "name": "gug_expiry", + "comment": "Text username or IP address", + "type": "mwtimestamp", + "options": { "notnull": true } + } + ], + "indexes": [ + { "name": "gug_group", "columns": [ "gug_group" ], "unique": false }, + { "name": "gug_expiry", "columns": [ "gug_expiry" ], "unique": false } + ], + "pk": [ "gug_user", "gug_group" ] + } +]