Skip to content

Commit

Permalink
Upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
barryoneill committed Oct 10, 2024
1 parent 49820af commit a248617
Show file tree
Hide file tree
Showing 33 changed files with 245 additions and 294 deletions.
97 changes: 28 additions & 69 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,80 +1,39 @@
version=2.7.5
version = 3.8.3

maxColumn = 100
runner.dialect = scala213

align.tokens = [
{
code = "←"
owner = "Enumerator.Generator"
}, {
code = "%"
owner = "Term.ApplyInfix"
}, {
code = "{"
owner = Template
}, {
code = "⇒"
owner = Case
}, {
code = extends
owner = "Defn.(Class|Trait|Object)"
}, {
code = "→"
owner = "Term.ApplyInfix"
}, {
code = "="
owner = "(Enumerator.Val|Defn.(Va(l|r)|Def|Type))"
}, {
code = "<-"
owner = "Enumerator.Generator"
}, {
code = "//"
owner = ".*"
}, {
code = "->"
owner = "Term.ApplyInfix"
}, {
code = "%%"
owner = "Term.ApplyInfix"
}, {
code = "=>"
owner = Case
}, {
code = "}"
owner = Template
}, {
code = "%%%"
owner = "Term.ApplyInfix"
},
":=",
"+=",
"++=",
in,
shouldBe,
should,
be
align.preset = more # For pretty alignment.
maxColumn = 140 # For my wide 30" display.

project.excludePaths = ["glob:**/ProtocolBenchArr.scala"]

rewrite.sortModifiers.order = [
"override"
"private"
"protected"
"implicit"
"final"
"sealed"
"abstract"
"lazy"
]

align.openParenCallSite = false
align.openParenDefnSite = false
align.arrowEnumeratorGenerator = true
align.tokenCategory.Equals = Assign
align.tokenCategory.LeftArrow = Assign
rewrite.rules = [
SortModifiers
RedundantBraces
RedundantParens
AsciiSortImports
PreferCurlyFors
]

danglingParentheses = true
spaces.inByNameTypes = false

rewrite.rules = [SortImports, RedundantBraces, SortModifiers, PreferCurlyFors]
rewrite.redundantBraces.stringInterpolation = true
rewrite.redundantBraces.includeUnitMethods = true

spaces.inImportCurlyBraces = true
spaces.inByNameTypes = false

newlines.afterCurlyLambda = preserve
newlines.neverInResultType = true
newlines.beforeMultilineDef = keep
newlines.sometimesBeforeColonInMethodReturnType = false
newlines.penalizeSingleSelectMultiArgList = false
newlines.neverInResultType = true

verticalMultiline.atDefnSite = false
newlines.implicitParamListModifierPrefer = before

continuationIndent.defnSite = 2
newlines.implicitParamListModifierPrefer = before
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ case class BinaryLogs(fileName: String, size: Long)

object BinaryLogs {
def showLogs[F[_]](
implicit xa: Transactor[F],
ev: MonadCancel[F, Throwable]
implicit xa: Transactor[F],
ev: MonadCancel[F, Throwable]
): F[List[BinaryLogs]] =
sql"""show binary logs""".query[BinaryLogs].to[List].transact(xa)

def bytesBehindTheHead[F[_]: Transactor](fileName: String, pos: Long)(
implicit ev: MonadCancel[F, Throwable]
implicit ev: MonadCancel[F, Throwable]
): F[Long] =
showLogs[F].map { logs =>
logs.dropWhile(log => log.fileName != fileName).foldLeft(0L) { case (sum, l) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.laserdisc.mysql.binlog.models

import java.io.Serializable

import com.github.shyiko.mysql.binlog.event.{ DeleteRowsEventData => JDeleteRowsEventData }
import com.github.shyiko.mysql.binlog.event.{DeleteRowsEventData => JDeleteRowsEventData}

import scala.jdk.CollectionConverters._
object DeleteRowsEventData {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{ EventType, EventHeaderV4 => JEventHeaderV4 }
import com.github.shyiko.mysql.binlog.event.{EventHeaderV4 => JEventHeaderV4, EventType}

object EventHeaderV4 {
def unapply(arg: JEventHeaderV4): Option[(EventType, Long, Long)] =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{ QueryEventData => JQueryEventData }
import com.github.shyiko.mysql.binlog.event.{QueryEventData => JQueryEventData}

object QueryEventData {
def truncateTable(sql: String) = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{ RotateEventData => JRotateEventData }
import com.github.shyiko.mysql.binlog.event.{RotateEventData => JRotateEventData}
object RotateEventData {
def unapply(arg: JRotateEventData): Option[(String, Long)] =
Some((arg.getBinlogFilename, arg.getBinlogPosition))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import scala.collection.mutable
import cats.effect.MonadCancel

case class Metadata(
table_name: String,
column_name: String,
data_type: String,
character_set_name: Option[String],
ordinal_position: Int,
column_type: String,
datetime_precision: Option[Long],
column_key: String,
is_pk: Boolean
table_name: String,
column_name: String,
data_type: String,
character_set_name: Option[String],
ordinal_position: Int,
column_type: String,
datetime_precision: Option[Long],
column_key: String,
is_pk: Boolean
)

case class SchemaMetadata(
tables: Map[String, TableMetadata],
idToTable: mutable.Map[Long, TableMetadata]
tables: Map[String, TableMetadata],
idToTable: mutable.Map[Long, TableMetadata]
)

case class ColumnMetadata(name: String, dataType: String, ordinal: Int, isPk: Boolean)
Expand Down Expand Up @@ -49,7 +49,7 @@ object SchemaMetadata {
|ORDER BY TABLE_NAME, ORDINAL_POSITION""".stripMargin.query[Metadata]

def buildSchemaMetadata[F[_]](
schema: String
schema: String
)(implicit xa: Transactor[F], ev: MonadCancel[F, Throwable]): F[SchemaMetadata] =
getMetadata(schema).to[List].map(metaToSchema).transact(xa)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{ TableMapEventData => JTableMapEventData }
import com.github.shyiko.mysql.binlog.event.{TableMapEventData => JTableMapEventData}

object TableMapEventData {
def unapply(arg: JTableMapEventData): Option[(Long, String)] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package io.laserdisc.mysql.binlog.models

import java.io

import com.github.shyiko.mysql.binlog.event.{ UpdateRowsEventData => JUpdateRowsEventData }
import com.github.shyiko.mysql.binlog.event.{UpdateRowsEventData => JUpdateRowsEventData}

import scala.jdk.CollectionConverters._

object UpdateRowsEventData {
def unapply(
arg: JUpdateRowsEventData
arg: JUpdateRowsEventData
): Some[(Long, List[(Array[io.Serializable], Array[io.Serializable])], Array[Int])] = {
val beforeAfter =
arg.getRows.asScala.toList.map(entry => entry.getKey -> entry.getValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.laserdisc.mysql.binlog.models

import java.io.Serializable

import com.github.shyiko.mysql.binlog.event.{ WriteRowsEventData => JWriteRowsEventData }
import com.github.shyiko.mysql.binlog.event.{WriteRowsEventData => JWriteRowsEventData}

import scala.jdk.CollectionConverters._

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.laserdisc.mysql.binlog.models

import com.github.shyiko.mysql.binlog.event.{ XidEventData => JXidEventData }
import com.github.shyiko.mysql.binlog.event.{XidEventData => JXidEventData}

object XidEventData {
def unapply(arg: JXidEventData): Option[Long] = Some(arg.getXid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,44 @@ package io.laserdisc.mysql.binlog.models
import cats.effect.IO
import com.dimafeng.testcontainers.ForAllTestContainer
import db.MySqlContainer
import doobie.util.transactor.Transactor
import doobie.util.transactor.Transactor.Aux
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import cats.effect.unsafe.implicits.global
import doobie.util.transactor.Transactor

class SchemaMetadataTest
extends AnyWordSpec
with ForAllTestContainer
with MySqlContainer
with Matchers {
import java.util.Properties

class SchemaMetadataTest extends AnyWordSpec with ForAllTestContainer with MySqlContainer with Matchers {

"Schema Metadata" should {

"restore schema state from DB" in {
implicit val testTransactor: Aux[IO, Unit] =
Transactor.fromDriverManager[IO](
mySqlContainer.getDriverClassName,
s"${mySqlContainer.getJdbcUrl}?useSSL=false",
mySqlContainer.getUsername,
mySqlContainer.getPassword
Transactor.fromDriverManager(
driver = mySqlContainer.getDriverClassName,
url = s"${mySqlContainer.getJdbcUrl}?useSSL=false",
info = {
// ugh
val p = new Properties()
p.put("user", mySqlContainer.getUsername)
p.put("password", mySqlContainer.getPassword)
p
},
None
)
val schemaState =
SchemaMetadata.buildSchemaMetadata("test").unsafeRunSync()

schemaState.tables should have size 2
schemaState.tables should have size 2
schemaState.tables("sku").columns should have size 2
schemaState
.tables("sku")
.columns
.values
.filter(_.isPk)
.head
.name should be("id")
.name should be("id")
schemaState.tables("variant").columns should have size 2
schemaState
.tables("variant")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package io.laserdisc.mysql.binlog.checkpoint

import io.laserdisc.mysql.binlog.event.Offset

case class BinlogOffset(appName: String, override val fileName: String, override val offset: Long)
extends Offset
case class BinlogOffset(appName: String, override val fileName: String, override val offset: Long) extends Offset

object BinlogOffset {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import io.laserdisc.mysql.binlog.config.BinLogConfig
package object client {

def createBinLogClient[F[_]: Sync: Logger](
config: BinLogConfig,
offset: Option[BinlogOffset] = None
config: BinLogConfig,
offset: Option[BinlogOffset] = None
): F[BinaryLogClient] =
for {
client <- Sync[F].delay(config.mkBinaryLogClient(offset))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package object compaction {
case None => acc.remove(emId)
}
}
//TODO: use this code, once Scala 2.12 support ends, or updateWith back ported to 2.12A
// TODO: use this code, once Scala 2.12 support ends, or updateWith back ported to 2.12A
// acc.updateWith(evt.pk) {
// case Some(latest) =>
// mkNewEvent(evt).andThen(finalizeNewEvent).run(latest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ package object config {

val blc = new BinaryLogClient(v.host, v.port, v.user, v.password)

blc.setEventDeserializer({
blc.setEventDeserializer {
val ed = new EventDeserializer()
ed.setCompatibilityMode(
CompatibilityMode.DATE_AND_TIME_AS_LONG_MICRO,
CompatibilityMode.CHAR_AND_BINARY_AS_BYTE_ARRAY
)
ed
})
}

blc.setSSLMode(if (v.useSSL) SSLMode.VERIFY_IDENTITY else SSLMode.DISABLED)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import io.laserdisc.mysql.binlog.config.BinLogConfig

package object database {
def transactor[F[_]: Async](
config: BinLogConfig
config: BinLogConfig
): Resource[F, HikariTransactor[F]] =
for {
ce <- ExecutionContexts.fixedThreadPool[F](32) // our connect EC
_ <- Resource.eval(Sync[F].delay(Class.forName(config.driverClass)))
xa <- HikariTransactor.newHikariTransactor[F](
config.driverClass,
config.connectionURL,
config.user,
config.password,
ce
)
config.driverClass,
config.connectionURL,
config.user,
config.password,
ce
)
} yield xa

}
Loading

0 comments on commit a248617

Please sign in to comment.