Files
ubicloud/db.rb
Enes Cakir eef9c54107 Revert "Add the implicit_subquery extension"
This reverts commit 0085befc4a.

This commit caused puma to fail to start, breaking production.

You can reproduce it locally by running:

    RACK_ENV=production bundle exec puma -t 5:5 -p ${PORT:-9292} -e ${RACK_ENV:-production}

The head of logs:

    2024-10-17 08:58:08  Starting process with command `bundle exec puma -t 5:5 -p ${PORT:-3000} -e ${RACK_ENV:-development}`
    2024-10-17 08:58:09  Puma starting in single mode...
    2024-10-17 08:58:09  * Puma version: 6.4.3 (ruby 3.2.5-p208) ("The Eagle of Durango")
    2024-10-17 08:58:09  *  Min threads: 5
    2024-10-17 08:58:09  *  Max threads: 5
    2024-10-17 08:58:09  *  Environment: production
    2024-10-17 08:58:09  *          PID: 2
    2024-10-17 08:58:11  ! Unable to load application: Sequel::DatabaseError: PG::SyntaxError: ERROR:  syntax error at or near ")"
    2024-10-17 08:58:11  LINE 1: ...T NULL AS "v" FROM (SHOW max_prepared_transactions) AS "t1" ...
    2024-10-17 08:58:11  bundler: failed to load command: puma (/app/vendor/bundle/ruby/3.2.0/bin/puma)
    2024-10-17 08:58:11  /app/vendor/bundle/ruby/3.2.0/gems/sequel-5.84.0/lib/sequel/adapters/postgres.rb:171:in `exec': PG::SyntaxError: ERROR:  syntax error at or near ")" (Sequel::DatabaseError)
    2024-10-17 08:58:11  LINE 1: ...T NULL AS "v" FROM (SHOW max_prepared_transactions) AS "t1" ...
    ...
    2024-10-17 08:58:11  	from /app/clover.rb:12:in `freeze'
    2024-10-17 08:58:11  	from config.ru:7:in `block (2 levels) in <top (required)>'
    ...
    2024-10-17 08:58:11  /app/vendor/bundle/ruby/3.2.0/gems/sequel-5.84.0/lib/sequel/adapters/postgres.rb:171:in `exec': ERROR:  syntax error at or near ")" (PG::SyntaxError)
    2024-10-17 08:58:11  LINE 1: ...T NULL AS "v" FROM (SHOW max_prepared_transactions) AS "t1" ...
    ...
    2024-10-17 08:58:11  	from /app/clover.rb:12:in `freeze'
    2024-10-17 08:58:11  	from config.ru:7:in `block (2 levels) in <top (required)>'
2024-10-17 12:15:05 +03:00

33 lines
1.6 KiB
Ruby

# frozen_string_literal: true
require "netaddr"
require "sequel/core"
require_relative "config"
require_relative "lib/util"
db_ca_bundle_filename = File.join(Dir.pwd, "var", "ca_bundles", "db_ca_bundle.crt")
Util.safe_write_to_file(db_ca_bundle_filename, Config.clover_database_root_certs)
DB = Sequel.connect(Config.clover_database_url, max_connections: Config.db_pool - 1, pool_timeout: Config.database_timeout).tap do |db|
# Replace dangerous (for cidrs) Ruby IPAddr type that is otherwise
# used by sequel_pg. Has come up more than once in the bug tracker:
#
# https://github.com/jeremyevans/sequel_pg/issues?q=inet
# https://github.com/jeremyevans/sequel_pg/issues/30
# https://github.com/jeremyevans/sequel_pg/pull/37
db.add_conversion_proc(650, NetAddr.method(:parse_net))
db.add_conversion_proc(869, NetAddr.method(:parse_ip))
end
postgres_monitor_db_ca_bundle_filename = File.join(Dir.pwd, "var", "ca_bundles", "postgres_monitor_db.crt")
Util.safe_write_to_file(postgres_monitor_db_ca_bundle_filename, Config.postgres_monitor_database_root_certs)
begin
POSTGRES_MONITOR_DB = Sequel.connect(Config.postgres_monitor_database_url, max_connections: Config.db_pool, pool_timeout: Config.database_timeout) if Config.postgres_monitor_database_url
rescue Sequel::DatabaseConnectionError => ex
Clog.emit("Failed to connect to Postgres Monitor database") { {database_connection_failed: {exception: Util.exception_to_hash(ex)}} }
end
# Load Sequel Database/Global extensions here
# DB.extension :date_arithmetic
DB.extension :pg_json, :pg_auto_parameterize, :pg_timestamptz, :pg_range, :pg_array
Sequel.extension :pg_range_ops