-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplpgsql_check.rb
76 lines (65 loc) · 2.59 KB
/
plpgsql_check.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class PlpgsqlCheck < Formula
desc "Plpgsql linter"
homepage "https://github.com/okbob/plpgsql_check"
url "https://github.com/okbob/plpgsql_check/archive/refs/tags/v2.7.15.tar.gz"
sha256 "1a16b957fa10dadd1abf3b17201eb702d3fc7fd466ff6ce04db2d6d6d38da442"
license "PostgreSQL"
bottle do
root_url "https://ghcr.io/v2/bayandin/tap"
sha256 cellar: :any_skip_relocation, arm64_sequoia: "3ae6b2ce39aac426ee1b27327f8607e3f63427de0406800b5226b9d1842a6138"
sha256 cellar: :any_skip_relocation, arm64_sonoma: "7e80b20b604c708c05a116ac7547d1c871776511dd1e96df943372b334a1ac9d"
sha256 cellar: :any_skip_relocation, ventura: "9b535c247a849dd0c08837133ad4c39b4c41647105d594795f7087a10063bb1b"
sha256 cellar: :any_skip_relocation, x86_64_linux: "13763b966e4ab35f8ff66acaf61c2ece606caf2c10a96b66822dcb23dacc1a3c"
end
depends_on "bayandin/tap/neon-postgres"
def neon_postgres
Formula["bayandin/tap/neon-postgres"]
end
def pg_versions
neon_postgres.pg_versions
end
def install
pg_versions.each do |v|
system "make", "clean", "PG_CONFIG=#{neon_postgres.pg_bin_for(v)}/pg_config"
system "make", "PG_CONFIG=#{neon_postgres.pg_bin_for(v)}/pg_config"
mkdir_p lib/neon_postgres.name/v
mv "plpgsql_check.#{neon_postgres.dlsuffix(v)}", lib/neon_postgres.name/v
mkdir_p share/neon_postgres.name/v/"extension"
cp "plpgsql_check.control", share/neon_postgres.name/v/"extension"
cp Dir["plpgsql_check--*.sql"], share/neon_postgres.name/v/"extension"
end
end
test do
pg_versions.each do |v|
pg_ctl = neon_postgres.pg_bin_for(v)/"pg_ctl"
psql = neon_postgres.pg_bin_for(v)/"psql"
port = free_port
system pg_ctl, "initdb", "-D", testpath/"test-#{v}"
(testpath/"test-#{v}/postgresql.conf").write <<~EOS, mode: "a+"
port = #{port}
EOS
system pg_ctl, "start", "-D", testpath/"test-#{v}", "-l", testpath/"log-#{v}"
begin
system psql, "-p", port.to_s, "-c", <<~SQL, "postgres"
CREATE EXTENSION plpgsql_check;
CREATE TABLE t1(a int, b int);
CREATE OR REPLACE FUNCTION public.f1()
RETURNS void
LANGUAGE plpgsql
AS $function$
DECLARE r record;
BEGIN
FOR r IN SELECT * FROM t1
LOOP
RAISE NOTICE '%', r.c; -- there is bug - table t1 missing "c" column
END LOOP;
END;
$function$;
SELECT * FROM plpgsql_check_function_tb('f1()');
SQL
ensure
system pg_ctl, "stop", "-D", testpath/"test-#{v}"
end
end
end
end