-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
150 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
modules/infra/src/main/scala/scaladex/infra/migrations/FlywayMigration.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package scaladex.infra.migrations | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
import cats.effect.ContextShift | ||
import cats.effect.IO | ||
import com.typesafe.scalalogging.LazyLogging | ||
import doobie.implicits._ | ||
import doobie.util.transactor.Transactor | ||
import org.flywaydb.core.api.migration.BaseJavaMigration | ||
import org.flywaydb.core.api.migration.Context | ||
import scaladex.infra.config.PostgreSQLConfig | ||
|
||
abstract class FlywayMigration extends BaseJavaMigration with LazyLogging { | ||
def migrationIO: IO[Unit] | ||
|
||
def run[A](v: doobie.ConnectionIO[A]): IO[A] = | ||
v.transact(FlywayMigration.transactor) | ||
|
||
override def migrate(context: Context): Unit = | ||
migrationIO.unsafeRunSync() | ||
} | ||
|
||
object FlywayMigration { | ||
private implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContext.global) | ||
private val config = PostgreSQLConfig.load().get | ||
private val transactor: Transactor.Aux[IO, Unit] = | ||
Transactor.fromDriverManager[IO](config.driver, config.url, config.user, config.pass.decode) | ||
} |
27 changes: 0 additions & 27 deletions
27
modules/infra/src/main/scala/scaladex/infra/migrations/ScaladexBaseMigration.scala
This file was deleted.
Oops, something went wrong.
25 changes: 7 additions & 18 deletions
25
...es/infra/src/main/scala/scaladex/infra/migrations/V11_2__add_data_to_the_new_tables.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
package scaladex.infra.migrations | ||
|
||
import com.typesafe.scalalogging.LazyLogging | ||
import org.flywaydb.core.api.migration.BaseJavaMigration | ||
import org.flywaydb.core.api.migration.Context | ||
import cats.effect.IO | ||
import scaladex.infra.sql.ArtifactTable | ||
import scaladex.infra.sql.ReleaseTable | ||
|
||
class V11_2__add_data_to_the_new_tables extends BaseJavaMigration with ScaladexBaseMigration with LazyLogging { | ||
override def migrate(context: Context): Unit = | ||
try { | ||
(for { | ||
releases <- run(xa)(ArtifactTable.getReleasesFromArtifacts.to[Seq]) | ||
_ <- run(xa)(ReleaseTable.insertIfNotExists.updateMany(releases)) | ||
} yield ()) | ||
.unsafeRunSync() | ||
|
||
} catch { | ||
case e: Throwable => | ||
logger.info("failed to migrate the database") | ||
throw new Exception(s"failed to migrate the database because of ${e.getMessage}") | ||
} | ||
|
||
class V11_2__add_data_to_the_new_tables extends FlywayMigration { | ||
override def migrationIO: IO[Unit] = | ||
for { | ||
releases <- run(ArtifactTable.getReleasesFromArtifacts.to[Seq]) | ||
_ <- run(ReleaseTable.insertIfNotExists.updateMany(releases)) | ||
} yield () | ||
} |
34 changes: 12 additions & 22 deletions
34
...nfra/src/main/scala/scaladex/infra/migrations/V13_2__update_new_fields_in_artifacts.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 7 additions & 11 deletions
18
modules/infra/src/main/scala/scaladex/infra/migrations/V17__add_mill_platform.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 12 additions & 22 deletions
34
modules/infra/src/main/scala/scaladex/infra/migrations/V9__fix_platform_and_language.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 0 additions & 57 deletions
57
modules/infra/src/test/scala/scaladex/infra/BaseDatabaseSuite.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.