feat(server): seed test users alice and bob on startup
This commit is contained in:
parent
dad2907481
commit
75f46de05e
1 changed files with 28 additions and 0 deletions
|
|
@ -53,6 +53,7 @@ internal object DatabaseFactory {
|
||||||
EncryptionService.init(encryptionKey)
|
EncryptionService.init(encryptionKey)
|
||||||
migrateEncryptData()
|
migrateEncryptData()
|
||||||
seedAdmin(adminPassword)
|
seedAdmin(adminPassword)
|
||||||
|
seedTestUsers()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runFlyway(dataSource: HikariDataSource, jdbcUrl: String, user: String, password: String) {
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue