File tree Expand file tree Collapse file tree 3 files changed +26
-8
lines changed
flyway/src/main/scala/com/avast/sst/flyway
flyway-pureconfig/src/main/scala/com/avast/sst/flyway/pureconfig Expand file tree Collapse file tree 3 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 1
1
package com .avast .sst .flyway .pureconfig
2
2
3
+ import java .nio .charset .{Charset , IllegalCharsetNameException , UnsupportedCharsetException }
4
+
5
+ import cats .syntax .either ._
3
6
import com .avast .sst .flyway .FlywayConfig
7
+ import org .flywaydb .core .api .MigrationVersion
4
8
import pureconfig .ConfigReader
9
+ import pureconfig .error .ExceptionThrown
5
10
import pureconfig .generic .semiauto .deriveReader
6
11
7
12
trait ConfigReaders {
8
13
14
+ implicit private [pureconfig] val charsetReader : ConfigReader [Charset ] = ConfigReader [String ].emap { value =>
15
+ try {
16
+ Charset .forName(value).asRight
17
+ } catch {
18
+ case ex @ (_ : IllegalArgumentException | _ : IllegalCharsetNameException | _ : UnsupportedCharsetException ) =>
19
+ ExceptionThrown (ex).asLeft
20
+ }
21
+ }
22
+
23
+ implicit val migrationVersionReader : ConfigReader [MigrationVersion ] = ConfigReader [String ].map(MigrationVersion .fromVersion)
24
+
9
25
implicit val configReader : ConfigReader [FlywayConfig ] = deriveReader
10
26
11
27
}
Original file line number Diff line number Diff line change 1
1
package com .avast .sst .flyway
2
2
3
- final case class FlywayConfig (url : String ,
4
- username : String ,
5
- password : String ,
6
- baselineOnMigrate : Boolean = false ,
7
- baselineVersion : Option [String ] = None ,
3
+ import java .nio .charset .{Charset , StandardCharsets }
4
+
5
+ import org .flywaydb .core .api .MigrationVersion
6
+
7
+ final case class FlywayConfig (baselineOnMigrate : Boolean = false ,
8
+ baselineVersion : Option [MigrationVersion ] = None ,
8
9
baselineDescription : Option [String ] = None ,
9
10
batch : Boolean = false ,
10
11
cleanDisabled : Boolean = false ,
11
12
cleanOnValidationError : Boolean = false ,
12
13
connectRetries : Int = 0 ,
13
- encoding : String = " UTF-8 " ,
14
+ encoding : Charset = StandardCharsets . UTF_8 ,
14
15
group : Boolean = false ,
15
16
ignoreFutureMigrations : Boolean = true ,
16
17
ignoreIgnoredMigrations : Boolean = false ,
Original file line number Diff line number Diff line change 1
1
package com .avast .sst .flyway
2
2
3
3
import cats .effect .Sync
4
+ import javax .sql .DataSource
4
5
import org .flywaydb .core .Flyway
5
6
6
7
object FlywayModule {
7
8
8
9
@ SuppressWarnings (Array (" org.wartremover.warts.NonUnitStatements" ))
9
- def make [F [_]: Sync ](config : FlywayConfig ): F [Flyway ] = {
10
+ def make [F [_]: Sync ](dataSource : DataSource , config : FlywayConfig ): F [Flyway ] = {
10
11
Sync [F ].delay {
11
12
val builder = Flyway
12
13
.configure
13
- .dataSource(config.url, config.username, config.password )
14
+ .dataSource(dataSource )
14
15
.baselineOnMigrate(config.baselineOnMigrate)
15
16
.batch(config.batch)
16
17
.cleanDisabled(config.cleanDisabled)
You can’t perform that action at this time.
0 commit comments