All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.chrisomeara.pillar.AppliedMigrations.scala Maven / Gradle / Ivy

There is a newer version: 2.3.0
Show newest version
package com.chrisomeara.pillar

import com.datastax.driver.core.Session
import com.datastax.driver.core.querybuilder.QueryBuilder
import scala.collection.JavaConversions
import java.util.Date

object AppliedMigrations {
  def apply(session: Session, registry: Registry): AppliedMigrations = {
    val results = session.execute(QueryBuilder.select("authored_at", "description").from("applied_migrations"))
    new AppliedMigrations(JavaConversions.asScalaBuffer(results.all()).map {
      row => registry(MigrationKey(row.getTimestamp("authored_at"), row.getString("description")))
    })
  }
}

class AppliedMigrations(applied: Seq[Migration]) {
  def length: Int = applied.length

  def apply(index: Int): Migration = applied.apply(index)

  def iterator: Iterator[Migration] = applied.iterator

  def authoredAfter(date: Date): Seq[Migration] = applied.filter(migration => migration.authoredAfter(date))

  def contains(other: Migration): Boolean = applied.contains(other)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy