vorta icon indicating copy to clipboard operation
vorta copied to clipboard

FR: Do not fail when some db migrations are already in place.

Open real-yfprojects opened this issue 2 years ago • 1 comments

The problem

As reported in #1761 and multiple previous issues sometimes database migrations seem to be only half way done. This leads to consequent error messages like

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/vorta/__main__.py", line 66, in main
    init_db(sqlite_db)
  File "/usr/lib/python3/dist-packages/vorta/store/connection.py", line 83, in init_db
    run_migrations(current_schema, con)
  File "/usr/lib/python3/dist-packages/vorta/store/migrations.py", line 190, in run_migrations
    _apply_schema_update(
  File "/usr/lib/python3/dist-packages/vorta/store/migrations.py", line 225, in _apply_schema_update
    migrate(*operations)
  File "/usr/lib/python3/dist-packages/playhouse/migrate.py", line 886, in migrate
    operation.run()
  File "/usr/lib/python3/dist-packages/peewee.py", line 3177, in execute_sql
    cursor.execute(sql, params or ())
sqlite3.OperationalError: duplicate column name: schedule_interval_unit

Requested Solution

Instead of failing vorta could only do those migrations actually needed by comparing the state of the database with the expected state. This will also help when testing PRs that add db migrations.

However this isn't straightforward at all as far as I can tell at the moment. These are possible roadblockers:

  • peewee doesn't provide such features and their might not be a viable third party library we can use together with peewee.
  • We sometimes have special data altering migrations steps like the following and I don't know how those could be implemented with the approach requested in this FR. https://github.com/borgbase/vorta/blob/567a3546ae09878cf64f9f10c5c6f7bb7254720e/src/vorta/store/migrations.py#L99-L106

Alternatives

  • Catch error and ignore it.
  • Find cause of incomplete migrations.

real-yfprojects avatar Sep 01 '23 19:09 real-yfprojects

I'm affected by this issue. That would be a nice improvement :)

lapineige avatar Jan 09 '25 14:01 lapineige