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

Adding method to create empty database

parent da319f92
...@@ -2,6 +2,7 @@ package nl.lumc.sasc.biopet.tools ...@@ -2,6 +2,7 @@ package nl.lumc.sasc.biopet.tools
import java.io.File import java.io.File
import nl.lumc.sasc.biopet.utils.summary.db.Schema
import slick.driver.H2Driver.api._ import slick.driver.H2Driver.api._
import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.ExecutionContext.Implicits.global
...@@ -45,21 +46,8 @@ object SummaryToSqlite extends ToolCommand { ...@@ -45,21 +46,8 @@ object SummaryToSqlite extends ToolCommand {
} else throw new IllegalArgumentException(s"Db already exist: ${cmdArgs.outputSqlite}") } 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") logger.info("Done")
} }
......
package nl.lumc.sasc.biopet.utils.summary.db package nl.lumc.sasc.biopet.utils.summary.db
import java.io.File
import java.sql.Blob import java.sql.Blob
import nl.lumc.sasc.biopet.utils.Logging
import slick.driver.H2Driver.api._ import slick.driver.H2Driver.api._
import scala.concurrent.Await
import scala.concurrent.duration.Duration
/** /**
* Created by pjvan_thof on 27-1-17. * Created by pjvan_thof on 27-1-17.
*/ */
...@@ -131,4 +136,21 @@ object Schema { ...@@ -131,4 +136,21 @@ object Schema {
def idx = index("idx_executables", (runId, toolName), unique = true) def idx = index("idx_executables", (runId, toolName), unique = true)
} }
val executables = TableQuery[Executables] 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