Created
December 21, 2020 23:09
-
-
Save geryit/54d271d63dc776ab958c8f6d79fd9a33 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import utils.HardcodedDatabaseIds.carbonPracticeIds | |
import models._ | |
import DBDriver.api._ | |
import slick.dbio.Effect | |
import utils.Util._ | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.Await | |
import scala.concurrent.duration._ | |
import java.util._ | |
def exec[T](action: DBIOAction[T, models.DBDriver.api.NoStream, models.DB.Effects]): T = | |
Await.result(DB.run(action), 2.seconds) | |
def aw[T](v: Future[T]): T = Await.result(v, 2.seconds) | |
//def consoleLog(v: Any): Unit = println(v) | |
//def toUUID(v: String) = UUID.fromString(v) | |
//def mk[A](action: DBDriver.StreamingProfileAction[Seq[A], A, Effect.Read]) = action.statements.mkString | |
def timezoneForLocation(location: Location): Future[Option[String]] = | |
Future.successful(Option("America/New_Yorkkkk")) | |
//val locUUID = toUUID("cd9a8109-bb1d-4869-bfb7-4a9250aab10d"); | |
def updateSingleLocationTimezone(location: Location) = | |
for { | |
timezone <- timezoneForLocation(location) | |
updateResults <- | |
Locations.BASEQUERY | |
.filter(_.id === location.id.get) | |
.map(_.timezone) | |
.update(timezone) | |
.run(DB) | |
} yield updateResults | |
def updateLocationsWithTimezones() = | |
for { | |
locationsToFill <- | |
DB.run(Locations.BASEQUERY | |
.filter(_.timezone.isEmpty) | |
.filter(_.practiceId inSet carbonPracticeIds) | |
.result | |
) | |
result <- locationsToFill.mapSequential(updateSingleLocationTimezone) | |
} yield result | |
aw(updateLocationsWithTimezones()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment