Errors after restoring old appdata

Hi All,
Some help with this would be appreciated.
Just restored an old appdata after getting some corruption with the sqlite database.
Now when I try and sign in I get “Error saving device” on the webpage and the following in the logs:

[2024-02-27 12:04:33.780][request][INFO] GET /api/config
[2024-02-27 12:04:33.780][response][INFO] (config) GET /api/config => 200 OK
[2024-02-27 12:04:38.331][request][INFO] GET /api/devices/knowndevice
[2024-02-27 12:04:38.332][response][INFO] (get_known_device) GET /api/devices/knowndevice => 200 OK
[2024-02-27 12:04:42.410][request][INFO] POST /identity/accounts/prelogin
[2024-02-27 12:04:42.410][response][INFO] (prelogin) POST /identity/accounts/prelogin => 200 OK
[2024-02-27 12:04:42.506][request][INFO] POST /identity/connect/token
[2024-02-27 12:04:47.119][error][ERROR] Error saving device.
[CAUSE] DatabaseError(
    UniqueViolation,
    "UNIQUE constraint failed: devices.uuid, devices.user_uuid",
)
[2024-02-27 12:04:47.119][response][INFO] (login) POST /identity/connect/token => 400 Bad Request

I have tried vacuuming/dumping the database with no success, also installing a fresh docker container and copying the db into the new docker with the same error occuring.
As mentioned this is using sqlite not any mysql/mariadb.
When running PRAGMA integrity_check; I get the following results:
wrong # of entries in index sqlite_autoindex_devices_1

Any way to fix this?
Thanks!

Nevermind, managed to fix.
For future people:
Managed to fix by dumping the db.sqlite3:

> sqlite3 db.sqlite3
> .output ./backup.sql
> .dump
> .exit

Backing up all db files just in case
Deleting db.sqlite3
Not starting vaultwarden yet
Then creating the db again by restoring before starting vaultwarden again:

> sqlite db.sqlite3 
> .read ./backup.sql

The above will not work unless the db.sqlite3 is completely removed before you restore the dump.

You could also have purged the devices table, that would have worked too.