Skip to content

Instantly share code, notes, and snippets.

@penguinbroker
Last active August 29, 2015 14:18
Show Gist options
  • Save penguinbroker/bc4493e7e6def45da291 to your computer and use it in GitHub Desktop.
Save penguinbroker/bc4493e7e6def45da291 to your computer and use it in GitHub Desktop.
clean slide uris
package migrations
import global.{ComponentRegistry, DaoRegistry}
import com.amazonaws.services.dynamodbv2.model.AttributeValue
import java.net.URI
import scala.concurrent.Await
import scala.concurrent.duration._
object SlideUriMigration extends DatabaseMigration with DaoRegistry {
val TableName = "slide"
private val embedlyUrlCol = "embedlyUrl"
def execute =
modifyRows(TableName)(cleanUris)
private def cleanUris(attributes: Map[String, AttributeValue]): Map[String, AttributeValue] = {
val uri = attributes.get(embedlyUrlCol).map(_.getS)
uri map { u =>
try {
val url = new URI(u)
attributes
} catch {
case e: Exception => attributes - embedlyUrlCol
}
} getOrElse attributes
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment