|
1 | 1 | package scaladex.infra.migrations
|
| 2 | +import cats.effect.IO |
2 | 3 | import cats.implicits._
|
3 |
| -import com.typesafe.scalalogging.LazyLogging |
4 | 4 | import doobie.Query0
|
5 | 5 | import doobie.util.update.Update
|
6 |
| -import org.flywaydb.core.api.migration.BaseJavaMigration |
7 |
| -import org.flywaydb.core.api.migration.Context |
8 | 6 | import scaladex.core.model.Artifact
|
9 | 7 | import scaladex.core.model.Artifact.MavenReference
|
10 | 8 | import scaladex.infra.sql.DoobieUtils.Mappings._
|
11 | 9 | import scaladex.infra.sql.DoobieUtils.selectRequest
|
12 | 10 | import scaladex.infra.sql.DoobieUtils.updateRequest
|
13 | 11 |
|
14 |
| -class V13_2__update_new_fields_in_artifacts extends BaseJavaMigration with ScaladexBaseMigration with LazyLogging { |
15 |
| - override def migrate(context: Context): Unit = |
16 |
| - try { |
17 |
| - (for { |
18 |
| - oldArtifacts <- run(xa)(selectArtifact.to[Seq]) |
19 |
| - groupedArtifacts = oldArtifacts.grouped(10000).toSeq |
20 |
| - _ <- groupedArtifacts |
21 |
| - .map(artifacts => run(xa)(updateNewFields.updateMany(artifacts.map(update)))) |
22 |
| - .sequence |
23 |
| - } yield ()) |
24 |
| - .unsafeRunSync() |
| 12 | +class V13_2__update_new_fields_in_artifacts extends FlywayMigration { |
| 13 | + override def migrationIO: IO[Unit] = |
| 14 | + for { |
| 15 | + oldArtifacts <- run(selectArtifact.to[Seq]) |
| 16 | + groupedArtifacts = oldArtifacts.grouped(10000).toSeq |
| 17 | + _ <- groupedArtifacts |
| 18 | + .map(artifacts => run(updateNewFields.updateMany(artifacts.map(update)))) |
| 19 | + .sequence |
| 20 | + } yield () |
25 | 21 |
|
26 |
| - } catch { |
27 |
| - case e: Throwable => |
28 |
| - logger.info("failed to migrate the database") |
29 |
| - throw new Exception(s"failed to migrate the database because of ${e.getMessage}") |
30 |
| - } |
31 |
| - |
32 |
| - val selectArtifact: Query0[Artifact] = selectRequest("artifacts", Seq("*")) |
33 |
| - val updateNewFields: Update[(Boolean, Boolean, MavenReference)] = |
| 22 | + private val selectArtifact: Query0[Artifact] = selectRequest("artifacts", Seq("*")) |
| 23 | + private val updateNewFields: Update[(Boolean, Boolean, MavenReference)] = |
34 | 24 | updateRequest("artifacts", Seq("is_semantic", "is_prerelease"), Seq("group_id", "artifact_id", "version"))
|
35 | 25 |
|
36 | 26 | private def update(artifact: Artifact): (Boolean, Boolean, MavenReference) =
|
|
0 commit comments