From 23875bad0b28ee73fdf99941c05d8af8c89022f2 Mon Sep 17 00:00:00 2001 From: Rodney Lorrimar Date: Fri, 25 Oct 2019 19:46:40 +1000 Subject: [PATCH] Sqlite: Fix DB migrations on Windows The wallet failed with: NUL: openFile: does not exist (No such file or directory) This is due to runMigrationSilent which uses the silently library: http://hackage.haskell.org/package/silently-1.2.5.1/docs/src/System.IO.Silently.html#line-27 To fix, we swap runMigrationSilent with runMigrationQuiet (added in persistent-2.10.2). --- lib/core/src/Cardano/DB/Sqlite.hs | 4 +- nix/.stack.nix/default.nix | 4 +- nix/.stack.nix/persistent-sqlite.nix | 4 +- nix/.stack.nix/persistent-template.nix | 115 ++++++++++++++++++++++++ nix/.stack.nix/persistent.nix | 118 +++++++++++++++++++++++++ stack.yaml | 10 +-- 6 files changed, 244 insertions(+), 11 deletions(-) create mode 100644 nix/.stack.nix/persistent-template.nix create mode 100644 nix/.stack.nix/persistent.nix diff --git a/lib/core/src/Cardano/DB/Sqlite.hs b/lib/core/src/Cardano/DB/Sqlite.hs index 61cfb51d735..b17fee96f9b 100644 --- a/lib/core/src/Cardano/DB/Sqlite.hs +++ b/lib/core/src/Cardano/DB/Sqlite.hs @@ -62,7 +62,7 @@ import Data.Maybe import Data.Text ( Text ) import Database.Persist.Sql - ( LogFunc, Migration, close', runMigrationSilent, runSqlConn ) + ( LogFunc, Migration, close', runMigrationQuiet, runSqlConn ) import Database.Persist.Sqlite ( SqlBackend, SqlPersistT, mkSqliteConnectionInfo, wrapConnectionInfo ) import Database.Sqlite @@ -152,7 +152,7 @@ startSqliteBackend logConfig migrateAll trace fp = do observe = bracketObserveIO logConfig traceQuery Debug "query" let runQuery :: SqlPersistT IO a -> IO a runQuery cmd = withMVar lock $ const $ observe $ runSqlConn cmd backend - migrations <- runQuery $ runMigrationSilent migrateAll + migrations <- runQuery $ runMigrationQuiet migrateAll dbLog trace $ MsgMigrations (length migrations) pure $ SqliteContext backend runQuery fp trace diff --git a/nix/.stack.nix/default.nix b/nix/.stack.nix/default.nix index bfe4806cde1..11fcdf89357 100644 --- a/nix/.stack.nix/default.nix +++ b/nix/.stack.nix/default.nix @@ -5,8 +5,6 @@ "base58-bytestring" = (((hackage.base58-bytestring)."0.1.0").revisions).default; "quickcheck-state-machine" = (((hackage.quickcheck-state-machine)."0.6.0").revisions).default; "command" = (((hackage.command)."0.1.1").revisions).default; - "persistent-template" = (((hackage.persistent-template)."2.7.2").revisions).default; - "persistent" = (((hackage.persistent)."2.10.1").revisions).default; "time-units" = (((hackage.time-units)."1.0.0").revisions).default; "libsystemd-journal" = (((hackage.libsystemd-journal)."1.4.4").revisions).default; bech32 = ./bech32.nix; @@ -17,7 +15,9 @@ text-class = ./text-class.nix; cardano-wallet-test-utils = ./cardano-wallet-test-utils.nix; cardano-wallet-jormungandr = ./cardano-wallet-jormungandr.nix; + persistent = ./persistent.nix; persistent-sqlite = ./persistent-sqlite.nix; + persistent-template = ./persistent-template.nix; cardano-crypto = ./cardano-crypto.nix; contra-tracer = ./contra-tracer.nix; iohk-monitoring = ./iohk-monitoring.nix; diff --git a/nix/.stack.nix/persistent-sqlite.nix b/nix/.stack.nix/persistent-sqlite.nix index 49a0faf118a..79209c1240f 100644 --- a/nix/.stack.nix/persistent-sqlite.nix +++ b/nix/.stack.nix/persistent-sqlite.nix @@ -130,8 +130,8 @@ in { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }: } // { src = (pkgs.lib).mkDefault (pkgs.fetchgit { url = "https://github.com/input-output-hk/persistent"; - rev = "79f2ece07eafae005a703c8eda1bd2420b5e07b5"; - sha256 = "081bhdg52wn7vgxsgl4aimy73ccai05j64r24hwkdnjj4kz96lia"; + rev = "107787ecc4c8a112375493cd66574f788f950fce"; + sha256 = "1livmfslqzadir5sc523r111wrd14s5k2nmvsxayk45hx3nnngfb"; }); postUnpack = "sourceRoot+=/persistent-sqlite; echo source root reset to \$sourceRoot"; } \ No newline at end of file diff --git a/nix/.stack.nix/persistent-template.nix b/nix/.stack.nix/persistent-template.nix new file mode 100644 index 00000000000..3d2b25047f5 --- /dev/null +++ b/nix/.stack.nix/persistent-template.nix @@ -0,0 +1,115 @@ +let + buildDepError = pkg: + builtins.throw '' + The Haskell package set does not contain the package: ${pkg} (build dependency). + + If you are using Stackage, make sure that you are using a snapshot that contains the package. Otherwise you may need to update the Hackage snapshot you are using, usually by updating haskell.nix. + ''; + sysDepError = pkg: + builtins.throw '' + The Nixpkgs package set does not contain the package: ${pkg} (system dependency). + + You may need to augment the system package mapping in haskell.nix so that it can be found. + ''; + pkgConfDepError = pkg: + builtins.throw '' + The pkg-conf packages does not contain the package: ${pkg} (pkg-conf dependency). + + You may need to augment the pkg-conf package mapping in haskell.nix so that it can be found. + ''; + exeDepError = pkg: + builtins.throw '' + The local executable components do not include the component: ${pkg} (executable dependency). + ''; + legacyExeDepError = pkg: + builtins.throw '' + The Haskell package set does not contain the package: ${pkg} (executable dependency). + + If you are using Stackage, make sure that you are using a snapshot that contains the package. Otherwise you may need to update the Hackage snapshot you are using, usually by updating haskell.nix. + ''; + buildToolDepError = pkg: + builtins.throw '' + Neither the Haskell package set or the Nixpkgs package set contain the package: ${pkg} (build tool dependency). + + If this is a system dependency: + You may need to augment the system package mapping in haskell.nix so that it can be found. + + If this is a Haskell dependency: + If you are using Stackage, make sure that you are using a snapshot that contains the package. Otherwise you may need to update the Hackage snapshot you are using, usually by updating haskell.nix. + ''; +in { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }: + { + flags = {}; + package = { + specVersion = "1.10"; + identifier = { name = "persistent-template"; version = "2.7.2"; }; + license = "MIT"; + copyright = ""; + maintainer = "Michael Snoyman , Greg Weber "; + author = "Michael Snoyman "; + homepage = "http://www.yesodweb.com/book/persistent"; + url = ""; + synopsis = "Type-safe, non-relational, multi-backend persistence."; + description = "Hackage documentation generation is not reliable. For up to date documentation, please see: ."; + buildType = "Simple"; + isLocal = true; + }; + components = { + "library" = { + depends = [ + (hsPkgs."base" or (buildDepError "base")) + (hsPkgs."persistent" or (buildDepError "persistent")) + (hsPkgs."aeson" or (buildDepError "aeson")) + (hsPkgs."bytestring" or (buildDepError "bytestring")) + (hsPkgs."containers" or (buildDepError "containers")) + (hsPkgs."http-api-data" or (buildDepError "http-api-data")) + (hsPkgs."monad-control" or (buildDepError "monad-control")) + (hsPkgs."monad-logger" or (buildDepError "monad-logger")) + (hsPkgs."path-pieces" or (buildDepError "path-pieces")) + (hsPkgs."template-haskell" or (buildDepError "template-haskell")) + (hsPkgs."text" or (buildDepError "text")) + (hsPkgs."transformers" or (buildDepError "transformers")) + (hsPkgs."unordered-containers" or (buildDepError "unordered-containers")) + ]; + buildable = true; + }; + tests = { + "test" = { + depends = [ + (hsPkgs."base" or (buildDepError "base")) + (hsPkgs."persistent" or (buildDepError "persistent")) + (hsPkgs."persistent-template" or (buildDepError "persistent-template")) + (hsPkgs."aeson" or (buildDepError "aeson")) + (hsPkgs."bytestring" or (buildDepError "bytestring")) + (hsPkgs."hspec" or (buildDepError "hspec")) + (hsPkgs."QuickCheck" or (buildDepError "QuickCheck")) + (hsPkgs."text" or (buildDepError "text")) + ]; + buildable = true; + }; + }; + benchmarks = { + "persistent-th-bench" = { + depends = [ + (hsPkgs."base" or (buildDepError "base")) + (hsPkgs."persistent" or (buildDepError "persistent")) + (hsPkgs."persistent-template" or (buildDepError "persistent-template")) + (hsPkgs."criterion" or (buildDepError "criterion")) + (hsPkgs."deepseq" or (buildDepError "deepseq")) + (hsPkgs."deepseq-generics" or (buildDepError "deepseq-generics")) + (hsPkgs."file-embed" or (buildDepError "file-embed")) + (hsPkgs."text" or (buildDepError "text")) + (hsPkgs."template-haskell" or (buildDepError "template-haskell")) + ]; + buildable = true; + }; + }; + }; + } // { + src = (pkgs.lib).mkDefault (pkgs.fetchgit { + url = "https://github.com/input-output-hk/persistent"; + rev = "107787ecc4c8a112375493cd66574f788f950fce"; + sha256 = "1livmfslqzadir5sc523r111wrd14s5k2nmvsxayk45hx3nnngfb"; + }); + postUnpack = "sourceRoot+=/persistent-template; echo source root reset to \$sourceRoot"; + } \ No newline at end of file diff --git a/nix/.stack.nix/persistent.nix b/nix/.stack.nix/persistent.nix new file mode 100644 index 00000000000..f6cd36e7813 --- /dev/null +++ b/nix/.stack.nix/persistent.nix @@ -0,0 +1,118 @@ +let + buildDepError = pkg: + builtins.throw '' + The Haskell package set does not contain the package: ${pkg} (build dependency). + + If you are using Stackage, make sure that you are using a snapshot that contains the package. Otherwise you may need to update the Hackage snapshot you are using, usually by updating haskell.nix. + ''; + sysDepError = pkg: + builtins.throw '' + The Nixpkgs package set does not contain the package: ${pkg} (system dependency). + + You may need to augment the system package mapping in haskell.nix so that it can be found. + ''; + pkgConfDepError = pkg: + builtins.throw '' + The pkg-conf packages does not contain the package: ${pkg} (pkg-conf dependency). + + You may need to augment the pkg-conf package mapping in haskell.nix so that it can be found. + ''; + exeDepError = pkg: + builtins.throw '' + The local executable components do not include the component: ${pkg} (executable dependency). + ''; + legacyExeDepError = pkg: + builtins.throw '' + The Haskell package set does not contain the package: ${pkg} (executable dependency). + + If you are using Stackage, make sure that you are using a snapshot that contains the package. Otherwise you may need to update the Hackage snapshot you are using, usually by updating haskell.nix. + ''; + buildToolDepError = pkg: + builtins.throw '' + Neither the Haskell package set or the Nixpkgs package set contain the package: ${pkg} (build tool dependency). + + If this is a system dependency: + You may need to augment the system package mapping in haskell.nix so that it can be found. + + If this is a Haskell dependency: + If you are using Stackage, make sure that you are using a snapshot that contains the package. Otherwise you may need to update the Hackage snapshot you are using, usually by updating haskell.nix. + ''; +in { system, compiler, flags, pkgs, hsPkgs, pkgconfPkgs, ... }: + { + flags = { nooverlap = false; }; + package = { + specVersion = "1.10"; + identifier = { name = "persistent"; version = "2.10.2"; }; + license = "MIT"; + copyright = ""; + maintainer = "Michael Snoyman , Greg Weber "; + author = "Michael Snoyman "; + homepage = "http://www.yesodweb.com/book/persistent"; + url = ""; + synopsis = "Type-safe, multi-backend data serialization."; + description = "Hackage documentation generation is not reliable. For up to date documentation, please see: ."; + buildType = "Simple"; + isLocal = true; + }; + components = { + "library" = { + depends = [ + (hsPkgs."base" or (buildDepError "base")) + (hsPkgs."aeson" or (buildDepError "aeson")) + (hsPkgs."attoparsec" or (buildDepError "attoparsec")) + (hsPkgs."base64-bytestring" or (buildDepError "base64-bytestring")) + (hsPkgs."blaze-html" or (buildDepError "blaze-html")) + (hsPkgs."bytestring" or (buildDepError "bytestring")) + (hsPkgs."conduit" or (buildDepError "conduit")) + (hsPkgs."containers" or (buildDepError "containers")) + (hsPkgs."fast-logger" or (buildDepError "fast-logger")) + (hsPkgs."http-api-data" or (buildDepError "http-api-data")) + (hsPkgs."monad-logger" or (buildDepError "monad-logger")) + (hsPkgs."mtl" or (buildDepError "mtl")) + (hsPkgs."path-pieces" or (buildDepError "path-pieces")) + (hsPkgs."resource-pool" or (buildDepError "resource-pool")) + (hsPkgs."resourcet" or (buildDepError "resourcet")) + (hsPkgs."scientific" or (buildDepError "scientific")) + (hsPkgs."silently" or (buildDepError "silently")) + (hsPkgs."template-haskell" or (buildDepError "template-haskell")) + (hsPkgs."text" or (buildDepError "text")) + (hsPkgs."time" or (buildDepError "time")) + (hsPkgs."transformers" or (buildDepError "transformers")) + (hsPkgs."unliftio-core" or (buildDepError "unliftio-core")) + (hsPkgs."unordered-containers" or (buildDepError "unordered-containers")) + (hsPkgs."vector" or (buildDepError "vector")) + ]; + buildable = true; + }; + tests = { + "test" = { + depends = [ + (hsPkgs."base" or (buildDepError "base")) + (hsPkgs."aeson" or (buildDepError "aeson")) + (hsPkgs."attoparsec" or (buildDepError "attoparsec")) + (hsPkgs."base64-bytestring" or (buildDepError "base64-bytestring")) + (hsPkgs."blaze-html" or (buildDepError "blaze-html")) + (hsPkgs."bytestring" or (buildDepError "bytestring")) + (hsPkgs."containers" or (buildDepError "containers")) + (hsPkgs."hspec" or (buildDepError "hspec")) + (hsPkgs."http-api-data" or (buildDepError "http-api-data")) + (hsPkgs."path-pieces" or (buildDepError "path-pieces")) + (hsPkgs."scientific" or (buildDepError "scientific")) + (hsPkgs."text" or (buildDepError "text")) + (hsPkgs."time" or (buildDepError "time")) + (hsPkgs."transformers" or (buildDepError "transformers")) + (hsPkgs."unordered-containers" or (buildDepError "unordered-containers")) + (hsPkgs."vector" or (buildDepError "vector")) + ]; + buildable = true; + }; + }; + }; + } // { + src = (pkgs.lib).mkDefault (pkgs.fetchgit { + url = "https://github.com/input-output-hk/persistent"; + rev = "107787ecc4c8a112375493cd66574f788f950fce"; + sha256 = "1livmfslqzadir5sc523r111wrd14s5k2nmvsxayk45hx3nnngfb"; + }); + postUnpack = "sourceRoot+=/persistent; echo source root reset to \$sourceRoot"; + } \ No newline at end of file diff --git a/stack.yaml b/stack.yaml index e361653c765..fb134e841bc 100644 --- a/stack.yaml +++ b/stack.yaml @@ -17,15 +17,15 @@ extra-deps: - quickcheck-state-machine-0.6.0 - command-0.1.1 -# persistent-sqlite with CASCADE DELETE support +# persistent-2.10.2 with CASCADE DELETE support for SQLite. # # See: https://github.com/input-output-hk/persistent/tree/cardano-wallet - git: https://github.com/input-output-hk/persistent - commit: 79f2ece07eafae005a703c8eda1bd2420b5e07b5 + commit: 107787ecc4c8a112375493cd66574f788f950fce subdirs: - - persistent-sqlite -- persistent-template-2.7.2 -- persistent-2.10.1 + - persistent + - persistent-sqlite + - persistent-template # cardano-crypto - git: https://github.com/input-output-hk/cardano-crypto