{"record":{"id":"8b71b7ea75908f6c","repo":"ankane/pghero","slug":"spec-not-found-config-spec","errorCode":null,"errorMessage":"Spec not found: #{config[\"spec\"]}","messagePattern":"Spec not found: #(.+?)","errorType":"exception","errorClass":"PgHero::Error","httpStatus":null,"severity":"error","filePath":"lib/pghero/database.rb","lineNumber":144,"sourceCode":"        unless @connection_model.connection_db_config.adapter.to_s.match?(/postg/i)\n          raise Error, \"Invalid connection URL\"\n        end\n        @adapter_checked = true\n      end\n\n      @connection_model\n    end\n\n    # just return the model\n    # do not start a connection\n    def build_connection_model\n      url = config[\"url\"]\n\n      # resolve spec\n      if !url && config[\"spec\"]\n        config_options = {env_name: PgHero.env, name: config[\"spec\"], include_hidden: true}\n        resolved = ActiveRecord::Base.configurations.configs_for(**config_options)\n        raise Error, \"Spec not found: #{config[\"spec\"]}\" unless resolved\n        url = resolved.configuration_hash\n      end\n\n      url = url.dup\n\n      Class.new(PgHero::Connection) do\n        def self.name\n          \"PgHero::Connection::Database#{object_id}\"\n        end\n\n        case url\n        when String\n          url = \"#{url}#{url.include?(\"?\") ? \"&\" : \"?\"}connect_timeout=5\" unless url.include?(\"connect_timeout=\")\n        when Hash\n          url[:connect_timeout] ||= 5\n        end\n        establish_connection url if url\n      end","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/ankane/pghero/blob/7edb57986ffd36f9d64f0830c4ccc90a5eac46d6/lib/pghero/database.rb#L126-L162","documentation":"When a database entry in pghero.yml has \"spec\" but no \"url\", build_connection_model resolves the spec against ActiveRecord::Base.configurations (database.yml) using configs_for(env_name: PgHero.env, name: spec, include_hidden: true). If no configuration matches that name in the current environment, PgHero raises Error \"Spec not found: {name}\" at database construction time.","triggerScenarios":"pghero.yml says spec: \"primary\" but database.yml names the entry differently (or only defines it under another env); RAILS_ENV/RACK_ENV differs between the environment that generated pghero.yml and the running one; a renamed or removed database config after a multi-database refactor. Note PgHero's default config derives spec names from database.yml automatically, so this usually appears after hand-editing.","commonSituations":"Rails 6+ three-tier database.yml where the same logical name exists only in some environments; promoting config from development to production; replicas/hidden configs where the name must match exactly (include_hidden covers visibility, not naming).","solutions":["Make the spec value match a database.yml configuration name exactly for the current environment","Or bypass spec resolution with an explicit url: postgres://user:pass@host:5432/dbname in pghero.yml","Check the environment: print PgHero.env and ActiveRecord::Base.configurations.configs_for(env_name: PgHero.env, include_hidden: true).map(&:name) in rails console"],"exampleFix":"# config/pghero.yml - before\ndatabases:\n  main:\n    spec: primary\n\n# after - match database.yml entry name exactly, or use a url\ndatabases:\n  main:\n    url: postgres://user:pass@host:5432/dbname","handlingStrategy":"validation","validationCode":"# verify every spec resolves before pghero builds its databases\nPgHero.config.fetch(\"databases\", {}).each do |id, db_config|\n  next if db_config[\"url\"] || !db_config[\"spec\"]\n  resolved = ActiveRecord::Base.configurations.configs_for(env_name: PgHero.env, name: db_config[\"spec\"], include_hidden: true)\n  raise \"pghero spec '#{db_config[\"spec\"]}' (database #{id}) not found in database.yml for #{PgHero.env}\" unless resolved\nend","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep pghero.yml spec names in lockstep with database.yml names per environment","Prefer explicit urls in pghero.yml for environments whose database.yml churns","Add a boot check that resolves all specs and fails the deploy on a miss"],"tags":["pghero","config","rails","database-yml"],"backgroundTag":"config-not-found","analyzedSha":"7edb57986ffd36f9d64f0830c4ccc90a5eac46d6","analyzedAt":"2026-08-21T17:33:54.942Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}