mstilkerich/rcmcarddav

migration problem 2

quenenni opened this issue · 2 comments

After resolving the "migration problem" issue, I now have this error (coming from 0018-accountentities2/migrate.php)

It seems the migration of existing accounts doesn't work.
This should be an UPDATE of the account or a DELETE + INSERT statements (line 151 of 0018-accountentities2/migrate.php):

                    $sql_result = $dbh->query(
                        "INSERT INTO $account_table "
                        . "(accountname,username,password,discovery_url,user_id,presetname)"
                        . "VALUES (?,?,?,?,?,?)",
                        $cols
                    );

I emptied the carddav_account table in order to bypass this migration step (knowing accounts will be recreated auto when the user will log again).

==> carddav.log <==
[19-Apr-2023 16:18:57 +0200]: <dulggo2q> [1 DBG] carddav::afterLogin
[19-Apr-2023 16:18:57 +0200]: <dulggo2q> [1 DBG] internalGet query: SELECT `filename` FROM carddav_migrations
[19-Apr-2023 16:18:57 +0200]: <dulggo2q> [3 NTC] In migration: 0018-accountentities2

==> errors.log <==
[19-Apr-2023 16:18:57 +0200]: <dulggo2q> DB Error: [1062] Duplicate entry '33-Yyyy' for key 'user_id' (SQL Query: INSERT INTO carddav_accounts (accountname,username,password,discovery_url,user_id,presetname)VALUES ('Address book','%l','{DES_KEY}BYBcPmmh8BmgtUp/z67u5Q==','https://cloud.yyyy.coop/remote.php/dav/addressbooks/users/xxxx/','33','Yyyy')) in /var/www/roundcube-test/program/lib/Roundcube/rcube_db.php on line 567 (GET /index.php/login/oauth?code=e30d416dbf8d86ecc107a5d13cf35566fec2ebf6aeec24dd054d8991a6c38bd0&state=R7DWGKxhYyZG&session_state=5dwFOWn8qfrWCsF5%2FScPOcDwTcRJAY50Tyu2lhQmr2U%3D.R0FVeGp2Y3E3amlkcHFVazRhaFkybXB5UEtFWHlCYXgrZUhjWlBjU2Z2K0tlRzljSFZhYm4vVXRGR1VGeHozdVR4MkdraGY5T0hSNVJ3NjlkaUx5YU1ENUQ2aDZXQXM0b1RPNHJmT2RPUTA9)

==> carddav.log <==
[19-Apr-2023 16:18:57 +0200]: <dulggo2q> [5 ERR] Error in PHP-based migration Migration0018: MStilkerich\RCMCardDAV\DBMigrations\Migration0018::migrate account insert failed: [1062] Duplicate entry '33-Yyyy' for key 'user_id'

The accounts table is newly created in migration empty and supposed to be empty when migration 0018 is executed. Therefore an UPDATE will not work, and a DELETE is not necessary.

Ho, then I understand now the problem.
Because of the early problems I had, my table was not empty.
Thanks