Skip to content

Commit

Permalink
Make addMigrationExtension parametric
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitalii Guzeev committed Sep 14, 2018
1 parent ae51c39 commit 5e82df8
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/Database/Schema/Migrations/Filesystem.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ filenameExtension = ".yml"
filenameExtensionTxt :: String
filenameExtensionTxt = ".txt"

supportedFilenameExtensions :: [String]
supportedFilenameExtensions = [filenameExtension, filenameExtensionTxt]

filesystemStore :: FilesystemStoreSettings -> MigrationStore
filesystemStore s =
MigrationStore { fullMigrationName = fmap addNewMigrationExtension . fsFullMigrationName s
Expand All @@ -75,15 +72,15 @@ filesystemStore s =
addNewMigrationExtension :: FilePath -> FilePath
addNewMigrationExtension path = path ++ filenameExtension

addLegacyMigrationExtension :: FilePath -> FilePath
addLegacyMigrationExtension path = path ++ filenameExtensionTxt
addMigrationExtension :: FilePath -> String -> FilePath
addMigrationExtension path ext = path ++ ext

-- |Build path to migrations without extension.
fsFullMigrationName :: FilesystemStoreSettings -> FilePath -> IO FilePath
fsFullMigrationName s name = return $ storePath s </> name

isMigrationFilename :: FilePath -> Bool
isMigrationFilename path = takeExtension path `elem` supportedFilenameExtensions
isMigrationFilename path = takeExtension path `elem` [filenameExtension, filenameExtensionTxt]

-- |Given a store and migration name, read and parse the associated
-- migration and return the migration if successful. Otherwise return
Expand All @@ -105,7 +102,7 @@ migrationFromPath path = do
ymlExists <- doesFileExist (addNewMigrationExtension path)
if ymlExists
then parseYamlFile (addNewMigrationExtension path) `catch` (\(e::IOException) -> throwFS $ show e)
else parseYamlFile (addLegacyMigrationExtension path) `catch` (\(e::IOException) -> throwFS $ show e)
else parseYamlFile (addMigrationExtension path filenameExtensionTxt) `catch` (\(e::IOException) -> throwFS $ show e)

process name = do
yaml <- readMigrationFile
Expand Down

0 comments on commit 5e82df8

Please sign in to comment.