Made the postgres connection be tested before opening, fixed the postgres create new users table

Signed-off-by: Arzumify <jliwin98@danwin1210.de>
This commit is contained in:
Tracker-Friendly 2024-10-14 12:23:33 +01:00
parent 4fe28255fe
commit 58838f51ad
2 changed files with 24 additions and 11 deletions

13
main.go
View File

@ -161,6 +161,18 @@ func processInterServiceMessage(channel chan library.InterServiceMessage, config
connectionString = config.Database.ConnectionString + "?search_path=\"" + message.ServiceID.String() + "\"" connectionString = config.Database.ConnectionString + "?search_path=\"" + message.ServiceID.String() + "\""
} }
pluginConn, err := sql.Open("postgres", connectionString) pluginConn, err := sql.Open("postgres", connectionString)
if err != nil {
// Report an error
services[message.ServiceID].Inbox <- library.InterServiceMessage{
ServiceID: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
ForServiceID: message.ServiceID,
MessageType: 1,
SentAt: time.Now(),
Message: err,
}
} else {
// Test the connection
err = pluginConn.Ping()
if err != nil { if err != nil {
// Report an error // Report an error
services[message.ServiceID].Inbox <- library.InterServiceMessage{ services[message.ServiceID].Inbox <- library.InterServiceMessage{
@ -186,6 +198,7 @@ func processInterServiceMessage(channel chan library.InterServiceMessage, config
} }
} }
} }
}
} else { } else {
// Report an error // Report an error
services[message.ServiceID].Inbox <- library.InterServiceMessage{ services[message.ServiceID].Inbox <- library.InterServiceMessage{

View File

@ -227,7 +227,7 @@ func Main(information library.ServiceInitializationInformation) {
logFunc(err.Error(), 3, information) logFunc(err.Error(), 3, information)
} }
// Create the users table // Create the users table
_, err = conn.DB.Exec("CREATE TABLE IF NOT EXISTS users (id BYTEA PRIMARY KEY NOT NULL UNIQUE, created INTEGER NOT NULL, username TEXT NOT NULL UNIQUE, password BYTEA NOT NULL, salt BYTEA NOT NULL)") _, err = conn.DB.Exec("CREATE TABLE IF NOT EXISTS users (id BYTEA PRIMARY KEY NOT NULL UNIQUE, created INTEGER NOT NULL, username TEXT NOT NULL UNIQUE, publicKey BYTEA NOT NULL)")
if err != nil { if err != nil {
logFunc(err.Error(), 3, information) logFunc(err.Error(), 3, information)
} }