Commit a5f4c0a0 authored by Peter van 't Hof's avatar Peter van 't Hof

Adding method to create empty database

parent da319f92
......@@ -2,6 +2,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.File
import nl.lumc.sasc.biopet.utils.summary.db.Schema
import slick.driver.H2Driver.api._
import scala.concurrent.ExecutionContext.Implicits.global
......@@ -45,21 +46,8 @@ object SummaryToSqlite extends ToolCommand {
} else throw new IllegalArgumentException(s"Db already exist: ${cmdArgs.outputSqlite}")
}
val db = Database.forURL(s"jdbc:sqlite:${cmdArgs.outputSqlite.getAbsolutePath}", driver = "org.sqlite.JDBC")
Schema.createEmptySqlite(cmdArgs.outputSqlite)
try {
import nl.lumc.sasc.biopet.utils.summary.db.Schema._
val setup = DBIO.seq(
(runs.schema ++ samples.schema ++
samplesRuns.schema ++ libraries.schema ++
librariesRuns.schema ++ pipelineNames.schema ++
moduleNames.schema ++ stats.schema ++ settings.schema ++
files.schema ++ executables.schema).create
)
val setupFuture = db.run(setup)
Await.result(setupFuture, Duration.Inf)
} finally db.close
logger.info("Done")
}
......
package nl.lumc.sasc.biopet.utils.summary.db
import java.io.File
import java.sql.Blob
import nl.lumc.sasc.biopet.utils.Logging
import slick.driver.H2Driver.api._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
/**
* Created by pjvan_thof on 27-1-17.
*/
......@@ -131,4 +136,21 @@ object Schema {
def idx = index("idx_executables", (runId, toolName), unique = true)
}
val executables = TableQuery[Executables]
def createEmptySqlite(file: File): Unit = {
val db = Database.forURL(s"jdbc:sqlite:${file.getAbsolutePath}", driver = "org.sqlite.JDBC")
try {
val setup = DBIO.seq(
(runs.schema ++ samples.schema ++
samplesRuns.schema ++ libraries.schema ++
librariesRuns.schema ++ pipelineNames.schema ++
moduleNames.schema ++ stats.schema ++ settings.schema ++
files.schema ++ executables.schema).create
)
val setupFuture = db.run(setup)
Await.result(setupFuture, Duration.Inf)
} finally db.close
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment