packages feed

sqlite-easy 1.1.0.0 → 1.1.0.1

raw patch · 4 files changed

+70/−3 lines, 4 files

Files

changelog.md view
@@ -1,3 +1,7 @@+### 1.1.0.1++* Make migrations containing transactions work.+ ### 1.1.0.0  * Add `openWith` and `createSqlitePoolWith`.
sqlite-easy.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.4  name: sqlite-easy-version: 1.1.0.0+version: 1.1.0.1 synopsis: A primitive yet easy to use sqlite library. description: A primitive yet easy to use sqlite library built using sqlite-direct, resource-pool and migrant. author: Gil Mizrahi
src/Database/Sqlite/Easy/Migrant.hs view
@@ -24,8 +24,8 @@ migrate migrations migrateUp migrateDown = Sqlite.SQLite $ \(Sqlite.SQLiteStuff database _) ->   Migrant.migrate     migrations-    (\name db -> void . Sqlite.withDatabase db $ migrateUp name)-    (\name db -> void . Sqlite.withDatabase db $ migrateDown name)+    (\name db -> void $ (Sqlite.unSQLite $ migrateUp name) (Sqlite.SQLiteStuff db (Just 1)))+    (\name db -> void $ (Sqlite.unSQLite $ migrateDown name) (Sqlite.SQLiteStuff db (Just 1)))     database  instance Driver Direct.Database where
test/SqliteEasySpec.hs view
@@ -142,3 +142,66 @@         run $ "select * from " <> table <> " order by rowid"       destroyAllResources pool       shouldBe (readerResult, result) ([], [[SQLInteger 1], [SQLInteger 2]])++  describe "migrations" $ do+    it "create" $ do+      pool <- createSqlitePool ":memory:"+      withPool pool runMigrations+      result <- withPool pool $ do+        [] <- run "insert into post(title) values ('hello world')"+        run "select id, title from post"+      destroyAllResources pool+      shouldBe result [[SQLInteger 1, SQLText "hello world"]]++runMigrations :: SQLite ()+runMigrations = migrate migrations migrateUp migrateDown++migrations :: [MigrationName]+migrations =+  [ "post"+  , "add-date-column"+  ]++migrateUp :: MigrationName -> SQLite ()+migrateUp m = case m of+  "post" -> do+    [] <-+      run+        "create table post(id integer primary key autoincrement, title text not null) strict;"+    pure ()+  "add-date-column" -> do+    [] <- transaction $ do+        void $ run+          "create table post_without_date as select * from post;"+        void $ run+          "drop table post;"+        void $ run+          "create table post(id integer primary key autoincrement, title text not null, date text default current_date) strict;"+        void $ run+          "insert into post(title) select title from post_without_date;"+        run+          "drop table post_without_date;"+    pure ()+  unknown ->+    error ("Unexpected migration: " <> show unknown)++migrateDown :: MigrationName -> SQLite ()+migrateDown m = case m of+  "post" -> do+    [] <- run "DROP TABLE post"+    pure ()+  "add-date-column" -> do+    [] <- transaction $ do+        void $ run+          "create table post_with_date as select * from post;"+        void $ run+          "drop table post;"+        void $ run+          "create table post(id integer primary key autoincrement, title text not null) strict;"+        void $ run+          "insert into post(title) select title from post_with_date;"+        run+          "drop table post_with_date;"+    pure ()+  unknown ->+    error ("Unexpected migration: " <> show unknown)