Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into skingle-main
Browse files Browse the repository at this point in the history
  • Loading branch information
adpi2 committed Aug 19, 2024
2 parents 8b6982f + e5012df commit c4125c0
Show file tree
Hide file tree
Showing 20 changed files with 20 additions and 233 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ lazy val loggingSettings = Seq(
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.5"
),
// Drop and replace commons-logging with slf4j
libraryDependencies += "org.slf4j" % "jcl-over-slf4j" % "2.0.13",
libraryDependencies += "org.slf4j" % "jcl-over-slf4j" % "2.0.16",
excludeDependencies += ExclusionRule("commons-logging", "commons-logging")
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ case class Artifact(
s"$groupId$sep$artifactName"
}

def release: Release =
Release(projectRef.organization, projectRef.repository, platform, language, version, releaseDate)

def releaseDateFormat: String = Artifact.dateFormatter.format(releaseDate)

def httpUrl: String = {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,14 @@ import java.util.UUID
import scala.concurrent.Future

import scaladex.core.model._
import scaladex.core.web.ArtifactsPageParams

trait WebDatabase {
// artifacts
// insertArtifact return a boolean. It's true if a new project is inserted, false otherwise
def insertArtifact(artifact: Artifact, dependencies: Seq[ArtifactDependency], time: Instant): Future[Boolean]
def getArtifacts(groupId: Artifact.GroupId, artifactId: Artifact.ArtifactId): Future[Seq[Artifact]]
def getArtifacts(projectRef: Project.Reference): Future[Seq[Artifact]]
def getArtifacts(
ref: Project.Reference,
artifactName: Artifact.Name,
params: ArtifactsPageParams
): Future[Seq[Artifact]]
def getArtifacts(ref: Project.Reference, artifactName: Artifact.Name, preReleases: Boolean): Future[Seq[Artifact]]
def getArtifacts(ref: Project.Reference, artifactName: Artifact.Name, version: SemanticVersion): Future[Seq[Artifact]]
def getArtifactsByName(projectRef: Project.Reference, artifactName: Artifact.Name): Future[Seq[Artifact]]
def getLatestArtifacts(ref: Project.Reference, preferStableVersions: Boolean): Future[Seq[Artifact]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ 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
import scaladex.core.service.SchedulerDatabase
import scaladex.core.web.ArtifactsPageParams

class InMemoryDatabase extends SchedulerDatabase {
private val allProjects = mutable.Map[Project.Reference, Project]()
Expand Down Expand Up @@ -125,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)]] = ???

Expand All @@ -134,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)

Expand All @@ -161,9 +156,9 @@ class InMemoryDatabase extends SchedulerDatabase {
override def getArtifacts(
ref: Project.Reference,
artifactName: Artifact.Name,
params: ArtifactsPageParams
preReleases: Boolean
): Future[Seq[Artifact]] =
// does not filter with params
// TODO: use preReleases to filter
Future.successful(allArtifacts.getOrElse(ref, Seq.empty).filter(_.artifactName == artifactName))
override def getProjectDependencies(
ref: Project.Reference,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE releases, release_dependencies;

24 changes: 6 additions & 18 deletions modules/infra/src/main/scala/scaladex/infra/SqlDatabase.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,25 @@ 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
import scaladex.core.service.SchedulerDatabase
import scaladex.core.web.ArtifactsPageParams
import scaladex.infra.sql.ArtifactDependencyTable
import scaladex.infra.sql.ArtifactTable
import scaladex.infra.sql.DoobieUtils
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(
Expand All @@ -49,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
}
Expand Down Expand Up @@ -180,19 +178,13 @@ 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))

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))

Expand Down Expand Up @@ -235,13 +227,9 @@ class SqlDatabase(datasource: HikariDataSource, xa: doobie.Transactor[IO]) exten
override def getArtifacts(
ref: Project.Reference,
artifactName: Artifact.Name,
params: ArtifactsPageParams
preReleases: Boolean
): Future[Seq[Artifact]] =
run(
ArtifactTable
.selectArtifactByParams(params.binaryVersions, params.preReleases)
.to[Seq](ref, artifactName)
)
run(ArtifactTable.selectArtifactByParams(preReleases).to[Seq](ref, artifactName))

override def countVersions(ref: Project.Reference): Future[Long] =
run(ArtifactTable.countVersionsByProject.unique(ref))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import java.time.Instant
import doobie._
import doobie.util.update.Update
import scaladex.core.model.Artifact
import scaladex.core.model.BinaryVersion
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._
Expand Down Expand Up @@ -86,21 +84,12 @@ object ArtifactTable {
where = Seq("organization=?", "repository=?", "artifact_name=?", "version=?")
)

def selectArtifactByParams(
binaryVersions: Seq[BinaryVersion],
preReleases: Boolean
): Query[(Project.Reference, Artifact.Name), Artifact] = {
val binaryVersionFilter =
if (binaryVersions.isEmpty) "true"
else
binaryVersions
.map(bv => s"(platform='${bv.platform.label}' AND language_version='${bv.language.label}')")
.mkString("(", " OR ", ")")
val preReleaseFilter = if (preReleases) s"true" else "is_prerelease=false"
def selectArtifactByParams(preReleases: Boolean): Query[(Project.Reference, Artifact.Name), Artifact] = {
val preReleaseFilter = if (preReleases) "true" else "is_prerelease=false"
Query[(Project.Reference, Artifact.Name), Artifact](
s"""|SELECT ${fields.mkString(", ")}
|FROM $table WHERE
|organization=? AND repository=? AND artifact_name=? AND $binaryVersionFilter AND $preReleaseFilter
|FROM $table
|WHERE organization=? AND repository=? AND artifact_name=? AND $preReleaseFilter
|""".stripMargin
)
}
Expand Down Expand Up @@ -128,13 +117,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"))

Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions modules/infra/src/main/scala/scaladex/infra/sql/ReleaseTable.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Loading

0 comments on commit c4125c0

Please sign in to comment.