fixed creation of first user upon database initalization

This commit is contained in:
2025-07-07 22:23:40 +02:00
parent d4bcf07b5c
commit 9d83008a62
6 changed files with 22 additions and 19 deletions

View File

@@ -20,7 +20,6 @@ import de.srsoftware.umbrella.user.api.UserDb;
import de.srsoftware.umbrella.user.model.*;
import de.srsoftware.umbrella.user.model.Session;
import de.srsoftware.umbrella.user.model.UmbrellaUser;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.ResultSet;
@@ -159,8 +158,17 @@ CREATE TABLE IF NOT EXISTS {0} (
throw new RuntimeException(e);
}
long count = 0L;
try {
Query.insertInto(TABLE_USERS,LOGIN,PASS,THEME,SETTINGS).values("admin", hasher.hash("admin",null),"default",null).execute(db);
ResultSet rs = select("COUNT(*)").from(TABLE_USERS).exec(db);
if (rs.next()) count = rs.getLong(1);
rs.close();
} catch (SQLException ignored) {
// go on with table creation
}
try {
if (count<1) insertInto(TABLE_USERS,LOGIN,PASS,THEME,SETTINGS).values("admin", hasher.hash("admin",null),"default",null).execute(db);
} catch (SQLException e) {
LOG.log(ERROR,"Failed to create first user…");
throw new RuntimeException(e);