perara / wg-manager

A easy to use WireGuard dashboard and management tool
MIT License
594 stars 74 forks source link

Database no longer "compatible" when restarting with latest commit pulled (as of 04.09.20) #36

Closed 2L3R4 closed 3 years ago

2L3R4 commented 3 years ago

when doing "git pull" in the directory it pulls the latest commit, (before I was on the commit as of "v1.0"

now when starting the server it throws an error (relevant part): sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: server.subnet

full log:

Traceback (most recent call last):
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context
    cursor, statement, parameters, context
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
    cursor.execute(statement, parameters)
sqlite3.OperationalError: no such column: server.subnet

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/wg-manager/wg_dashboard_backend/venv/bin/uvicorn", line 10, in <module>
    sys.exit(main())
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/uvicorn/main.py", line 331, in main
    run(**kwargs)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/uvicorn/main.py", line 354, in run
    server.run()
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/uvicorn/main.py", line 382, in run
    loop.run_until_complete(self.serve(sockets=sockets))
  File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/uvicorn/main.py", line 389, in serve
    config.load()
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/uvicorn/config.py", line 288, in load
    self.loaded_app = import_from_string(self.app)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/uvicorn/importer.py", line 20, in import_from_string
    module = importlib.import_module(module_str)
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "./main.py", line 76, in <module>
    servers: typing.List[models.WGServer] = _db.query(models.WGServer).all()
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3246, in all
    return list(self)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3405, in __iter__
    return self._execute_and_instances(context)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/orm/query.py", line 3430, in _execute_and_instances
    result = conn.execute(querycontext.statement, self._params)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 984, in execute
    return meth(self, multiparams, params)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 293, in _execute_on_connection
    return connection._execute_clauseelement(self, multiparams, params)
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1103, in _execute_clauseelement
    distilled_params,
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1288, in _execute_context
    e, statement, parameters, cursor, context
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1482, in _handle_dbapi_exception
    sqlalchemy_exception, with_traceback=exc_info[2], from_=e
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/engine/base.py", line 1248, in _execute_context
    cursor, statement, parameters, context
  File "/opt/wg-manager/wg_dashboard_backend/venv/lib/python3.7/site-packages/sqlalchemy/engine/default.py", line 590, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such column: server.subnet
[SQL: SELECT server.id AS server_id, server.interface AS server_interface, server.subnet AS server_subnet, server.address AS server_address, server.v6_address AS server_v6_address, server.v6_subnet AS server_v6_subnet, server.listen_port AS server_listen_port, server.private_key AS server_private_key, server.public_key AS server_public_key, server.endpoint AS server_endpoint, server.dns AS server_dns, server.read_only AS server_read_only, server.post_up AS server_post_up, server.post_down AS server_post_down, server.is_running AS server_is_running, server.configuration AS server_configuration, peer_1.id AS peer_1_id, peer_1.name AS peer_1_name, peer_1.address AS peer_1_address, peer_1.v6_address AS peer_1_v6_address, peer_1.public_key AS peer_1_public_key, peer_1.private_key AS peer_1_private_key, peer_1.shared_key AS peer_1_shared_key, peer_1.dns AS peer_1_dns, peer_1.allowed_ips AS peer_1_allowed_ips, peer_1.read_only AS peer_1_read_only, peer_1.server_id AS peer_1_server_id, peer_1.configuration AS peer_1_configuration 
FROM server LEFT OUTER JOIN peer AS peer_1 ON server.id = peer_1.server_id]
(Background on this error at: http://sqlalche.me/e/e3q8)

so is there a "convert-database.sh" or similar script to add that column?

perara commented 3 years ago

Hi, There should be migrations for this. I'll try to reproduce and post a patch, As a manual, fix you can open the database file and add the column subnet to the server table

Zixim commented 3 years ago

How to do this in the docker container?

2L3R4 commented 3 years ago

closing because fixed in #86

perara commented 3 years ago

Good to hear its working!