about summary refs log tree commit diff
path: root/pkgs/development/tools/squawk
diff options
context:
space:
mode:
authorAndrew Smith <andrew@velvet.software>2023-02-03 19:53:58 -0800
committerAndrew Smith <andrew@velvet.software>2023-02-13 14:58:02 -0800
commit206da520053caa6022fc3dbbc6847939df9c8c42 (patch)
tree20aae3a3dc0ad8a56c1d446717ccd11a249ae82d /pkgs/development/tools/squawk
parent6f7a553d0a3c3dd59a4203afe97cf8e45a734afa (diff)
squawk: init at 0.20.0
Squawk is a useful tool for linting PostgreSQL DDL migrations for
potential downtime risks.

Squawk 0.20.0 was released without updating Cargo.lock, so I patched
that. There was also a test that failed because it snapshots the
internal version of the PostgreSQL parser and there was a minor version
difference. I patched that as well.

Each version of libpg_query corresponds to the PostgreSQL version from
which the parser code is extracted. There are slightly different
abstract syntax trees produced by different versions of PostgreSQL and
Squawk doesn't handle the latest one available in nixpkgs. Override it
just for Squawk.

I pulled this from 45bff9e87be49f8c5b97d5d471039b9242e86251.
Diffstat (limited to 'pkgs/development/tools/squawk')
-rw-r--r--pkgs/development/tools/squawk/correct-Cargo.lock.patch13
-rw-r--r--pkgs/development/tools/squawk/default.nix67
-rw-r--r--pkgs/development/tools/squawk/fix-postgresql-version-in-snapshot-test.patch13
3 files changed, 93 insertions, 0 deletions
diff --git a/pkgs/development/tools/squawk/correct-Cargo.lock.patch b/pkgs/development/tools/squawk/correct-Cargo.lock.patch
new file mode 100644
index 0000000000000..431f004d2d752
--- /dev/null
+++ b/pkgs/development/tools/squawk/correct-Cargo.lock.patch
@@ -0,0 +1,13 @@
+diff --git a/Cargo.lock b/Cargo.lock
+index d5803a8..384224d 100644
+--- a/Cargo.lock
++++ b/Cargo.lock
+@@ -1585,7 +1585,7 @@ checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
+ 
+ [[package]]
+ name = "squawk"
+-version = "0.19.0"
++version = "0.20.0"
+ dependencies = [
+  "atty",
+  "base64 0.12.3",
diff --git a/pkgs/development/tools/squawk/default.nix b/pkgs/development/tools/squawk/default.nix
new file mode 100644
index 0000000000000..9649625c1737d
--- /dev/null
+++ b/pkgs/development/tools/squawk/default.nix
@@ -0,0 +1,67 @@
+{ darwin
+, fetchFromGitHub
+, lib
+, libiconv
+, libpg_query
+, openssl
+, pkg-config
+, rustPlatform
+, stdenv
+}:
+let
+  # The query parser produces a slightly different AST between major versions
+  # and Squawk is not capable of handling >=14 correctly yet.
+  libpg_query13 = libpg_query.overrideAttrs (_: rec {
+    version = "13-2.2.0";
+    src = fetchFromGitHub {
+      owner = "pganalyze";
+      repo = "libpg_query";
+      rev = version;
+      hash = "sha256-gEkcv/j8ySUYmM9lx1hRF/SmuQMYVHwZAIYOaCQWAFs=";
+    };
+  });
+in
+rustPlatform.buildRustPackage rec {
+  pname = "squawk";
+  version = "0.20.0";
+
+  src = fetchFromGitHub {
+    owner = "sbdchd";
+    repo = pname;
+    rev = "v${version}";
+    hash = "sha256-v9F+HfscX4dIExIP1YvxOldZPPtmxh8lO3SREu6M+C0=";
+  };
+
+  cargoHash = "sha256-kSaQxqom8LSCOQBoIZ1iv+q2+Ih8l61L97xXv5c4a0k=";
+
+  cargoPatches = [
+    ./correct-Cargo.lock.patch
+  ];
+
+  patches = [
+    ./fix-postgresql-version-in-snapshot-test.patch
+  ];
+
+  nativeBuildInputs = [
+    pkg-config
+    rustPlatform.bindgenHook
+  ];
+
+  buildInputs = lib.optionals (!stdenv.isDarwin) [
+    libiconv
+    openssl
+  ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
+    CoreFoundation
+    Security
+  ]);
+
+  LIBPG_QUERY_PATH = libpg_query13;
+
+  meta = with lib; {
+    description = "Linter for PostgreSQL, focused on migrations";
+    homepage = "https://squawkhq.com/";
+    changelog = "https://github.com/sbdchd/squawk/blob/v${version}/CHANGELOG.md";
+    license = licenses.gpl3Only;
+    maintainers = with lib.maintainers; [ andrewsmith ];
+  };
+}
diff --git a/pkgs/development/tools/squawk/fix-postgresql-version-in-snapshot-test.patch b/pkgs/development/tools/squawk/fix-postgresql-version-in-snapshot-test.patch
new file mode 100644
index 0000000000000..205fd3dba9731
--- /dev/null
+++ b/pkgs/development/tools/squawk/fix-postgresql-version-in-snapshot-test.patch
@@ -0,0 +1,13 @@
+diff --git a/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json.snap b/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json.snap
+index 7273b74..ae94927 100644
+--- a/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json.snap
++++ b/parser/src/snapshots/squawk_parser__parse__tests__parse_sql_query_json.snap
+@@ -133,7 +133,7 @@ Ok(
+             }),
+         ]),
+         "version": Number(
+-            130003,
++            130008,
+         ),
+     }),
+ )