Skip to content

Commit

Permalink
User can choose between creating symbolic link or copying migration file
Browse files Browse the repository at this point in the history
  • Loading branch information
softinio committed Aug 2, 2017
1 parent 8c4bcae commit d546118
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions core/src/main/scala/Commands.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ trait MigrationFilesHandler[T] {
toMove.toStream
}

def handleMigrationFile(file: File) {
def handleMigrationFile(file: File, cflag: Boolean) {
val target = new File(handledLoc + "/" + file.getName)
val source = new File(unhandledLoc + "/" + file.getName).getAbsoluteFile.toPath
if (!target.exists) {
println("create target to " + target.toPath + " for " + source)
Files.copy(source, target.toPath)
if (cflag) {
Files.copy(source, target.toPath)
} else {
Files.createSymbolicLink(target.toPath, source)
}
}
}

Expand Down Expand Up @@ -116,14 +120,15 @@ trait MigrationCommands[T, S] {

def migrateOp(options: Seq[String]) {
val prompt = options.contains("-p")
val cflag = options.contains("-c")
if (!notYetAppliedMigrations.isEmpty) {
for (op <- previewOps) op()
if (prompt) {
if (StdIn.readLine("Do you wish to continue? [Y/N]") != "Y") return
}
for (op <- applyOps) op()
}
updateOp
updateOp(cflag)
}
def migrateCommand(options: Seq[String]) {
migrateOp(options)
Expand All @@ -143,18 +148,19 @@ trait MigrationCommands[T, S] {
resetOp
}

def updateOp {
def updateOp(cflag: Boolean = false) {
val files = migrationFiles(alreadyAppliedIds)
if (!files.isEmpty) {
for (file <- files) {
handleMigrationFile(file)
handleMigrationFile(file, cflag)
}
// only write summary if files are moved
writeSummary(summary)
}
}
def updateCommand {
updateOp
def updateCommand(options: Seq[String]) {
val cflag = options.contains("-c")
updateOp(cflag)
}
}

Expand All @@ -170,12 +176,12 @@ trait RescueCommandLineTool[T] { this: RescueCommands[T] =>
trait MigrationCommandLineTool[T, S] { this: MigrationCommands[T, S] =>

def execCommands(args: List[String]) = args match {
case "status" :: Nil => statusCommand
case "preview" :: Nil => previewCommand
case "apply" :: Nil => applyCommand
case "init" :: Nil => initCommand
case "reset" :: Nil => resetCommand
case "update" :: Nil => updateCommand
case "status" :: Nil => statusCommand
case "preview" :: Nil => previewCommand
case "apply" :: Nil => applyCommand
case "init" :: Nil => initCommand
case "reset" :: Nil => resetCommand
case "update" :: (options: Seq[String]) => updateCommand
case "migrate" :: (options: Seq[String]) =>
migrateCommand(options)
case _ => println(helpOutput)
Expand Down

0 comments on commit d546118

Please sign in to comment.