HugoFara / lwt

Learn languages by reading! A language learning app stemmed from Learning with Texts (LWT).
https://hugofara.github.io/lwt/
The Unlicense
164 stars 19 forks source link

Duplicate Entry Fatal Error in SQL Query When Running LWT Program #196

Open voothi opened 3 months ago

voothi commented 3 months ago

Describe the bug

Fatal Error in SQL Query: INSERT INTO _migrations VALUES ('19700101_000001_lwt_original.sql'), ('19700102_000001_lwt_fork.sql'), ('20231224_131202_missing_auto_increment.sql'), ('20240103_120316_2.10.0-fork.sql')

Error Code & Message: [1062] Duplicate entry '19700101_000001_lwt_original.sql' for key 'PRIMARY'

Backtrace:

#0 /var/www/html/lwt/inc/database_connect.php(63): do_mysqli_query('...')
#1 /var/www/html/lwt/inc/database_connect.php(1873): runsql('...', '')
#2 /var/www/html/lwt/inc/database_connect.php(2180): check_update_db(0, '', '...')
#3 /var/www/html/lwt/inc/session_utility.php(19): require_once('...')
#4 /var/www/html/lwt/do_text.php(20): require_once('...')

To Reproduce Steps to reproduce the behavior:

  1. I installed LWT from docker on Debian 12 (VM Hyper-V). Everything is in default settings.
  2. http://vm1:8010/lwt/backup_restore.php -> Empty LWT Database
  3. Add German Language.
  4. Add Text.
  5. In READ ▶ So würde ich programmieren lernen 2024. -> Translations on/off.
  6. I see db error.

Expected behavior

Screenshots

image

Server (please complete) You can copy/paste data from http://[.. your LWT installation]/server_data.php. Server Data Server Data Value LWT version v002010000 Web Server Apache/2.4.56 (Debian) Server Software Apache/2.4.56 Server Location vm1:8010 PHP Version 8.1.27 Database Data Value Database name learning-with-texts Database prefix (surrounded by "") "" Database Size 0.1 MB MySQL Version 10.7.8-MariaDB-1:10.7.8+maria~ubu2004 Client API Data Value REST API Version 0.1.1 REST API Release date 2023-12-29

Desktop (if necessary):

Smartphone (if necessary):

Additional context LWT Backup lwt-backup-exp_version-2024-04-07-08-00-08.sql.gz

HugoFara commented 3 months ago

That's quite an annoying issue, because I thought it fixed before publishing 2.10, yet it nothing critical. I hope reloading the page whenever it happens should be enough.

The cause of this issue is that version 2.10 implements are cleaner database system, yet backward compatible with the previous iterations of LWT, so it's not so cleaned. This issue appears when two scripts are trying to check the database for updates at the same time. One way to fix it definitely is to comment (or delete) the first lines of db/schema/baseline.sql: https://github.com/HugoFara/lwt/blob/13b0d85f37f916c5df0e4fbed9fcfda8e40598a1/db/schema/baseline.sql#L4C1-L16C1

Once I get rid of $tbpref it won't appear anymore, but I think it's better if I publish a hacky fix before that.