diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a0b23cf541..2ace7ffe98 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -247,7 +247,7 @@ jobs: Build-Cabal: strategy: matrix: - ghc: ['9.0.2', '9.2.4'] + ghc: ['9.4.8'] fail-fast: false name: Build Linux (Cabal, GHC ${{ matrix.ghc }}) runs-on: ubuntu-latest @@ -284,7 +284,7 @@ jobs: Build-Cabal-Arm: strategy: matrix: - ghc: ['9.2.4'] + ghc: ['9.4.8'] fail-fast: false name: Build aarch64 (Cabal, GHC ${{ matrix.ghc }}) if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/heads/rel-') }} diff --git a/cabal.project b/cabal.project new file mode 100644 index 0000000000..313d3fc1f4 --- /dev/null +++ b/cabal.project @@ -0,0 +1,2 @@ +packages: postgrest.cabal +tests: true diff --git a/cabal.project.freeze b/cabal.project.freeze index 20a931e505..b9a591a7c4 100644 --- a/cabal.project.freeze +++ b/cabal.project.freeze @@ -1 +1 @@ -index-state: hackage.haskell.org 2023-10-13T13:54:33Z +index-state: hackage.haskell.org 2024-01-06T00:00:00Z diff --git a/default.nix b/default.nix index aa125e60a1..918a96f52d 100644 --- a/default.nix +++ b/default.nix @@ -5,7 +5,7 @@ let "postgrest"; compiler = - "ghc924"; + "ghc948"; # PostgREST source files, filtered based on the rules in the .gitignore files # and file extensions. We want to include as litte as possible, as the files @@ -36,10 +36,10 @@ let allOverlays.build-toolbox allOverlays.checked-shell-script allOverlays.gitignore - allOverlays.postgis (allOverlays.postgresql-default { inherit patches; }) allOverlays.postgresql-legacy allOverlays.postgresql-future + allOverlays.postgis (allOverlays.haskell-packages { inherit compiler; }) allOverlays.slocat ]; @@ -50,19 +50,7 @@ let postgresqlVersions = [ - { - name = "postgresql-16"; - postgresql = pkgs.postgresql_16.withPackages (p: [ - p.postgis - (p.pg_safeupdate.overrideAttrs (old: { - installPhase = '' - mkdir -p $out/bin - cp safeupdate.dylib safeupdate.so || true - install -D safeupdate.so -t $out/lib - ''; - })) - ]); - } + { name = "postgresql-16"; postgresql = pkgs.postgresql_16.withPackages (p: [ p.postgis p.pg_safeupdate ]); } { name = "postgresql-15"; postgresql = pkgs.postgresql_15.withPackages (p: [ p.postgis p.pg_safeupdate ]); } { name = "postgresql-14"; postgresql = pkgs.postgresql_14.withPackages (p: [ p.postgis p.pg_safeupdate ]); } { name = "postgresql-13"; postgresql = pkgs.postgresql_13.withPackages (p: [ p.postgis p.pg_safeupdate ]); } diff --git a/nix/hsie/Main.hs b/nix/hsie/Main.hs index b3a52c55d3..ed85430534 100644 --- a/nix/hsie/Main.hs +++ b/nix/hsie/Main.hs @@ -17,7 +17,6 @@ module Main (main) where import qualified Data.Aeson as JSON import qualified Data.ByteString.Lazy.Char8 as LBS8 import qualified Data.Csv as Csv -import qualified Data.List as List import qualified Data.Map as Map import qualified Data.Set as Set import qualified Data.Text as T @@ -34,12 +33,13 @@ import Data.Function ((&)) import Data.List (intercalate) import Data.Maybe (catMaybes, mapMaybe) import Data.Text (Text) -import GHC.Data.Bag (bagToList) import GHC.Generics (Generic) import GHC.Hs.Extension (GhcPs) +import GHC.Types.Error (getMessages) import GHC.Types.Name.Occurrence (occNameString) import GHC.Types.Name.Reader (rdrNameOcc) import GHC.Unit.Module.Name (moduleNameString) +import GHC.Utils.Error (pprMsgEnvelopeBagWithLoc) import System.Directory.Recursive (getFilesRecursive) import System.Exit (exitFailure) @@ -206,7 +206,7 @@ parseModule filepath = do return $ GHC.unLoc hsmod Left errs -> fail $ "Errors with " <> show filepath <> ":\n " - <> List.intercalate "\n " (show <$> bagToList errs) + <> show (pprMsgEnvelopeBagWithLoc $ getMessages errs) -- | Symbols imported in an import declaration. -- @@ -250,8 +250,7 @@ dump OutputJson = encodePretty -- | Find modules that are imported under different aliases inconsistentAliases :: [ImportedSymbol] -> ModuleAliases inconsistentAliases symbols = - fmap moduleAlias symbols - & foldr insertSetMapMap Map.empty + foldr (insertSetMapMap . moduleAlias) Map.empty symbols & Map.map (aliases . Map.toList) & Map.filter ((<) 1 . length) & Map.toList diff --git a/nix/hsie/default.nix b/nix/hsie/default.nix index 1f6c2297d7..706c43848c 100644 --- a/nix/hsie/default.nix +++ b/nix/hsie/default.nix @@ -11,6 +11,7 @@ let ps.dir-traverse ps.dot ps.ghc-exactprint + ps.ghc-paths ps.optparse-applicative ]; ghc = ghcWithPackages modules; diff --git a/nix/nixpkgs-version.nix b/nix/nixpkgs-version.nix index 9500eb9a78..b943aa0fcf 100644 --- a/nix/nixpkgs-version.nix +++ b/nix/nixpkgs-version.nix @@ -1,6 +1,6 @@ # Pinned version of Nixpkgs, generated with postgrest-nixpkgs-upgrade. { - date = "2023-03-25"; - rev = "dbf5322e93bcc6cfc52268367a8ad21c09d76fea"; - tarballHash = "0lwk4v9dkvd28xpqch0b0jrac4xl9lwm6snrnzx8k5lby72kmkng"; + date = "2024-01-06"; + rev = "4bbf5a2eb6046c54f7a29a0964c642ebfe912cbc"; + tarballHash = "03p45qdcxqxc41mmzmmyzbkff29vv95vv643z0kd3mf1s2nnsy5b"; } diff --git a/nix/overlays/haskell-packages.nix b/nix/overlays/haskell-packages.nix index 6751d75a31..01764e63ad 100644 --- a/nix/overlays/haskell-packages.nix +++ b/nix/overlays/haskell-packages.nix @@ -29,6 +29,18 @@ let # To fill in the sha256: # update-nix-fetchgit nix/overlays/haskell-packages.nix + configurator-pg = + prev.callHackageDirect + { + pkg = "configurator-pg"; + ver = "0.2.9"; + sha256 = "sha256-UqFiOgPlksbIdHBVO0wYhCnboB+mxKJcXVhY9C1V7Hg="; + } + { }; + + # Marked as broken (?) + fuzzyset = lib.markUnbroken prev.fuzzyset; + postgresql-libpq = lib.dontCheck (prev.callCabal2nix "postgresql-libpq" (super.fetchFromGitHub { @@ -39,23 +51,8 @@ let }) { }); - hasql-notifications = lib.dontCheck - (prev.callHackageDirect - { - pkg = "hasql-notifications"; - ver = "0.2.0.6"; - sha256 = "sha256-7PyFlB2B70njudOjaX6tk1m77ol9vnF5fI0LF86kVAI="; - } - { }); + hasql-pool = lib.dontCheck prev.hasql-pool_0_10; - hasql-pool = lib.dontCheck - (prev.callHackageDirect - { - pkg = "hasql-pool"; - ver = "0.10"; - sha256 = "sha256-kHzoqtNV9BFWnn1h560JRqMooQRwxokVKgDRBexamNI="; - } - { }); } // extraOverrides final prev; in { diff --git a/nix/overlays/postgis.nix b/nix/overlays/postgis.nix index 846fb7a857..26b5e226e4 100644 --- a/nix/overlays/postgis.nix +++ b/nix/overlays/postgis.nix @@ -6,6 +6,7 @@ let url = "https://download.osgeo.org/postgis/source/postgis-${version}.tar.gz"; sha256 = "sha256-G02LXHVuWrpZ77wYM7Iu/k1lYneO7KVvpJf+susTZow="; }; + meta.broken = false; }; in { diff --git a/nix/overlays/postgresql-future.nix b/nix/overlays/postgresql-future.nix index 9180c64e5e..90964d075c 100644 --- a/nix/overlays/postgresql-future.nix +++ b/nix/overlays/postgresql-future.nix @@ -4,16 +4,16 @@ self: super: { ## Example for including a postgresql version from a specific nixpks commit: ## - postgresql_16 = - let - rev = "5148520bfab61f99fd25fb9ff7bfbb50dad3c9db"; - tarballHash = "1dfjmz65h8z4lk845724vypzmf3dbgsdndjpj8ydlhx6c7rpcq3p"; - - pinnedPkgs = - builtins.fetchTarball { - url = "https://github.com/nixos/nixpkgs/archive/${rev}.tar.gz"; - sha256 = tarballHash; - }; - in - (import pinnedPkgs { }).pkgs.postgresql_16; + # postgresql_16 = + # let + # rev = "5148520bfab61f99fd25fb9ff7bfbb50dad3c9db"; + # tarballHash = "1dfjmz65h8z4lk845724vypzmf3dbgsdndjpj8ydlhx6c7rpcq3p"; + # + # pinnedPkgs = + # builtins.fetchTarball { + # url = "https://github.com/nixos/nixpkgs/archive/${rev}.tar.gz"; + # sha256 = tarballHash; + # }; + # in + # (import pinnedPkgs { }).pkgs.postgresql_16; } diff --git a/nix/overlays/postgresql-legacy.nix b/nix/overlays/postgresql-legacy.nix index cb2c5940fd..cd07af5aa1 100644 --- a/nix/overlays/postgresql-legacy.nix +++ b/nix/overlays/postgresql-legacy.nix @@ -31,4 +31,19 @@ self: super: }; in (import pinnedPkgs { }).pkgs.postgresql_10; + + # PostgreSQL 11 was removed from Nixpkgs with + # https://github.com/NixOS/nixpkgs/commit/1220a4d4dd1a4590780a5e1c18d1333a121be366 + # We pin its parent commit to get the last version that was available. + postgresql_11 = + let + rev = "f5458516e42cc5cb4123cc2d93f45c240548aa18"; + tarballHash = "1h03621sxfhw4z6ya74k6c2lyx3z7pvf2jcg4vs7i01yz2m6w3cv"; + pinnedPkgs = + builtins.fetchTarball { + url = "https://github.com/nixos/nixpkgs/archive/${rev}.tar.gz"; + sha256 = tarballHash; + }; + in + (import pinnedPkgs { }).pkgs.postgresql_11; } diff --git a/nix/overlays/slocat.nix b/nix/overlays/slocat.nix index cb17963c0e..577b527fba 100644 --- a/nix/overlays/slocat.nix +++ b/nix/overlays/slocat.nix @@ -8,6 +8,6 @@ final: prev: rev = "52e7512c6029fd00483e41ccce260a3b4b9b3b64"; sha256 = "sha256-qn6luuh5wqREu3s8RfuMCP5PKdS2WdwPrujRYTpfzQ8="; }; - vendorSha256 = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; + vendorHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; }; } diff --git a/nix/static-haskell-package.nix b/nix/static-haskell-package.nix index 60f97bb8b3..01ba11ee61 100644 --- a/nix/static-haskell-package.nix +++ b/nix/static-haskell-package.nix @@ -51,7 +51,7 @@ let defaultCabalPackageVersionComingWithGhc = { - ghc924 = "Cabal_3_6_3_0"; + ghc948 = "Cabal_3_8_1_0"; }."${compiler}"; # The static-haskell-nix 'survey' derives a full static set of Haskell diff --git a/nix/tools/loadtest.nix b/nix/tools/loadtest.nix index 1e6d3152eb..0d514d54c0 100644 --- a/nix/tools/loadtest.nix +++ b/nix/tools/loadtest.nix @@ -172,7 +172,7 @@ let } '' find loadtest -type f -iname '*.bin' -exec ${reporter} {} \; \ - | ${jq}/bin/jq '[leaf_paths as $path | {param: $path | join("."), (.branch): getpath($path)}]' \ + | ${jq}/bin/jq '[paths(scalars) as $path | {param: $path | join("."), (.branch): getpath($path)}]' \ | ${jq}/bin/jq --slurp 'flatten | group_by(.param) | map(add)' \ | ${toMarkdown} ''; diff --git a/nix/tools/nixpkgsTools.nix b/nix/tools/nixpkgsTools.nix index c4128e5b9c..6f4d04269a 100644 --- a/nix/tools/nixpkgsTools.nix +++ b/nix/tools/nixpkgsTools.nix @@ -5,7 +5,7 @@ , jq , nix }: -# Utility script for pinning the latest unstable version of Nixpkgs. +# Utility script for pinning the latest stable version of Nixpkgs. # Instead of pinning Nixpkgs based on the huge Git repository, we reference a # specific tarball that only contains the source of the revision that we want @@ -15,7 +15,7 @@ let "postgrest-nixpkgs-upgrade"; refUrl = - "https://api.github.com/repos/nixos/nixpkgs/git/ref/heads/nixpkgs-unstable"; + "https://api.github.com/repos/nixos/nixpkgs/git/matching-refs/heads/nixpkgs-"; githubV3Header = "Accept: application/vnd.github.v3+json"; @@ -27,11 +27,12 @@ let checkedShellScript { inherit name; - docs = "Pin the newest unstable version of Nixpkgs."; + docs = "Pin the newest stable version of Nixpkgs."; inRootDir = true; } '' - commitHash="$(${curl}/bin/curl "${refUrl}" -H "${githubV3Header}" | ${jq}/bin/jq -r .object.sha)" + # The list of refs is sorted. The first result will be nixpkgs-unstable, the second the latest stable branch. + commitHash="$(${curl}/bin/curl "${refUrl}" -H "${githubV3Header}" | ${jq}/bin/jq -r 'sort_by(.ref) | reverse | .[1].object.sha')" tarballUrl="${tarballUrlBase}$commitHash.tar.gz" tarballHash="$(${nix}/bin/nix-prefetch-url --unpack "$tarballUrl")" currentDate="$(${coreutils}/bin/date --iso)" diff --git a/nix/tools/tests.nix b/nix/tools/tests.nix index eddeccd4de..a5da6f0546 100644 --- a/nix/tools/tests.nix +++ b/nix/tools/tests.nix @@ -132,7 +132,7 @@ let ( trap 'echo Found dead code: Check file list above.' ERR ; - ${weeder}/bin/weeder --config=./test/weeder.dhall + ${weeder}/bin/weeder --config=./test/weeder.toml ) # collect all tests diff --git a/postgrest.cabal b/postgrest.cabal index d879b1b639..689ef77cd4 100644 --- a/postgrest.cabal +++ b/postgrest.cabal @@ -75,7 +75,7 @@ library PostgREST.Response.Performance PostgREST.Version other-modules: Paths_postgrest - build-depends: base >= 4.9 && < 4.17 + build-depends: base >= 4.9 && < 4.18 , HTTP >= 4000.3.7 && < 4000.5 , Ranged-sets >= 0.3 && < 0.5 , aeson >= 2.0.3 && < 2.2 @@ -93,7 +93,7 @@ library , directory >= 1.2.6 && < 1.4 , either >= 4.4.1 && < 5.1 , extra >= 1.7.0 && < 2.0 - , fuzzyset >= 0.2.3 + , fuzzyset >= 0.3.0 , gitrev >= 1.2 && < 1.4 , hasql >= 1.6.1.1 && < 1.7 , hasql-dynamic-statements >= 0.3.1 && < 0.4 @@ -118,11 +118,11 @@ library , scientific >= 0.3.4 && < 0.4 , streaming-commons >= 0.1.1 && < 0.3 , swagger2 >= 2.4 && < 2.9 - , text >= 1.2.2 && < 1.3 - , time >= 1.6 && < 1.12 + , text >= 1.2.2 && < 2.1 + , time >= 1.6 && < 1.13 , timeit >= 2.0 && < 2.1 , unordered-containers >= 0.2.8 && < 0.3 - , unix-compat >= 0.5.4 && < 0.6 + , unix-compat >= 0.5.4 && < 0.8 , vault >= 0.3.1.5 && < 0.4 , vector >= 0.11 && < 0.14 , wai >= 3.2.1 && < 3.3 @@ -159,7 +159,7 @@ executable postgrest NoImplicitPrelude hs-source-dirs: main main-is: Main.hs - build-depends: base >= 4.9 && < 4.17 + build-depends: base >= 4.9 && < 4.18 , containers >= 0.5.7 && < 0.7 , postgrest , protolude >= 0.3.1 && < 0.4 @@ -233,7 +233,7 @@ test-suite spec Feature.RollbackSpec Feature.RpcPreRequestGucsSpec SpecHelper - build-depends: base >= 4.9 && < 4.17 + build-depends: base >= 4.9 && < 4.18 , aeson >= 2.0.3 && < 2.2 , aeson-qq >= 0.8.1 && < 0.9 , async >= 2.1.1 && < 2.3 @@ -245,7 +245,7 @@ test-suite spec , hasql-pool >= 0.10 && < 0.11 , hasql-transaction >= 1.0.1 && < 1.1 , heredoc >= 0.2 && < 0.3 - , hspec >= 2.3 && < 2.10 + , hspec >= 2.3 && < 2.11 , hspec-wai >= 0.10 && < 0.12 , hspec-wai-json >= 0.10 && < 0.12 , http-types >= 0.12.3 && < 0.13 @@ -257,7 +257,7 @@ test-suite spec , protolude >= 0.3.1 && < 0.4 , regex-tdfa >= 1.2.2 && < 1.4 , scientific >= 0.3.4 && < 0.4 - , text >= 1.2.2 && < 1.3 + , text >= 1.2.2 && < 2.1 , transformers-base >= 0.4.4 && < 0.5 , wai >= 3.2.1 && < 3.3 , wai-extra >= 3.0.19 && < 3.2 @@ -275,7 +275,7 @@ test-suite doctests NoImplicitPrelude hs-source-dirs: test/doc main-is: Main.hs - build-depends: base >= 4.9 && < 4.17 + build-depends: base >= 4.9 && < 4.18 , doctest >= 0.8 , postgrest , pretty-simple diff --git a/src/PostgREST/Error.hs b/src/PostgREST/Error.hs index b378702005..b63384b439 100644 --- a/src/PostgREST/Error.hs +++ b/src/PostgREST/Error.hs @@ -17,7 +17,7 @@ module PostgREST.Error import qualified Data.Aeson as JSON import qualified Data.ByteString.Char8 as BS import qualified Data.CaseInsensitive as CI -import qualified Data.FuzzySet as Fuzzy +import qualified Data.FuzzySet.Simple as Fuzzy import qualified Data.HashMap.Strict as HM import qualified Data.Map.Internal as M import qualified Data.Text as T @@ -293,9 +293,9 @@ noRelBetweenHint parent child schema allRels = ("Perhaps you meant '" <>) <$> findParent = HM.lookup (QualifiedIdentifier schema parent, schema) allRels fuzzySetOfParents = Fuzzy.fromList [qiName (fst p) | p <- HM.keys allRels, snd p == schema] fuzzySetOfChildren = Fuzzy.fromList [qiName (relForeignTable c) | c <- fromMaybe [] findParent] - suggestParent = Fuzzy.getOne fuzzySetOfParents parent + suggestParent = snd <$> Fuzzy.findOne parent fuzzySetOfParents -- Do not give suggestion if the child is found in the relations (weight = 1.0) - suggestChild = headMay [snd k | k <- Fuzzy.get fuzzySetOfChildren child, fst k < 1.0] + suggestChild = headMay [snd k | k <- Fuzzy.find child fuzzySetOfChildren, fst k < 1.0] -- | -- If no function is found with the given name, it does a fuzzy search to all the functions @@ -345,8 +345,8 @@ noRpcHint schema procName params allProcs overloadedProcs = -- E.g. ["val", "param", "name"] into "(name, param, val)" listToText = ("(" <>) . (<> ")") . T.intercalate ", " . sort possibleProcs - | null overloadedProcs = Fuzzy.getOne fuzzySetOfProcs procName - | otherwise = (procName <>) <$> Fuzzy.getOne fuzzySetOfParams (listToText params) + | null overloadedProcs = snd <$> Fuzzy.findOne procName fuzzySetOfProcs + | otherwise = (procName <>) . snd <$> Fuzzy.findOne (listToText params) fuzzySetOfParams compressedRel :: Relationship -> JSON.Value -- An ambiguousness error cannot happen for computed relationships TODO refactor so this mempty is not needed diff --git a/stack.yaml b/stack.yaml index cd42879e0a..ba4ad97b4f 100644 --- a/stack.yaml +++ b/stack.yaml @@ -1,4 +1,4 @@ -resolver: lts-20.6 # 2023-01-09, GHC 9.2.5 +resolver: lts-21.7 # 2023-08-14, GHC 9.4.5 nix: packages: @@ -10,7 +10,10 @@ nix: pure: false extra-deps: + - configurator-pg-0.2.7 - git: https://github.com/PostgREST/postgresql-libpq.git commit: 890a0a16cf57dd401420fdc6c7d576fb696003bc - hasql-notifications-0.2.0.6 - hasql-pool-0.10 + - fuzzyset-0.3.1 + - megaparsec-9.2.2 diff --git a/stack.yaml.lock b/stack.yaml.lock index dfc9c8208d..4b8f686c99 100644 --- a/stack.yaml.lock +++ b/stack.yaml.lock @@ -4,6 +4,13 @@ # https://docs.haskellstack.org/en/stable/lock_files packages: +- completed: + hackage: configurator-pg-0.2.7@sha256:7327ce30c3b6bc50930efa73e2e215c8f62857564483edbbe5a75920057ef764,2849 + pantry-tree: + sha256: 023bd4835a7ac2624c44d3bbb26e99000994ce953d11d853c0f194278983d4dc + size: 2463 + original: + hackage: configurator-pg-0.2.7 - completed: commit: 890a0a16cf57dd401420fdc6c7d576fb696003bc git: https://github.com/PostgREST/postgresql-libpq.git @@ -29,9 +36,23 @@ packages: size: 346 original: hackage: hasql-pool-0.10 +- completed: + hackage: fuzzyset-0.3.1@sha256:344e16deedb43da5cabae558450e5710843cff7ac2f3073be9db453c6f3a3fb7,2373 + pantry-tree: + sha256: 89e22c2ce70a7c7c4b599ffe2546cda5699e4f8f15410eac49f39af8c4c381c8 + size: 643 + original: + hackage: fuzzyset-0.3.1 +- completed: + hackage: megaparsec-9.2.2@sha256:c306a135ec25d91d252032c6128f03598a00e87ea12fcf5fc4878fdffc75c768,3219 + pantry-tree: + sha256: db9715d6910e64d3bbfce69895042a66fcdcd64a54805563834bf0821562b74f + size: 1518 + original: + hackage: megaparsec-9.2.2 snapshots: - completed: - sha256: 4905c93319aa94aa53da8f41d614d7bacdbfe6c63a8c6132d32e6e62f24a9af4 - size: 649315 - url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/20/6.yaml - original: lts-20.6 + sha256: 23bb9bb355bfdb1635252e120a29b712f0d5e8a6c6a65c5ab5bd6692f46c438e + size: 640457 + url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/21/7.yaml + original: lts-21.7 diff --git a/test/weeder.dhall b/test/weeder.dhall deleted file mode 100644 index 683e34bddc..0000000000 --- a/test/weeder.dhall +++ /dev/null @@ -1,4 +0,0 @@ -{ - roots = [ "^Main.main$", "^Paths_" ], - type-class-roots = True -} diff --git a/test/weeder.toml b/test/weeder.toml new file mode 100644 index 0000000000..6c357c2583 --- /dev/null +++ b/test/weeder.toml @@ -0,0 +1,2 @@ +roots = [ "^Main.main$", "^Paths_" ] +type-class-roots = true