feat(server): seed test users alice and bob on startup

This commit is contained in:
Jens Reinemann 2026-05-18 08:19:58 +02:00
parent dad2907481
commit 75f46de05e

View file

@ -53,6 +53,7 @@ internal object DatabaseFactory {
EncryptionService.init(encryptionKey)
migrateEncryptData()
seedAdmin(adminPassword)
seedTestUsers()
}
private fun runFlyway(dataSource: HikariDataSource, jdbcUrl: String, user: String, password: String) {
@ -190,4 +191,31 @@ internal object DatabaseFactory {
}
}
}
private fun seedTestUsers() {
val testPassword = "15z3QA7mtosybQKSplhi"
val testUsers = listOf("alice", "bob")
transaction {
for (name in testUsers) {
val exists = Users.selectAll().where { Users.username eq name }.count() > 0
if (!exists) {
val userId = UUID.randomUUID().toString()
val inventoryId = UUID.randomUUID().toString()
Inventories.insert {
it[id] = inventoryId
it[createdAt] = System.currentTimeMillis()
}
Users.insert {
it[id] = userId
it[username] = name
it[passwordHash] = BCrypt.hashpw(testPassword, BCrypt.gensalt())
it[createdAt] = System.currentTimeMillis()
it[isAdmin] = false
it[Users.inventoryId] = inventoryId
}
logger.info("Created test user: $name")
}
}
}
}
}