Skip to content

Commit

Permalink
Refactor Redshift migrations (close #173)
Browse files Browse the repository at this point in the history
  • Loading branch information
voropaevp authored and oguzhanunlu committed Jun 2, 2023
1 parent 870d668 commit 9582293
Show file tree
Hide file tree
Showing 66 changed files with 2,139 additions and 7,029 deletions.
17 changes: 0 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,3 @@ lazy val core = project.in(file("modules/core"))
Dependencies.Libraries.specs2Scalacheck,
Dependencies.Libraries.specs2Cats
))

lazy val json4s = project.in(file("modules/json4s"))
.settings(
name := "schema-ddl-json4s",
description := "Json4s-compatible entities for Schema DDL",
)
.settings(BuildSettings.basicSettigns)
.settings(BuildSettings.commonSettings)
.settings(BuildSettings.publishSettings)
.settings(libraryDependencies ++= Seq(
Dependencies.Libraries.igluCoreJson4s,
Dependencies.Libraries.specs2,
Dependencies.Libraries.scalaCheck,
Dependencies.Libraries.specs2Scalacheck,
Dependencies.Libraries.specs2Cats
))
.dependsOn(core)
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,19 @@
*/
package com.snowplowanalytics.iglu.schemaddl

// IgluCore
import com.snowplowanalytics.iglu.core.SchemaMap

/**
* Utilities for manipulating Strings
*/
object StringUtils {
/**
* Create a Redshift Table name from a schema
*
* "iglu:com.acme/PascalCase/jsonschema/13-0-0" -> "com_acme_pascal_case_13"
*
* @param schemaMap full Schema description
* @return the Redshift Table name
*/
def getTableName(schemaMap: SchemaMap): String = {
// Split the vendor's reversed domain name using underscores rather than dots
val snakeCaseOrganization = schemaMap
.schemaKey
.vendor
.replaceAll( """\.""", "_")
.replaceAll("-", "_")
.toLowerCase

// Change the name from PascalCase to snake_case if necessary
val snakeCaseName = snakeCase(schemaMap.schemaKey.name)

s"${snakeCaseOrganization}_${snakeCaseName}_${schemaMap.schemaKey.version.model}"
}

/**
* Transforms CamelCase string into snake_case
* Also replaces all hyphens with underscores
*/
val snakeCase: String => String = str =>
str.replaceAll("([A-Z]+)([A-Z][a-z])", "$1_$2")
.replaceAll("([a-z\\d])([A-Z])", "$1_$2")
.replaceAll("-", "_")
.toLowerCase

/**
* Checks if comma-delimited string contains only integers (including negative)
*
* @param string string with items delimited by comma
* @return true if string contains only integers
*/
def isIntegerList(string: String): Boolean = {
val elems = string.split(",").toList
if (elems.isEmpty) { false }
else {
elems.forall { s =>
s.headOption match {
case Some('-') if s.length > 1 => s.tail.forall(_.isDigit)
case _ => s.forall(_.isDigit) }
}
}
}

/**
* Utility object to match convertible strings
*/
object IntegerAsString {
def unapply(s : String) : Option[Int] = try {
Some(s.toInt)
} catch {
case _: java.lang.NumberFormatException => None
}
}
.replaceAll("([a-z\\d])([A-Z])", "$1_$2")
.replaceAll("-", "_")
.toLowerCase

}

This file was deleted.

Loading

0 comments on commit 9582293

Please sign in to comment.