mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2026-10-30 01:12:07 +00:00
fix: use database dialect for configuration backup and restore (#1370)
This commit is contained in:
@@ -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 as e:
|
except Exception:
|
||||||
current_app.logger.error("Dropping table failed")
|
current_app.logger.exception("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
|
||||||
|
|||||||
Reference in New Issue
Block a user