How would you go about and seed a database when it's first being created?
I don't want to drop all tables every time the server starts up, but when I decide to clear the complete database I'd like to seed it with some mock data.
What would be the prefered way to do that? Should I do this after the
database.connect
function? Would you just use
insertAndIgnore
, or is there some kind of callback on the database that states that it has been created instead of just connected? 🤔
j
jean-paul
01/01/2024, 7:35 PM
I'm still learning, so my apologies if I lead you astray 😉
The way I am currently doing it was in some tutorial, and it called apply on the instantiated service in the Application.configureRouting() definition. Something like this:
Copy code
fun Application.configureRouting() {
val dao: DAOFacade = DAOImpl()
.apply {
runBlocking {
if (allPosts().isEmpty()) {
addNewPost("PostTitle", "Post Content")
addNewPost("PostTitle2", "Post 2 Content")
}
}
}
}