Update scalafmt to 2.5.1 + scalafmtAll

This commit is contained in:
Eike Kettner
2020-05-04 23:52:53 +02:00
parent 169510aec1
commit c41cdeefec
65 changed files with 523 additions and 431 deletions

View File

@ -22,10 +22,11 @@ case class Column(name: String, ns: String = "", alias: String = "") {
def is[A: Put](value: A): Fragment =
f ++ fr" = $value"
def is[A: Put](ov: Option[A]): Fragment = ov match {
case Some(v) => f ++ fr" = $v"
case None => fr"is null"
}
def is[A: Put](ov: Option[A]): Fragment =
ov match {
case Some(v) => f ++ fr" = $v"
case None => fr"is null"
}
def is(c: Column): Fragment =
f ++ fr"=" ++ c.f

View File

@ -8,28 +8,29 @@ import org.log4s._
object FlywayMigrate {
private[this] val logger = getLogger
def run[F[_]: Sync](jdbc: JdbcConfig): F[Int] = Sync[F].delay {
logger.info("Running db migrations...")
val locations = jdbc.dbmsName match {
case Some(dbtype) =>
val name = if (dbtype == "h2") "postgresql" else dbtype
List(s"classpath:db/migration/${name}")
case None =>
logger.warn(
s"Cannot read database name from jdbc url: ${jdbc.url}. Go with PostgreSQL"
)
List("classpath:db/postgresql")
def run[F[_]: Sync](jdbc: JdbcConfig): F[Int] =
Sync[F].delay {
logger.info("Running db migrations...")
val locations = jdbc.dbmsName match {
case Some(dbtype) =>
val name = if (dbtype == "h2") "postgresql" else dbtype
List(s"classpath:db/migration/${name}")
case None =>
logger.warn(
s"Cannot read database name from jdbc url: ${jdbc.url}. Go with PostgreSQL"
)
List("classpath:db/postgresql")
}
logger.info(s"Using migration locations: $locations")
val fw = Flyway
.configure()
.cleanDisabled(true)
.dataSource(jdbc.url.asString, jdbc.user, jdbc.password)
.locations(locations: _*)
.load()
fw.repair()
fw.migrate()
}
logger.info(s"Using migration locations: $locations")
val fw = Flyway
.configure()
.cleanDisabled(true)
.dataSource(jdbc.url.asString, jdbc.user, jdbc.password)
.locations(locations: _*)
.load()
fw.repair()
fw.migrate()
}
}

View File

@ -30,16 +30,18 @@ object QAttachment {
for {
files <- store.transact(loadFiles)
k <- if (files._3 == 1) deleteArchive(store)(attachId)
else store.transact(RAttachmentArchive.delete(attachId))
k <-
if (files._3 == 1) deleteArchive(store)(attachId)
else store.transact(RAttachmentArchive.delete(attachId))
n <- store.transact(RAttachment.delete(attachId))
f <- Stream
.emits(files._1.toSeq ++ files._2.toSeq)
.map(_.id)
.flatMap(store.bitpeace.delete)
.map(flag => if (flag) 1 else 0)
.compile
.foldMonoid
f <-
Stream
.emits(files._1.toSeq ++ files._2.toSeq)
.map(_.id)
.flatMap(store.bitpeace.delete)
.map(flag => if (flag) 1 else 0)
.compile
.foldMonoid
} yield n + k + f
}
@ -55,12 +57,13 @@ object QAttachment {
_ <- logger.fdebug[F](
s"Deleted $n meta records (source, meta, archive). Deleting binaries now."
)
f <- Stream
.emits(ra.fileId.id +: (s.map(_.fileId.id).toSeq))
.flatMap(store.bitpeace.delete)
.map(flag => if (flag) 1 else 0)
.compile
.foldMonoid
f <-
Stream
.emits(ra.fileId.id +: (s.map(_.fileId.id).toSeq))
.flatMap(store.bitpeace.delete)
.map(flag => if (flag) 1 else 0)
.compile
.foldMonoid
} yield n + f
def deleteArchive[F[_]: Sync](store: Store[F])(attachId: Ident): F[Int] =
@ -119,7 +122,9 @@ object QAttachment {
val IC = RItem.Columns
val q =
fr"SELECT" ++ commas(MC.all.map(_.prefix("m").f)) ++ fr"FROM" ++ RItem.table ++ fr"i" ++
fr"SELECT" ++ commas(
MC.all.map(_.prefix("m").f)
) ++ fr"FROM" ++ RItem.table ++ fr"i" ++
fr"INNER JOIN" ++ RAttachment.table ++ fr"a ON" ++ IC.id
.prefix("i")
.is(AC.itemId.prefix("a")) ++

View File

@ -96,7 +96,9 @@ object QCollective {
RC.Columns.all,
RC.table,
and(
Seq(or(RC.Columns.orgId.isIn(orgCond), RC.Columns.personId.isIn(persCond))) ++ queryCond ++ kindCond
Seq(
or(RC.Columns.orgId.isIn(orgCond), RC.Columns.personId.isIn(persCond))
) ++ queryCond ++ kindCond
)
) ++ orderBy(RC.Columns.value.f)

View File

@ -291,7 +291,9 @@ object QItem {
val IC = RItem.Columns
val AC = RAttachment.Columns
val q =
fr"SELECT DISTINCT" ++ commas(IC.all.map(_.prefix("i").f)) ++ fr"FROM" ++ RItem.table ++ fr"i" ++
fr"SELECT DISTINCT" ++ commas(
IC.all.map(_.prefix("i").f)
) ++ fr"FROM" ++ RItem.table ++ fr"i" ++
fr"INNER JOIN" ++ RAttachment.table ++ fr"a ON" ++ AC.itemId
.prefix("a")
.is(IC.id.prefix("i")) ++

View File

@ -55,8 +55,9 @@ object QJob {
def markJob(job: RJob): F[Either[Unit, RJob]] =
store.transact(for {
n <- RJob.setScheduled(job.id, worker)
_ <- if (n == 1) RJobGroupUse.setGroup(RJobGroupUse(worker, job.group))
else 0.pure[ConnectionIO]
_ <-
if (n == 1) RJobGroupUse.setGroup(RJobGroupUse(worker, job.group))
else 0.pure[ConnectionIO]
} yield if (n == 1) Right(job) else Left(()))
for {
@ -68,9 +69,10 @@ object QJob {
_ <- logger.ftrace[F](s"Choose group ${group.map(_.id)}")
prio <- group.map(priority).getOrElse((Priority.Low: Priority).pure[F])
_ <- logger.ftrace[F](s"Looking for job of prio $prio")
job <- group
.map(g => store.transact(selectNextJob(g, prio, retryPause, now)))
.getOrElse((None: Option[RJob]).pure[F])
job <-
group
.map(g => store.transact(selectNextJob(g, prio, retryPause, now)))
.getOrElse((None: Option[RJob]).pure[F])
_ <- logger.ftrace[F](s"Found job: ${job.map(_.info)}")
res <- job.traverse(j => markJob(j))
} yield res.map(_.map(_.some)).getOrElse {

View File

@ -81,12 +81,13 @@ object PeriodicTaskStore {
def unmark(job: RPeriodicTask): F[Unit] =
for {
now <- Timestamp.current[F]
nextRun <- CalevFs2
.nextElapses[F](now.atUTC)(job.timer)
.take(1)
.compile
.last
.map(_.map(Timestamp.from))
nextRun <-
CalevFs2
.nextElapses[F](now.atUTC)(job.timer)
.take(1)
.compile
.last
.map(_.map(Timestamp.from))
_ <- store.transact(QPeriodicTask.unsetWorker(job.id, nextRun))
} yield ()

View File

@ -43,7 +43,11 @@ object RAttachment {
fId: Ident,
fname: Option[String]
): ConnectionIO[Int] =
updateRow(table, id.is(attachId), commas(fileId.setTo(fId), name.setTo(fname))).update.run
updateRow(
table,
id.is(attachId),
commas(fileId.setTo(fId), name.setTo(fname))
).update.run
def updatePosition(attachId: Ident, pos: Int): ConnectionIO[Int] =
updateRow(table, id.is(attachId), position.setTo(pos)).update.run

View File

@ -38,7 +38,11 @@ object RAttachmentArchive {
RAttachmentArchive(ra.id, ra.fileId, ra.name, mId, ra.created)
def insert(v: RAttachmentArchive): ConnectionIO[Int] =
insertRow(table, all, fr"${v.id},${v.fileId},${v.name},${v.messageId},${v.created}").update.run
insertRow(
table,
all,
fr"${v.id},${v.fileId},${v.name},${v.messageId},${v.created}"
).update.run
def findById(attachId: Ident): ConnectionIO[Option[RAttachmentArchive]] =
selectSimple(all, table, id.is(attachId)).query[RAttachmentArchive].option

View File

@ -35,7 +35,11 @@ object RAttachmentMeta {
import Columns._
def insert(v: RAttachmentMeta): ConnectionIO[Int] =
insertRow(table, all, fr"${v.id},${v.content},${v.nerlabels},${v.proposals}").update.run
insertRow(
table,
all,
fr"${v.id},${v.content},${v.nerlabels},${v.proposals}"
).update.run
def exists(attachId: Ident): ConnectionIO[Boolean] =
selectCount(id, table, id.is(attachId)).query[Int].unique.map(_ > 0)

View File

@ -29,7 +29,11 @@ object RJobLog {
import Columns._
def insert(v: RJobLog): ConnectionIO[Int] =
insertRow(table, all, fr"${v.id},${v.jobId},${v.level},${v.created},${v.message}").update.run
insertRow(
table,
all,
fr"${v.id},${v.jobId},${v.level},${v.created},${v.message}"
).update.run
def findLogs(id: Ident): ConnectionIO[Vector[RJobLog]] =
(selectSimple(all, table, jobId.is(id)) ++ orderBy(created.asc))

View File

@ -34,7 +34,11 @@ object RNode {
import Columns._
def insert(v: RNode): ConnectionIO[Int] =
insertRow(table, all, fr"${v.id},${v.nodeType},${v.url},${v.updated},${v.created}").update.run
insertRow(
table,
all,
fr"${v.id},${v.nodeType},${v.url},${v.updated},${v.created}"
).update.run
def update(v: RNode): ConnectionIO[Int] =
updateRow(

View File

@ -38,8 +38,8 @@ trait UserTaskStore[F[_]] {
/** Return all tasks of the given name and user. The task's arguments
* are decoded using the given json decoder.
*/
def getByName[A](account: AccountId, name: Ident)(
implicit D: Decoder[A]
def getByName[A](account: AccountId, name: Ident)(implicit
D: Decoder[A]
): Stream[F, UserTask[A]]
/** Updates or inserts the given task.
@ -65,8 +65,8 @@ trait UserTaskStore[F[_]] {
* error is returned. The task's arguments are decoded using the
* given json decoder.
*/
def getOneByName[A](account: AccountId, name: Ident)(
implicit D: Decoder[A]
def getOneByName[A](account: AccountId, name: Ident)(implicit
D: Decoder[A]
): OptionT[F, UserTask[A]]
/** Updates or inserts the given task.
@ -80,8 +80,8 @@ trait UserTaskStore[F[_]] {
* the user `account`, they will all be removed and the given task
* inserted!
*/
def updateOneTask[A](account: AccountId, ut: UserTask[A])(
implicit E: Encoder[A]
def updateOneTask[A](account: AccountId, ut: UserTask[A])(implicit
E: Encoder[A]
): F[UserTask[String]]
/** Delete all tasks of the given user that have name `name'.
@ -100,16 +100,16 @@ object UserTaskStore {
def getByNameRaw(account: AccountId, name: Ident): Stream[F, UserTask[String]] =
store.transact(QUserTask.findByName(account, name))
def getByName[A](account: AccountId, name: Ident)(
implicit D: Decoder[A]
def getByName[A](account: AccountId, name: Ident)(implicit
D: Decoder[A]
): Stream[F, UserTask[A]] =
getByNameRaw(account, name).flatMap(_.decode match {
case Right(ua) => Stream.emit(ua)
case Left(err) => Stream.raiseError[F](new Exception(err))
})
def updateTask[A](account: AccountId, ut: UserTask[A])(
implicit E: Encoder[A]
def updateTask[A](account: AccountId, ut: UserTask[A])(implicit
E: Encoder[A]
): F[Int] = {
val exists = QUserTask.exists(ut.id)
val insert = QUserTask.insert(account, ut.encode)
@ -142,8 +142,8 @@ object UserTaskStore {
}
)
def getOneByName[A](account: AccountId, name: Ident)(
implicit D: Decoder[A]
def getOneByName[A](account: AccountId, name: Ident)(implicit
D: Decoder[A]
): OptionT[F, UserTask[A]] =
getOneByNameRaw(account, name)
.semiflatMap(_.decode match {
@ -151,8 +151,8 @@ object UserTaskStore {
case Left(err) => Effect[F].raiseError(new Exception(err))
})
def updateOneTask[A](account: AccountId, ut: UserTask[A])(
implicit E: Encoder[A]
def updateOneTask[A](account: AccountId, ut: UserTask[A])(implicit
E: Encoder[A]
): F[UserTask[String]] =
getByNameRaw(account, ut.name).compile.toList.flatMap {
case a :: rest =>