Skip to content

Commit

Permalink
Fixed findAllMigrations not finding migrations without description. F…
Browse files Browse the repository at this point in the history
…ixes #556
  • Loading branch information
mpscholten committed Nov 18, 2020
1 parent 51fccee commit c41dfe5
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 2 deletions.
3 changes: 2 additions & 1 deletion IHP/SchemaMigration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import IHP.ModelSupport
import qualified Database.PostgreSQL.Simple.Types as PG
import qualified Data.Time.Clock.POSIX as POSIX
import qualified IHP.NameSupport as NameSupport
import qualified Data.Char as Char

data Migration = Migration
{ revision :: Int
Expand Down Expand Up @@ -104,7 +105,7 @@ pathToMigration fileName = case revision of
where
revision :: Maybe Int
revision = fileName
|> Text.split (== '-')
|> Text.split (not . Char.isDigit)
|> head
|> fmap textToInt
|> join
Expand Down
4 changes: 3 additions & 1 deletion Test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import qualified Test.HaskellSupportSpec
import qualified Test.View.CSSFrameworkSpec
import qualified Test.Controller.ContextSpec
import qualified Test.Controller.ParamSpec
import qualified Test.SchemaMigrationSpec

main :: IO ()
main = hspec do
Expand All @@ -44,4 +45,5 @@ main = hspec do
Test.HtmlSupport.ParserSpec.tests
Test.View.CSSFrameworkSpec.tests
Test.Controller.ContextSpec.tests
Test.Controller.ParamSpec.tests
Test.Controller.ParamSpec.tests
Test.SchemaMigrationSpec.tests
22 changes: 22 additions & 0 deletions Test/SchemaMigrationSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{-|
Module: Test.HaskellSupportSpec
Copyright: (c) digitally induced GmbH, 2020
-}
module Test.SchemaMigrationSpec where

import Test.Hspec
import IHP.Prelude
import IHP.SchemaMigration
import qualified System.Directory as Directory

tests = do
describe "IHP.SchemaMigration" do
describe "findAllMigrations" do
it "should find all migrations" do
Directory.withCurrentDirectory "Test/TestApp" do
migrations <- findAllMigrations

migrations `shouldBe`
[ Migration { revision = 1605721927, migrationFile = "1605721927.sql"}
, Migration { revision = 1605721940, migrationFile = "1605721940-create-users.sql" }
]
1 change: 1 addition & 0 deletions Test/TestApp/Application/Migration/1605721927.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE users (id SERIAL PRIMARY KEY);
1 change: 1 addition & 0 deletions Test/TestApp/Application/Migration/not_a_migration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
other file that is not a migration

0 comments on commit c41dfe5

Please sign in to comment.