HDInnovations / UNIT3D-Community-Edition

Private Torrent Tracker Built With Laravel, Livewire and AlpineJS.
GNU Affero General Public License v3.0
1.94k stars 370 forks source link

[Bug] - Migration error - stdClass::delete undefined #3829

Open costaht opened 3 months ago

costaht commented 3 months ago

UNIT3D Version

8.1.3

PHP & Platform

PHP 8.3.7 Ubuntu 22.04.4 LTS

Laravel verion

Laravel Framework 11.5.0

Have you done this?

Expectation

I'm trying to migrate a database from v6.3.0 to the latest Unit3d version

Description

Getting migration errors

https://paste.centos.org/view/d1c12b05

Stack trace & logs

No response

Upvote & Fund

Fund with Polar

Roardom commented 2 months ago

Do you still have the logs? Can you paste them directly into the issue? Your link returns a 404 now.

costaht commented 2 months ago

I don't, but since I'm in the process of updating my tracker I can try to reproduce it for you. Back then I copied the changes from your PR to my local file and it worked, though. I'll come back and let your know if the the error persists.

Roardom commented 2 months ago

Many of the errors will unfortunately still be there.

I recall you having 5-6 different errors. I fixed 2 of them, but the other ones were related to Laravel's (imo very poor) decision of changing the migration syntax in version 11. It's nearly impossible to migrate the existing syntax to the new syntax because they basically make all their column modifications absolute where it used to be relative. E.g. before, when you changed a column from string to int, if the column was previously null, it would remain null. Now, laravel will set the column back to not null if you don't explicitly specify it when converting the string to int.

Theoretically it might be possible to take a schema dump after every migration until April 22 (the release before our laravel 11 update) using both Laravel 10 and Laravel 11 and see where the diffs between them differ. It would probably be the only way we could fix it.

The only other fix for your issue specifically (although a pita) would be to run all the migrations until April 22 on laravel 10, then upgrade to laravel 11, then continue the remaining migrations.

costaht commented 2 months ago

After struggling with those migrations and not really understanding where the problem was, I took a different route. I created a bunch of VMs with Ubuntu 20 and 22, different versions of Unit3d, ran the dump/migration for each version. I went from 6.3 -> 6.5 -> 7.0.2 -> 7.2.5. I had a migration problem to the latest version which is 8.1.3 as of today but I was too sleepy and left it for another day. Hopefully I'll get it done by tomorrow. That's when I'm gonna try to run migrations straight from 6.3 to 8.13 just for fun and hopefully collect the error message for you.

costaht commented 2 months ago

Running the migration from 6.3 to 8.1.3 I got the errors below. Applying the changes from #3830 fixes the issue:

  INFO  Running migrations.  

  2014_10_12_200000_add_two_factor_columns_to_users_table ............................................................................. 70.41ms DONE
  2022_01_23_232931_update_comments_table .................................................................................................. 3s DONE
  2022_08_29_030244_update_history_table_add_refundable ............................................................................... 61.73ms DONE
  2022_08_29_030525_update_torrents_table_add_refundable ............................................................................. 112.25ms DONE
  2022_08_29_031309_update_groups_table_add_refundable ................................................................................ 28.62ms DONE
  2022_08_29_155715_create_client_blacklist_table ..................................................................................... 76.88ms DONE
  2022_09_29_182332_alter_torrents_table ............................................................................................. 108.72ms DONE
  2022_11_23_024350_update_history_table ............................................................................................. 535.47ms FAIL

In 2022_11_23_024350_update_history_table.php line 52:

  Call to undefined method stdClass::delete()  

root@srv-63-80:/var/www/html# vim database/migrations/2022_11_23_024350_update_history_table.php 
root@srv-63-80:/var/www/html# php artisan migrate

   INFO  Running migrations.  

  2022_11_23_024350_update_history_table ............................................................................................... 2m 23s DONE
  2022_11_23_195306_update_peers_table ................................................................................................ 33.07ms FAIL

In 2022_11_23_195306_update_peers_table.php line 46:

  Call to undefined method stdClass::delete()  

root@srv-63-80:/var/www/html# vim database/migrations/2022_11_23_195306_update_peers_table.php 
root@srv-63-80:/var/www/html# php artisan migrate

   INFO  Running migrations.  

  2022_11_23_195306_update_peers_table ..................................................................................................... 1s DONE
  2022_11_24_032502_update_torrents_table ................................................................................................. 41s DONE

But then, I get this error (as you mentioned)

  2022_11_29_030020_alter_user_id ....................................................................................................... 1m 6s FAIL

In Connection.php line 813:

  SQLSTATE[01000]: Warning: 1265 Data truncated for column 'filled_by' at row 5 (Connection: mysql, SQL: alter table `requests` modify `user_id` int unsigned not null, modify `filled_by` int unsigned not null,   
  modify `approved_by` int unsigned not null)                                                                                                                                                                       

In Connection.php line 571:

  SQLSTATE[01000]: Warning: 1265 Data truncated for column 'filled_by' at row 5  

I manually changed their type to int unsigned, commented lines from 574 to 580 in 2022_11_29_030020_alter_user_id.php, and ran the migration again.

Then I started getting errors like: SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'fk_articles_users1'; check that column/key exists (Connection: mysql, SQL: alter tablearticlesdrop foreign keyfk_articles_users1)

All the fk drop failed because non of them exist. After commenting all the their lines I got stuck on this one:

  2022_11_29_030020_alter_user_id .......................................................................................................... 3s FAIL

In Connection.php line 813:

  SQLSTATE[HY000]: General error: 1826 Duplicate foreign key constraint name 'users_deleted_by_foreign' (Connection: mysql, SQL: alter table `users` add constraint `users_deleted_by_foreign` foreign key (`delet  
  ed_by`) references `users` (`id`) on update cascade)                                                                                                                                                              

In Connection.php line 571:

  SQLSTATE[HY000]: General error: 1826 Duplicate foreign key constraint name 'users_deleted_by_foreign'  

This one I don't know how to fix. If you wanna keep going just let me know and I'll continue the migration.

Roardom commented 2 months ago

See the linked PR I completed last night.

costaht commented 2 months ago

Duuude..... I don't know what black magic that was, but you did it! I applied all the changes from #3830 #3938 and ran the migrations on a pristine 6.3 DB, and all migrations ran successfully I guess anyone now will be able to bring very old versions up to date. That's big! 🚀 Thanks a lot!

Roardom commented 1 month ago

jfyi in case you're running unstable in prod: #3995