mirror of
https://github.com/ysoftdevs/odc-analyzer.git
synced 2026-01-19 01:57:25 +01:00
Added support for changelog
This commit is contained in:
38
app/models/Change.scala
Normal file
38
app/models/Change.scala
Normal file
@@ -0,0 +1,38 @@
|
||||
package models
|
||||
|
||||
import java.time.LocalTime
|
||||
|
||||
import models.profile.MappedJdbcType
|
||||
import models.profile.api._
|
||||
import models.jodaSupport._
|
||||
import models.profile.api._
|
||||
import org.joda.time.{DateTime, LocalDate}
|
||||
import play.api.data.Form
|
||||
import slick.lifted.{ProvenShape, Tag}
|
||||
|
||||
|
||||
object Change {
|
||||
abstract sealed class Direction private[Change] (private[Change] val description: String)
|
||||
object Direction{
|
||||
object Added extends Direction("added")
|
||||
object Removed extends Direction("removed")
|
||||
val All = Set(Added, Removed)
|
||||
val ByName = All.map(x => x.description -> x).toMap
|
||||
implicit val TypeMapper = MappedJdbcType.base[Direction, String](_.description, ByName)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
case class Change (time: DateTime, vulnerabilityName: String, projectName: String, direction: Change.Direction)
|
||||
|
||||
class Changes(tag: Tag) extends Table[(Int, Change)](tag, "change"){
|
||||
def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
|
||||
import Change.Direction.TypeMapper
|
||||
def time = column[DateTime]("time")
|
||||
def vulnerabilityName = column[String]("vulnerability_name")
|
||||
def projectName = column[String]("project_name")
|
||||
def direction = column[Change.Direction]("direction")
|
||||
|
||||
def base = (time, vulnerabilityName, projectName, direction) <> ((Change.apply _).tupled, Change.unapply)
|
||||
override def * = (id, base)
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
import java.nio.file.{Paths, Files}
|
||||
|
||||
import slick.lifted.MappedProjection
|
||||
|
||||
import scala.language.reflectiveCalls
|
||||
|
||||
package object models {
|
||||
@@ -18,6 +20,7 @@ package object models {
|
||||
val snoozesTable = TableQuery[Snoozes]
|
||||
val authTokens = TableQuery[CookieAuthenticators]
|
||||
val vulnerabilitySubscriptions = TableQuery[VulnerabilitySubscriptions]
|
||||
val changelog = TableQuery[Changes]
|
||||
|
||||
val issueTrackerExportTables = new ExportPlatformTables[String, (String, String, Int)](){
|
||||
val tableNamePart = "issue_tracker"
|
||||
@@ -44,10 +47,24 @@ package object models {
|
||||
override val tickets = TableQuery[EmailExportedVulnerabilities]
|
||||
}
|
||||
|
||||
val diffDbExportTables = new ExportPlatformTables[String, (String, Int)] {
|
||||
val tableNamePart = "diff_db"
|
||||
class DiffDbVulnerabilities(tag: Tag) extends ExportedVulnerabilities[String, (String, Int)](tag, tableNamePart){
|
||||
override def base: MappedProjection[ExportedVulnerability[String], (String, Int)] = (vulnerabilityName, ticketFormatVersion) <> (
|
||||
((n: String, v: Int) => ExportedVulnerability[String](n, n, v)).tupled,
|
||||
obj => ExportedVulnerability.unapply[String](obj).map{case (n, _, v) => (n, v)}
|
||||
)
|
||||
}
|
||||
class DiffDbVulnerabilityProject(tag: Tag) extends ExportedVulnerabilityProjects(tag, tableNamePart)
|
||||
|
||||
override val projects = TableQuery[DiffDbVulnerabilityProject]
|
||||
override val tickets = TableQuery[DiffDbVulnerabilities]
|
||||
}
|
||||
|
||||
/*{
|
||||
import profile.SchemaDescription
|
||||
val schema = Seq[Any{def schema: SchemaDescription}](
|
||||
vulnerabilitySubscriptions, issueTrackerExportTables, mailExportTables
|
||||
diffDbExportTables, changelog
|
||||
).map(_.schema).foldLeft(profile.DDL(Seq(), Seq()))(_ ++ _)
|
||||
|
||||
val sql = Seq(
|
||||
@@ -58,7 +75,7 @@ package object models {
|
||||
schema.dropStatements.toSeq.map(_+";").mkString("\n").dropWhile(_ == "\n"),
|
||||
"\n"
|
||||
).mkString("\n")
|
||||
Files.write(Paths.get("conf/evolutions/default/6.sql"), sql.getBytes("utf-8"))
|
||||
Files.write(Paths.get("conf/evolutions/default/7.sql"), sql.getBytes("utf-8"))
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user