Added support to postgresql and Mysql with SqlAlchemy

This commit is contained in:
Donald Zou
2025-05-05 00:40:29 +08:00
parent 61404d9c12
commit 196dc78b4f
4 changed files with 25 additions and 14 deletions

View File

@@ -1803,7 +1803,10 @@ class DashboardConfig:
"welcome_session": "true"
},
"Database":{
"type": "sqlite"
"type": "sqlite",
"host": "",
"username": "",
"password": ""
},
"Email":{
"server": "",
@@ -1829,6 +1832,13 @@ class DashboardConfig:
self.APIAccessed = False
self.SetConfig("Server", "version", DASHBOARD_VERSION)
def getConnectionString(self, database) -> str or None:
if self.GetConfig("Database", "type")[1] == "sqlite":
return f'sqlite:///{os.path.join(CONFIGURATION_PATH, "db", f".db")}'
elif self.GetConfig("Database", "type")[1] == "postgresql":
return f'postgresql+psycopg2://{self.GetConfig("Database", "username")[1]}:{self.GetConfig("Database", "password")[1]}@{self.GetConfig("Database", "host")[1]}/{database}'
return None
def __createAPIKeyTable(self):
existingTable = sqlSelect("SELECT name FROM sqlite_master WHERE type='table' AND name = 'DashboardAPIKeys'").fetchall()
if len(existingTable) == 0:
@@ -3185,8 +3195,8 @@ def InitWireguardConfigurationsList(startup: bool = False):
AllPeerShareLinks: PeerShareLinks = PeerShareLinks()
AllPeerJobs: PeerJobs = PeerJobs()
JobLogger: PeerJobLogger = PeerJobLogger(CONFIGURATION_PATH, AllPeerJobs)
DashboardLogger: DashboardLogger = DashboardLogger(CONFIGURATION_PATH)
JobLogger: PeerJobLogger = PeerJobLogger(CONFIGURATION_PATH, AllPeerJobs, DashboardConfig)
DashboardLogger: DashboardLogger = DashboardLogger(CONFIGURATION_PATH, DashboardConfig)
_, app_ip = DashboardConfig.GetConfig("Server", "app_ip")
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
_, WG_CONF_PATH = DashboardConfig.GetConfig("Server", "wg_conf_path")