Bug 38788 - Fix '0000-00-00' issue on database
Summary: Fix '0000-00-00' issue on database
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Database (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low major
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on: 31143
Blocks:
  Show dependency treegraph
 
Reported: 2024-12-27 07:44 UTC by Aditya Sethi
Modified: 2024-12-27 09:07 UTC (History)
0 users

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aditya Sethi 2024-12-27 07:44:06 UTC
Continuation of the thread from https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=31143#c90

I have mysql version 8.0.40-0ubuntu0.24.04.1 setup in the remote azure machine. The infrastructure is setup such that there are 2 VMs, one acting as Koha application server and another acting as MySQL database server. MySQL server does not have koha installed but the credentials are setup such that application server has access to it. 

I am getting errors while running fix_invalid_dates.pl file. 

DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Incorrect TIMESTAMP value: '0000-00-00' at ./fix_invalid_dates.pl line 65

The line 65 contains this line: 
my $invalid_dates = $rs->search( { $column => '0000-00-00' } )->count;

It is very obvious that the mysql database throws sanity errors when there are errors in database. To attempt fixing it, I added these lines on top:

# Disable strict mode for this session
$schema->storage->dbh_do(
    sub {
        my ($storage, $dbh) = @_;
        $dbh->do("SET SESSION sql_mode = ''"); # Disables all kinds of checks in mysql for the whole script session
    }
);

These seemingly did nothing. After running cli tool, it didn't return any response. Especially when I try searching names of old patrons, it throws error "month out of range" (there is possibility that the "borrowers" table is not properly cleaned using that script)

What worked for me is below command when running mysql as root user:
UPDATE borrowers SET lastseen = NULL WHERE CAST(lastseen AS CHAR) = '0000-00-00 00:00:00'; -- 6000+ rows changed
UPDATE borrowers SET date_renewed = NULL WHERE CAST(date_renewed AS CHAR) = '0000-00-00'; -- 3000+ rows changed
UPDATE categories SET enrolmentperioddate = NULL WHERE CAST(enrolmentperioddate AS CHAR) = '0000-00-00'; -- 4 rows changed

Please suggest me if there are other tables having same issue too so that I can manually fix it using mysql. I manually created and run the fix_invalid_dates.pl file using koha-shell in koha 23.11 (which was originally not backported) but I don't think the script file not working properly is version-related issue at all.
Comment 1 Katrin Fischer 2024-12-27 08:58:13 UTC
What is your MySQL version?
Please also check:
https://wiki.koha-community.org/wiki/System_requirements_and_recommendations
Comment 2 Aditya Sethi 2024-12-27 09:07:48 UTC
I am using mysql 8.0.40-0ubuntu0.24.04.1