From 58838f51ad018a4d7214ec18540b9234870ab0ba Mon Sep 17 00:00:00 2001 From: Arzumify Date: Mon, 14 Oct 2024 12:23:33 +0100 Subject: [PATCH] Made the postgres connection be tested before opening, fixed the postgres create new users table Signed-off-by: Arzumify --- main.go | 33 +++++++++++++++++++++++---------- services-src/auth/main.go | 2 +- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/main.go b/main.go index a260e93..2f65681 100644 --- a/main.go +++ b/main.go @@ -171,16 +171,29 @@ func processInterServiceMessage(channel chan library.InterServiceMessage, config Message: err, } } else { - // Report a successful activation - services[message.ServiceID].Inbox <- library.InterServiceMessage{ - ServiceID: uuid.MustParse("00000000-0000-0000-0000-000000000001"), - ForServiceID: message.ServiceID, - MessageType: 2, - SentAt: time.Now(), - Message: library.Database{ - DB: pluginConn, - DBType: library.Postgres, - }, + // Test the connection + err = pluginConn.Ping() + 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 { + // Report a successful activation + services[message.ServiceID].Inbox <- library.InterServiceMessage{ + ServiceID: uuid.MustParse("00000000-0000-0000-0000-000000000001"), + ForServiceID: message.ServiceID, + MessageType: 2, + SentAt: time.Now(), + Message: library.Database{ + DB: pluginConn, + DBType: library.Postgres, + }, + } } } } diff --git a/services-src/auth/main.go b/services-src/auth/main.go index ec03ced..0162a8b 100644 --- a/services-src/auth/main.go +++ b/services-src/auth/main.go @@ -227,7 +227,7 @@ func Main(information library.ServiceInitializationInformation) { logFunc(err.Error(), 3, information) } // 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 { logFunc(err.Error(), 3, information) }