I really stuck with this: I need to integrate flyw...
# ktor
s
I really stuck with this: I need to integrate flyway with the ktor and a custom application.conf file. I have my database connection configured in the application.conf, so I need to have it also use in the flyway when applying migrations... and the place where the conf file is read changes, on my machine is resources/application.conf, on production, who knows, it will be passed as an argument. It looks like a normal configuration, however, it's not really easy to do it.
e
@cy
m
hey
common, I was playing with that this weekend. Look this: https://github.com/JMagnoJunior/kotlin-ktor-example
s
Hey. Thanks. You did what I want to avoid. You have hardcoded the database connection in the gradle file. This way it would be hard to deploy the application on production using different database settings.
m
I am learning kotlin, so I would like to have suggestion about this project to know what I could improve. Maybe it's "too spring" style. I don't know.
@Szymon Lipiński but take a look on the tests
s
I'm learning ktor too. I don't know how to do implement it properly. I want to have settings in one file. I thought about using the application.conf in development, build jar, then use external application.conf on a server with
java -jar x-all.jar -config=production_application.conf
. In this case I think having the flyway db connection in the gradle build is not the best idea. But I cannot do it differently.
m
you can use this same api but to use the config from the application.config file
s
The tests also have a hardcoded db connection. I cannot use it, as I cannot use h2 for testing.
So this is my problem currently: how to remove flyway settings from gradle.build and use the properties.conf everywhere 🙂
m
yes.. It was hardcoded, but you don't need to... This is a kotlin file. you can use the config file as you want.
s
I'd read it from the application.conf. This is the easy part. The hard part is to use flyway without storing the db connection in two files.
m
you can use this, but getting the config from app. Something like this:
Copy code
...
        val flyway: Flyway = Flyway.configure()
        .locations(config.location)
        .dataSource("config.dburl, config.user, null)
        .load();
...
    flyway.migrate();
s
do the migration from the code https://flywaydb.org/getstarted/firststeps/api
yeah, the thing Magno says
m
I did not use on my project because the setup was different. But I will change it. Maybe today on the end of the day.
s
oh, this way... it makes sense, thank you. I tried to put all the stuff in gradle and I couldn't figure out how to.
m
@Szymon Lipiński your project is public? If it is I would like to see.. if it's not, no problem 😃
s
It's not. There is barely anything working. I just started. I have a basic ktor app with one route and now I'm trying to add the flyway stuff.
m
ok... 😢
s
I will have a working example today
265 Views