diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala b/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala index ca118f683..ccfc9018f 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala @@ -49,9 +49,6 @@ case class Artifact( val mavenReference: Artifact.MavenReference = Artifact.MavenReference(groupId.value, artifactId, version.encode) - def release: Release = - Release(projectRef.organization, projectRef.repository, platform, language, version, releaseDate) - def releaseDateFormat: String = Artifact.dateFormatter.format(releaseDate) def fullHttpUrl(env: Env): String = diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/Release.scala b/modules/core/shared/src/main/scala/scaladex/core/model/Release.scala deleted file mode 100644 index 71120f43e..000000000 --- a/modules/core/shared/src/main/scala/scaladex/core/model/Release.scala +++ /dev/null @@ -1,14 +0,0 @@ -package scaladex.core.model - -import java.time.Instant - -import scaladex.core.model.Project._ - -case class Release( - organization: Organization, - repository: Repository, - platform: Platform, - language: Language, - version: SemanticVersion, - releaseDate: Instant -) diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/ReleaseDependency.scala b/modules/core/shared/src/main/scala/scaladex/core/model/ReleaseDependency.scala deleted file mode 100644 index 60ca2a76b..000000000 --- a/modules/core/shared/src/main/scala/scaladex/core/model/ReleaseDependency.scala +++ /dev/null @@ -1,13 +0,0 @@ -package scaladex.core.model - -import scaladex.core.model.ArtifactDependency.Scope - -case class ReleaseDependency( - source: Release, - target: Release, - scope: Scope -) -object ReleaseDependency { - case class Direct(targetRef: Project.Reference, targetVersion: SemanticVersion, scope: Scope) - case class Reverse(sourceRef: Project.Reference, targetVersion: SemanticVersion, scope: Scope) -} diff --git a/modules/core/shared/src/main/scala/scaladex/core/service/SchedulerDatabase.scala b/modules/core/shared/src/main/scala/scaladex/core/service/SchedulerDatabase.scala index 80d751b18..2dee10e16 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/service/SchedulerDatabase.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/service/SchedulerDatabase.scala @@ -9,7 +9,6 @@ import scaladex.core.model.Artifact.MavenReference import scaladex.core.model.ArtifactDependency import scaladex.core.model.Project import scaladex.core.model.ProjectDependency -import scaladex.core.model.ReleaseDependency import scaladex.core.model.SemanticVersion trait SchedulerDatabase extends WebDatabase { @@ -18,11 +17,9 @@ trait SchedulerDatabase extends WebDatabase { def updateProjectCreationDate(ref: Project.Reference, creationDate: Instant): Future[Unit] def computeAllProjectsCreationDates(): Future[Seq[(Instant, Project.Reference)]] - // project dependencies (and release dependencies) + // project dependencies def computeProjectDependencies(reference: Project.Reference, version: SemanticVersion): Future[Seq[ProjectDependency]] - def computeReleaseDependencies(): Future[Seq[ReleaseDependency]] def insertProjectDependencies(projectDependencies: Seq[ProjectDependency]): Future[Int] - def insertReleaseDependencies(projectDependencies: Seq[ReleaseDependency]): Future[Int] def deleteProjectDependencies(ref: Project.Reference): Future[Int] // artifacts and its dependencies diff --git a/modules/core/shared/src/test/scala/scaladex/core/test/InMemoryDatabase.scala b/modules/core/shared/src/test/scala/scaladex/core/test/InMemoryDatabase.scala index 375cec6ab..b0a4d4327 100644 --- a/modules/core/shared/src/test/scala/scaladex/core/test/InMemoryDatabase.scala +++ b/modules/core/shared/src/test/scala/scaladex/core/test/InMemoryDatabase.scala @@ -14,7 +14,6 @@ import scaladex.core.model.Language import scaladex.core.model.Platform import scaladex.core.model.Project import scaladex.core.model.ProjectDependency -import scaladex.core.model.ReleaseDependency import scaladex.core.model.SemanticVersion import scaladex.core.model.UserInfo import scaladex.core.model.UserState @@ -124,7 +123,6 @@ class InMemoryDatabase extends SchedulerDatabase { ref: Project.Reference, version: SemanticVersion ): Future[Seq[ProjectDependency]] = ??? - override def computeReleaseDependencies(): Future[Seq[ReleaseDependency]] = ??? override def computeAllProjectsCreationDates(): Future[Seq[(Instant, Project.Reference)]] = ??? @@ -133,8 +131,6 @@ class InMemoryDatabase extends SchedulerDatabase { override def insertProjectDependencies(projectDependencies: Seq[ProjectDependency]): Future[Int] = ??? - override def insertReleaseDependencies(releaseDependency: Seq[ReleaseDependency]): Future[Int] = ??? - override def countProjectDependents(ref: Project.Reference): Future[Long] = Future.successful(0) diff --git a/modules/infra/src/main/resources/migrations/V21__drop_release_and_release_dependencies.sql b/modules/infra/src/main/resources/migrations/V21__drop_release_and_release_dependencies.sql new file mode 100644 index 000000000..33c69a7e1 --- /dev/null +++ b/modules/infra/src/main/resources/migrations/V21__drop_release_and_release_dependencies.sql @@ -0,0 +1,2 @@ +DROP TABLE releases, release_dependencies; + diff --git a/modules/infra/src/main/scala/scaladex/infra/SqlDatabase.scala b/modules/infra/src/main/scala/scaladex/infra/SqlDatabase.scala index 24c8c5d9c..412625137 100644 --- a/modules/infra/src/main/scala/scaladex/infra/SqlDatabase.scala +++ b/modules/infra/src/main/scala/scaladex/infra/SqlDatabase.scala @@ -18,7 +18,6 @@ import scaladex.core.model.Language import scaladex.core.model.Platform import scaladex.core.model.Project import scaladex.core.model.ProjectDependency -import scaladex.core.model.ReleaseDependency import scaladex.core.model.SemanticVersion import scaladex.core.model.UserInfo import scaladex.core.model.UserState @@ -30,13 +29,14 @@ import scaladex.infra.sql.GithubInfoTable import scaladex.infra.sql.ProjectDependenciesTable import scaladex.infra.sql.ProjectSettingsTable import scaladex.infra.sql.ProjectTable -import scaladex.infra.sql.ReleaseDependenciesTable -import scaladex.infra.sql.ReleaseTable import scaladex.infra.sql.UserSessionsTable class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) extends SchedulerDatabase with LazyLogging { private val flyway = DoobieUtils.flyway(datasource) - def migrate: IO[Unit] = IO(flyway.migrate()) + def migrate: IO[Unit] = IO { + flyway.repair() + flyway.migrate() + } def dropTables: IO[Unit] = IO(flyway.clean()) override def insertArtifact( @@ -48,7 +48,6 @@ class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) exten for { isNewProject <- insertProjectRef(artifact.projectRef, unknownStatus) _ <- run(ArtifactTable.insertIfNotExist(artifact)) - _ <- run(ReleaseTable.insertIfNotExists.run(artifact.release)) _ <- insertDependencies(dependencies) } yield isNewProject } @@ -179,9 +178,6 @@ class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) exten ): Future[Seq[ProjectDependency]] = run(ArtifactDependencyTable.computeProjectDependencies.to[Seq]((ref, version))) - override def computeReleaseDependencies(): Future[Seq[ReleaseDependency]] = - run(ArtifactDependencyTable.computeReleaseDependency.to[Seq]) - override def insertProjectDependencies(projectDependencies: Seq[ProjectDependency]): Future[Int] = if (projectDependencies.isEmpty) Future.successful(0) else run(ProjectDependenciesTable.insertOrUpdate.updateMany(projectDependencies)) @@ -189,9 +185,6 @@ class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) exten override def deleteProjectDependencies(ref: Project.Reference): Future[Int] = run(ProjectDependenciesTable.deleteBySource.run(ref)) - override def insertReleaseDependencies(releaseDependency: Seq[ReleaseDependency]): Future[Int] = - run(ReleaseDependenciesTable.insertIfNotExists.updateMany(releaseDependency)) - override def countProjectDependents(projectRef: Project.Reference): Future[Long] = run(ProjectDependenciesTable.countDependents.unique(projectRef)) diff --git a/modules/infra/src/main/scala/scaladex/infra/migrations/V11_2__add_data_to_the_new_tables.scala b/modules/infra/src/main/scala/scaladex/infra/migrations/V11_2__add_data_to_the_new_tables.scala deleted file mode 100644 index a69c246cd..000000000 --- a/modules/infra/src/main/scala/scaladex/infra/migrations/V11_2__add_data_to_the_new_tables.scala +++ /dev/null @@ -1,24 +0,0 @@ -package scaladex.infra.migrations - -import com.typesafe.scalalogging.LazyLogging -import org.flywaydb.core.api.migration.BaseJavaMigration -import org.flywaydb.core.api.migration.Context -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}") - } - -} diff --git a/modules/infra/src/main/scala/scaladex/infra/sql/ArtifactDependencyTable.scala b/modules/infra/src/main/scala/scaladex/infra/sql/ArtifactDependencyTable.scala index 6ae2a5e7f..db4193de5 100644 --- a/modules/infra/src/main/scala/scaladex/infra/sql/ArtifactDependencyTable.scala +++ b/modules/infra/src/main/scala/scaladex/infra/sql/ArtifactDependencyTable.scala @@ -6,7 +6,6 @@ import scaladex.core.model.Artifact import scaladex.core.model.ArtifactDependency import scaladex.core.model.Project import scaladex.core.model.ProjectDependency -import scaladex.core.model.ReleaseDependency import scaladex.core.model.SemanticVersion import scaladex.infra.sql.DoobieUtils.Mappings._ import scaladex.infra.sql.DoobieUtils._ @@ -74,16 +73,6 @@ object ArtifactDependencyTable { Seq("d.organization", "d.repository", "d.version", "t.organization", "t.repository", "t.version", "d.scope") ).contramap { case (ref, version) => (ref, version, ref) } - val computeReleaseDependency: Query0[ReleaseDependency] = { - val sourceReleaseFields = ReleaseTable.primaryKeys.map("d." + _) - val targetReleaseFields = ReleaseTable.primaryKeys.map("t." + _) - selectRequest( - fullJoin, - sourceReleaseFields ++ Seq("MIN(d.release_date)") ++ targetReleaseFields ++ Seq("MIN(t.release_date)", "d.scope"), - groupBy = (sourceReleaseFields ++ targetReleaseFields) ++ Seq("d.scope") - ) - } - val selectDependencyFromProject: Query[Project.Reference, ArtifactDependency] = selectRequest( tableWithSourceArtifact, diff --git a/modules/infra/src/main/scala/scaladex/infra/sql/ArtifactTable.scala b/modules/infra/src/main/scala/scaladex/infra/sql/ArtifactTable.scala index f2bedfbce..1363d66db 100644 --- a/modules/infra/src/main/scala/scaladex/infra/sql/ArtifactTable.scala +++ b/modules/infra/src/main/scala/scaladex/infra/sql/ArtifactTable.scala @@ -8,7 +8,6 @@ import scaladex.core.model.Artifact import scaladex.core.model.Language import scaladex.core.model.Platform import scaladex.core.model.Project -import scaladex.core.model.Release import scaladex.core.model.SemanticVersion import scaladex.infra.sql.DoobieUtils.Mappings._ import scaladex.infra.sql.DoobieUtils._ @@ -115,13 +114,6 @@ object ArtifactTable { groupBy = projectReferenceFields ) - val getReleasesFromArtifacts: Query0[Release] = - selectRequest( - table, - Seq("organization", "repository", "platform", "language_version", "version", "MIN(release_date)"), - groupBy = Seq("organization", "repository ", "platform ", "language_version", "version") - ) - def selectLatestArtifacts(stableOnly: Boolean): Query[Project.Reference, Artifact] = selectRequest1(latestDateTable(stableOnly), fields.map(c => s"a.$c")) diff --git a/modules/infra/src/main/scala/scaladex/infra/sql/ReleaseDependenciesTable.scala b/modules/infra/src/main/scala/scaladex/infra/sql/ReleaseDependenciesTable.scala deleted file mode 100644 index c5e009123..000000000 --- a/modules/infra/src/main/scala/scaladex/infra/sql/ReleaseDependenciesTable.scala +++ /dev/null @@ -1,36 +0,0 @@ -package scaladex.infra.sql - -import doobie.util.update.Update -import scaladex.core.model.ReleaseDependency -import scaladex.infra.sql.DoobieUtils.Mappings._ -import scaladex.infra.sql.DoobieUtils.insertOrUpdateRequest - -object ReleaseDependenciesTable { - private val table: String = "release_dependencies" - private val sourcePrimaryKeys: Seq[String] = - Seq( - "source_organization", - "source_repository", - "source_platform", - "source_language_version", - "source_version" - ) - private val targetPrimaryKeys: Seq[String] = - Seq( - "target_organization", - "target_repository", - "target_platform", - "target_language_version", - "target_version" - ) - - val scope = "scope" - val sourceKeys: Seq[String] = sourcePrimaryKeys :+ "source_release_date" - val targetKeys: Seq[String] = targetPrimaryKeys :+ "target_release_date" - private val primaryKeys = (sourcePrimaryKeys ++ targetPrimaryKeys) :+ scope - - private val fields: Seq[String] = (sourceKeys ++ targetKeys) :+ scope - - val insertIfNotExists: Update[ReleaseDependency] = - insertOrUpdateRequest(table, fields, primaryKeys) -} diff --git a/modules/infra/src/main/scala/scaladex/infra/sql/ReleaseTable.scala b/modules/infra/src/main/scala/scaladex/infra/sql/ReleaseTable.scala deleted file mode 100644 index aebf5c9e8..000000000 --- a/modules/infra/src/main/scala/scaladex/infra/sql/ReleaseTable.scala +++ /dev/null @@ -1,23 +0,0 @@ -package scaladex.infra.sql -import doobie.util.update.Update -import scaladex.core.model.Release -import scaladex.infra.sql.DoobieUtils.Mappings._ -import scaladex.infra.sql.DoobieUtils.insertOrUpdateRequest - -object ReleaseTable { - private val table: String = "releases" - val primaryKeys: Seq[String] = - Seq( - "organization", - "repository", - "platform", - "language_version", - "version" - ) - private val fields: Seq[String] = - primaryKeys ++ Seq( - "release_date" - ) - val insertIfNotExists: Update[Release] = - insertOrUpdateRequest(table, fields, primaryKeys) -} diff --git a/modules/infra/src/test/scala/scaladex/infra/sql/ArtifactDependencyTableTests.scala b/modules/infra/src/test/scala/scaladex/infra/sql/ArtifactDependencyTableTests.scala index 051596714..00c261546 100644 --- a/modules/infra/src/test/scala/scaladex/infra/sql/ArtifactDependencyTableTests.scala +++ b/modules/infra/src/test/scala/scaladex/infra/sql/ArtifactDependencyTableTests.scala @@ -11,5 +11,4 @@ class ArtifactDependencyTableTests extends AnyFunSpec with BaseDatabaseSuite wit it("check selectDirectDependency")(check(ArtifactDependencyTable.selectDirectDependency)) it("check selectReverseDependency")(check(ArtifactDependencyTable.selectReverseDependency)) it("check computeProjectDependencies")(check(ArtifactDependencyTable.computeProjectDependencies)) - it("check computeReleaseDependency")(check(ArtifactDependencyTable.computeReleaseDependency)) } diff --git a/modules/infra/src/test/scala/scaladex/infra/sql/ArtifactTableTests.scala b/modules/infra/src/test/scala/scaladex/infra/sql/ArtifactTableTests.scala index 8d0af573b..440553416 100644 --- a/modules/infra/src/test/scala/scaladex/infra/sql/ArtifactTableTests.scala +++ b/modules/infra/src/test/scala/scaladex/infra/sql/ArtifactTableTests.scala @@ -25,7 +25,6 @@ class ArtifactTableTests extends AnyFunSpec with BaseDatabaseSuite with Matchers it("check selectMavenReference")(check(selectMavenReference)) it("check updateReleaseDate")(check(updateReleaseDate)) it("check selectByMavenReference")(check(selectByMavenReference)) - it("check getReleasesFromArtifacts")(check(getReleasesFromArtifacts)) it("check countVersionsByProject")(check(countVersionsByProject)) it("check selectArtifactByParams") { check(selectArtifactByParams(false)) diff --git a/modules/infra/src/test/scala/scaladex/infra/sql/ReleaseDependenciesTableTests.scala b/modules/infra/src/test/scala/scaladex/infra/sql/ReleaseDependenciesTableTests.scala deleted file mode 100644 index a57beb4b7..000000000 --- a/modules/infra/src/test/scala/scaladex/infra/sql/ReleaseDependenciesTableTests.scala +++ /dev/null @@ -1,9 +0,0 @@ -package scaladex.infra.sql - -import org.scalatest.funspec.AnyFunSpec -import org.scalatest.matchers.should.Matchers -import scaladex.infra.BaseDatabaseSuite - -class ReleaseDependenciesTableTests extends AnyFunSpec with BaseDatabaseSuite with Matchers { - it("check insertIfNotExists")(check(ReleaseDependenciesTable.insertIfNotExists)) -} diff --git a/modules/infra/src/test/scala/scaladex/infra/sql/ReleaseTableTests.scala b/modules/infra/src/test/scala/scaladex/infra/sql/ReleaseTableTests.scala deleted file mode 100644 index 3ef958076..000000000 --- a/modules/infra/src/test/scala/scaladex/infra/sql/ReleaseTableTests.scala +++ /dev/null @@ -1,9 +0,0 @@ -package scaladex.infra.sql - -import org.scalatest.funspec.AnyFunSpec -import org.scalatest.matchers.should.Matchers -import scaladex.infra.BaseDatabaseSuite - -class ReleaseTableTests extends AnyFunSpec with BaseDatabaseSuite with Matchers { - it("check insertIfNotExists")(check(ReleaseTable.insertIfNotExists)) -} diff --git a/modules/server/src/main/scala/scaladex/server/service/DependencyUpdater.scala b/modules/server/src/main/scala/scaladex/server/service/DependencyUpdater.scala index 253d35fdb..9f2a17ac2 100644 --- a/modules/server/src/main/scala/scaladex/server/service/DependencyUpdater.scala +++ b/modules/server/src/main/scala/scaladex/server/service/DependencyUpdater.scala @@ -15,7 +15,6 @@ class DependencyUpdater(database: SchedulerDatabase)(implicit ec: ExecutionConte def updateAll(): Future[String] = for { status <- updateProjectDependencyTable() - _ <- updateReleaseDependencyTable() } yield status def updateProjectDependencyTable(): Future[String] = @@ -50,29 +49,4 @@ class DependencyUpdater(database: SchedulerDatabase)(implicit ec: ExecutionConte logger.error(s"Failed to update dependencies of ${project.reference} of status ${project.githubStatus}", cause) } } - - def updateReleaseDependencyTable(): Future[Unit] = - for { - releaseDependencies <- database - .computeReleaseDependencies() - .mapFailure(e => - new Exception( - s"Failed to compute release dependencies because of ${e.getMessage}" - ) - ) - _ = logger.info(s"will try to insert ${releaseDependencies.size} releaseDependencies") - _ <- releaseDependencies - .grouped(10000) - .map(releaseDependencies => - database - .insertReleaseDependencies(releaseDependencies) - .mapFailure(e => - new Exception( - s"Failed to insert release dependencies because of ${e.getMessage}" - ) - ) - ) - .sequence - - } yield () }