diff --git a/wg_dashboard_backend/main.py b/wg_dashboard_backend/main.py index 6b23dea..9eed90c 100644 --- a/wg_dashboard_backend/main.py +++ b/wg_dashboard_backend/main.py @@ -38,13 +38,6 @@ if not database_exists(engine.url): # Create database from metadata models.Base.metadata.create_all(engine) - # Do migrations - try: - main(["version_control", DATABASE_URL, "migrations"]) - except DatabaseAlreadyControlledError: - pass - main(["upgrade", DATABASE_URL, "migrations"]) - # Create default user _db.add(models.User( username=os.getenv("ADMIN_USERNAME", "admin"), @@ -55,6 +48,15 @@ if not database_exists(engine.url): )) _db.commit() + +# Do migrations +try: + main(["version_control", DATABASE_URL, "migrations"]) +except DatabaseAlreadyControlledError: + pass +main(["upgrade", DATABASE_URL, "migrations"]) + + servers: typing.List[models.WGServer] = _db.query(models.WGServer).all() for s in servers: try: