Bug 29426

Summary: borrower_debarments.created is "ON UPDATE current_timestamp()"
Product: Koha Reporter: Magnus Enger <magnus>
Component: DatabaseAssignee: Bugs List <koha-bugs>
Status: NEW --- QA Contact: Testopia <testopia>
Severity: normal    
Priority: P5 - low CC: jonathan.druart
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:

Description Magnus Enger 2021-11-05 14:40:56 UTC
https://git.koha-community.org/Koha-community/Koha/src/branch/master/installer/data/mysql/kohastructure.sql

Currently, the table borrower_debarments is created like this:

CREATE TABLE `borrower_debarments` (
  `borrower_debarment_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'unique key for the restriction',
  `borrowernumber` int(11) NOT NULL COMMENT 'foreign key for borrowers.borrowernumber for patron who is restricted',
  `expiration` date DEFAULT NULL COMMENT 'expiration date of the restriction',
  `type` enum('SUSPENSION','OVERDUES','MANUAL','DISCHARGE') COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'MANUAL' COMMENT 'type of restriction',
  `comment` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT 'comments about the restriction',
  `manager_id` int(11) DEFAULT NULL COMMENT 'foreign key for borrowers.borrowernumber for the librarian managing the restriction',
  `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'date the restriction was added',
  `updated` timestamp NULL DEFAULT NULL COMMENT 'date the restriction was updated',
  PRIMARY KEY (`borrower_debarment_id`),
  KEY `borrowernumber` (`borrowernumber`),
  CONSTRAINT `borrower_debarments_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

Looks like there has been a mixup between the created and the updated columns? We have this:

  `created` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'date the restriction was added',
  `updated` timestamp NULL DEFAULT NULL COMMENT 'date the restriction was updated',

Would it not make more sense to have this:

  `created` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'date the restriction was added',
  `updated` timestamp NULL DEFAULT NULL ON UPDATE current_timestamp() COMMENT 'date the restriction was updated',

...so that the updated column is actually updated when the row is updated?
Comment 1 Jonathan Druart 2021-11-16 13:03:03 UTC
Yes it does, can you provide a patch please?