From c9228950d5aed27c8fb753847da5fe18e2a83831 Mon Sep 17 00:00:00 2001 From: "kham.vilaythong" Date: Sat, 16 May 2026 23:22:42 +1000 Subject: [PATCH] add check db is not there create db not there same as table --- API/FamilyTreeAPI/Program.cs | 11 ++++++++++- API/FamilyTreeAPI/appsettings.json | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/API/FamilyTreeAPI/Program.cs b/API/FamilyTreeAPI/Program.cs index 8ca30e6..0e36ec0 100644 --- a/API/FamilyTreeAPI/Program.cs +++ b/API/FamilyTreeAPI/Program.cs @@ -123,7 +123,16 @@ using (var scope = app.Services.CreateScope()) //if (!databaseCreator.Exists()) try { - databaseCreator.CreateTables(); + // Check if database exists + if (!databaseCreator.Exists()) + { + databaseCreator.Create(); + } + + if (!databaseCreator.HasTables()) + { + databaseCreator.CreateTables(); + } } catch { diff --git a/API/FamilyTreeAPI/appsettings.json b/API/FamilyTreeAPI/appsettings.json index e599f51..870e5c1 100644 --- a/API/FamilyTreeAPI/appsettings.json +++ b/API/FamilyTreeAPI/appsettings.json @@ -3,7 +3,7 @@ "AppSettings": { "Secret": "Super Secret SIGN AND VERIFY JWT TOKENS, BEARER TOKEN USE WHEN CALLING THIS API.", "SQLConnectionString_i": "host=localhost;port=5432;database=FamilyTreeDB_prod;username=postgres;password=Positive~1;", - "SQLConnectionString": "host=192.168.1.240;port=5432;database=FamilyTreeDB;username=postgres;password=Positive~1;", + "SQLConnectionString": "host=192.168.1.240;port=5432;database=FamilyTreeDB_prod;username=postgres;password=Positive~1;", "ImageFolder": "c:\\temp\\Family", "ImportFolder": "c:\\temp"