{-# LANGUAGE OverloadedStrings  #-}
module Main where

import            Control.Exception
import            Control.Monad.Except
import            Data.Monoid
import qualified  Data.Text.Lazy        as T
import            System.Directory
import            System.Environment

import            HealthDB


main :: IO ()
main = do
  (path:_) <- getArgs
  copyFile path (path <> ".backup")
  bracket
    (runExceptT (migrateSqlite (T.pack path) Latest))
    (either (\_ -> return ()) finalizer)
    $ \db -> case db of
      Left err -> print err
      Right _ -> putStrLn "migration complete"
