tillsteinbach / VWsFriend

VW WeConnect visualization and control
MIT License
238 stars 18 forks source link

Migration fails for upgrade from 0.24.5 to 0.24.6 #662

Closed WerFra closed 3 days ago

WerFra commented 4 days ago

After updating to 0.24.6 vwsfriend no longer starts.

2024-09-13T21:44:39+0000:INFO:vwsfriend_base:vwsfriend 0.24.6 (using WeConnect-python 0.60.5, WeConnect-mqtt 0.49.2)
2024-09-13T21:44:39+0000:INFO:session_manager:Could not use token from file /tmp/weconnect.token ([Errno 2] No such file or directory: '/tmp/weconnect.token')
2024-09-13T21:44:40+0000:INFO:agent_connector:It looks like you have an existing database will check if an upgrade is necessary
2024-09-13T21:44:40+0000:INFO:migration:Context impl PostgresqlImpl.
2024-09-13T21:44:40+0000:INFO:migration:Will assume transactional DDL.
2024-09-13T21:44:40+0000:INFO:migration:Running upgrade 6c4cdc5006ba -> 83cab0919846, add missing Enums
Traceback (most recent call last):
  File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/engine/base.py", line 1967, in _exec_single_context
    self.dialect.do_execute(
  File "/opt/venv/lib/python3.12/site-packages/sqlalchemy/engine/default.py", line 941, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.DuplicateObject: enum label "OTHER" already exists
WerFra commented 4 days ago

To get vwsfriend running again, I manually set my DB version to the target version.

tillsteinbach commented 3 days ago

This is really odd. Did you make any changes to the database before?

WerFra commented 3 days ago

I haven't previously done any changes to the database. I created the system in the beginning of August with 0.24.5. Looks like the the enum value already existed in weconnect-cli at that time. I never used SQL alchemy, so I don't know how it determines what it does during DB creation, but maybe it already added that value then. Looking through the migrations, I didn't see any added for a long time, may be it was missing for earlier versions?

tillsteinbach commented 3 days ago

Ah, yes! The enum was autocreated for you. I need to add a check that it is only added when missing. I did not come up with that corner case before.

MatzeG commented 3 days ago

Same here also without any changes in the db.

tillsteinbach commented 3 days ago

I hope I got this fixed with 0.24.7 that should be online soon

WerFra commented 3 days ago

After resetting my database version to the old one and upgrading, I can confirm that 0.24.7 fixes this issue.

tillsteinbach commented 3 days ago

Great! Thanks for checking!