From 8d62b63791b25b0c0d1e3dbc4945f9f31ed37769 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 29 Nov 2024 12:08:18 -0300 Subject: [PATCH] Bug 37292: Add an index on oauth_access_tokens.expires This patch adds a needed index to the column. To test: 1. On a fresh KTD, run: $ ktd --shell k$ koha-mysql kohadev > SHOW CREATE TABLE oauth_access_tokens; => FAIL: There's no 'KEY' entry for the `expires` column 2. Apply this patch 3. Run: k$ updatedatabase => SUCCESS: A message tells the index was added 4. Repeat 1 => SUCCESS: The index was actually added to the DB 5. Run: k$ reset_all 6. Repeat 1 => SUCCESS: The index is created at install time too! 7. Run: k$ updatedatabase => SUCCESS: Nothing explodes, no message about index being created 8. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: Matt Blenkinsop --- .../data/mysql/atomicupdate/bug_37292.pl | 20 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_37292.pl diff --git a/installer/data/mysql/atomicupdate/bug_37292.pl b/installer/data/mysql/atomicupdate/bug_37292.pl new file mode 100755 index 00000000000..934c0c6713a --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_37292.pl @@ -0,0 +1,20 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "37292", + description => "'oauth_access_tokens.expires' needs an index", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + if ( !index_exists( 'oauth_access_tokens', 'expires' ) ) { + $dbh->do( + q{ + ALTER TABLE `oauth_access_tokens` ADD INDEX `expires` (`expires`) + } + ); + say_success( $out, "Added new index on 'oauth_access_tokens.expires'" ); + } + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 445d476b704..2c8340508b1 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4971,7 +4971,8 @@ CREATE TABLE `oauth_access_tokens` ( `access_token` varchar(191) NOT NULL COMMENT 'generarated access token', `client_id` varchar(191) NOT NULL COMMENT 'the client id the access token belongs to', `expires` int(11) NOT NULL COMMENT 'expiration time in seconds', - PRIMARY KEY (`access_token`) + PRIMARY KEY (`access_token`), + KEY `expires` (`expires`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- 2.39.3 (Apple Git-146)