|
| 1 | +class Electric < Formula |
| 2 | + desc "Real-time sync for Postgres" |
| 3 | + homepage "https://electric-sql.com" |
| 4 | + url "https://github.com/electric-sql/electric/archive/refs/tags/@core/[email protected]" |
| 5 | + sha256 "58f28cf698cc7d8de8c780fe831932aa62efb207ec443b26ba46e9a0d6242a41" |
| 6 | + license "Apache-2.0" |
| 7 | + |
| 8 | + bottle do |
| 9 | + sha256 cellar: :any, arm64_sequoia: "6d77cb95934fbb68d5022b728635efda38da9b359e3d7d596f8521814a0c9ef8" |
| 10 | + sha256 cellar: :any, arm64_sonoma: "c92bb0710595e82915596640f6d5fd5c2394325f57a89090ade94e2da47f9cd3" |
| 11 | + sha256 cellar: :any, arm64_ventura: "5ad12957265cb407bd227421468efa67771ebe19828a6ee32401d71f927919a2" |
| 12 | + sha256 cellar: :any, sonoma: "737c07d008629bf0036d8f51d9332801193aaa7b9d0f5d8479aaffc2228531d9" |
| 13 | + sha256 cellar: :any, ventura: "b06c3901909e728b86949b21f5ec4cab239a5bba9ab62b1a1c8115b48e300e20" |
| 14 | + sha256 cellar: :any_skip_relocation, x86_64_linux: "0663309185b4eade5947e6ece0ffc0cbb30d2f121dd32b4e71376927c148383a" |
| 15 | + end |
| 16 | + |
| 17 | + depends_on "elixir" => :build |
| 18 | + depends_on "postgresql@17" => :test |
| 19 | + depends_on "erlang" |
| 20 | + depends_on "openssl@3" |
| 21 | + |
| 22 | + uses_from_macos "ncurses" |
| 23 | + uses_from_macos "zlib" |
| 24 | + |
| 25 | + def install |
| 26 | + ENV["MIX_ENV"] = "prod" |
| 27 | + ENV["MIX_TARGET"] = "application" |
| 28 | + |
| 29 | + cd "packages/sync-service" do |
| 30 | + system "mix", "deps.get" |
| 31 | + system "mix", "compile" |
| 32 | + system "mix", "release" |
| 33 | + libexec.install Dir["_build/application_prod/rel/electric/*"] |
| 34 | + bin.write_exec_script libexec.glob("bin/*") |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + test do |
| 39 | + assert_match version.to_s, shell_output("#{bin}/electric version") |
| 40 | + |
| 41 | + ENV["LC_ALL"] = "C" |
| 42 | + |
| 43 | + postgresql = Formula["postgresql@17"] |
| 44 | + pg_ctl = postgresql.opt_bin/"pg_ctl" |
| 45 | + port = free_port |
| 46 | + |
| 47 | + system pg_ctl, "initdb", "-D", testpath/"test" |
| 48 | + (testpath/"test/postgresql.conf").write <<~EOS, mode: "a+" |
| 49 | + port = #{port} |
| 50 | + wal_level = logical |
| 51 | + EOS |
| 52 | + system pg_ctl, "start", "-D", testpath/"test", "-l", testpath/"log" |
| 53 | + |
| 54 | + begin |
| 55 | + ENV["DATABASE_URL"] = "postgres://#{ENV["USER"]}:@localhost:#{port}/postgres?sslmode=disable" |
| 56 | + ENV["ELECTRIC_INSECURE"] = "true" |
| 57 | + ENV["ELECTRIC_PORT"] = free_port.to_s |
| 58 | + spawn bin/"electric", "start" |
| 59 | + |
| 60 | + output = shell_output("curl -s --retry 5 --retry-connrefused localhost:#{ENV["ELECTRIC_PORT"]}/v1/health") |
| 61 | + assert_match "active", output |
| 62 | + ensure |
| 63 | + system pg_ctl, "stop", "-D", testpath/"test" |
| 64 | + end |
| 65 | + end |
| 66 | +end |
0 commit comments