fix: use database dialect for configuration backup and restore (#1370)

This commit is contained in:
Evgeny Volferts
2026-10-25 22:32:12 +01:00
committed by GitHub
parent 58fa826862
commit b6da11ec2d
+15 -8
View File
@@ -235,14 +235,13 @@ class WireguardConfiguration:
existingTables = [self.Name, f'{self.Name}_restrict_access', f'{self.Name}_transfer', f'{self.Name}_deleted'] existingTables = [self.Name, f'{self.Name}_restrict_access', f'{self.Name}_transfer', f'{self.Name}_deleted']
try: try:
with self.engine.begin() as conn: with self.engine.begin() as conn:
for t in existingTables: for name in existingTables:
table = sqlalchemy.Table(name, sqlalchemy.MetaData())
conn.execute( conn.execute(
sqlalchemy.text( sqlalchemy.schema.DropTable(table, if_exists=True)
f'DROP TABLE "{t}"'
) )
) except Exception:
except Exception as e: current_app.logger.exception("Dropping table failed")
current_app.logger.error("Dropping table failed")
return False return False
return True return True
@@ -327,11 +326,19 @@ class WireguardConfiguration:
rows = conn.execute(i.select()).mappings().fetchall() rows = conn.execute(i.select()).mappings().fetchall()
for row in rows: for row in rows:
insert_stmt = i.insert().values(dict(row)) insert_stmt = i.insert().values(dict(row))
yield str(insert_stmt.compile(compile_kwargs={"literal_binds": True})) yield str(
insert_stmt.compile(
dialect=self.engine.dialect,
compile_kwargs={"literal_binds": True},
)
)
def __importDatabase(self, sqlFilePath, restore = False) -> bool: def __importDatabase(self, sqlFilePath, restore = False) -> bool:
if not restore: if not restore:
self.__dropDatabase() if not self.__dropDatabase():
raise RuntimeError(
f"Failed to drop tables for configuration {self.Name}"
)
self.createDatabase() self.createDatabase()
if not os.path.exists(sqlFilePath): if not os.path.exists(sqlFilePath):
return False return False