1. 17 3月, 2018 5 次提交
    • G
      Merge pull request #32275 from elainefang/fix-grammar · ef73318e
      George Claghorn 提交于
      Fix grammar in Getting Started with Rails
      ef73318e
    • E
      Fix grammar in Getting Started with Rails · aa8f51b9
      ef718 提交于
      aa8f51b9
    • E
      Merge pull request #32271 from eileencodes/fix-three-tier-default-connection · 9700dacf
      Eileen M. Uchitelle 提交于
      Fix default connection handling with three-tier config
      9700dacf
    • E
      Switch dbconsole config loader check · 4027643f
      eileencodes 提交于
      In a three-tier config environment
      `configurations[environment].presence` will return `{ :primary => {
      :key => value, :key => value }, :secondary => { :key => value, :key =>
      value} }, which means it's not given a single config to connect to.
      
      If we flip these however it will connect to primary because that's the
      default connection, and on a two tier it will be `nil` so the code will
      select the connection from the configurations rather than the
      connection.
      4027643f
    • E
      Fix connection handling with three-tier config · 03929463
      eileencodes 提交于
      If you had a three-tier config, the `establish_connection` that's called
      in the Railtie on load can't figure out how to access the default
      configuration.
      
      This is because Rails assumes that the config is the first value in the
      hash and always associated with the key from the environment. With a
      three tier config however we need to go one level deeper.
      
      This commit includes 2 changes. 1) removes a line from `resolve_all`
      which was parsing out the the environment from the config so instead of
      getting
      
      ```
      {
        :development => {
          :primary => {
            :database => "whatever"
          }
        },
          :animals => {
            :database => "whatever-animals"
          }
        },
        etc with test / prod
      }
      ```
      
      We'd instead end up with a config that had no attachment to it's
      envioronment.
      
      ```
      {
        :primary => {
          :database => "whatever"
        }
        :animals => {
          :database => "whatever-animals"
        }
        etc - without test and prod
      }
      ```
      
      Not only did this mean that Active Record didn't know how to establish a
      connection, it didn't have the other necessary configs along with it in
      the configs list.
      
      So fix this I removed the line that deletes these configs.
      
      The second thing this commit changes is adding this line to
      `establish_connection`
      
      ```
      spec = spec[spec_name.to_sym] if spec[spec_name.to_sym]
      ```
      
      When you have a three-tier config and don't pass any hash/symbol/env etc
      to `establish_connection` the resolver will automatically return both
      the primary and secondary (in this case animals db) configurations.
      We'll get an `database configuration does not specify adapter` error
      because AR will try to establish a connection on the `primary` key
      rather than the `primary` key's config. It assumes that the
      `development` or default env automatically will return a config hash,
      but with a three-tier config we actually get a key and config `primary
      => config`.
      
      This fix is a bit of a bandaid because it's not the "correct" way to
      handle this situation, but it does solve our immediate problem. The new
      code here is saying "if the config returned from the resolver (I know
      it's called spec in here but we interchange our meanings a LOT and what
      is returned is a three-tier config) has a key matching the "primary"
      spec name, grab the config from the spec and pass that to the
      estalbish_connection method".
      
      This works because if we pass `:animals` or a hash, or `:primary` we'll
      already have the correct configuration to connect with.
      
      This fixes the case where we want Rail to connect with the default
      connection.
      
      Coming soon is a refactoring that should eliminate the need to do this
      but I need this fix in order to write the multi-db rake tasks that I
      promised in my RailsConf submission. `@tenderlove` and I are working on
      the refactoring of the internals for connection management but it won't
      be ready for a few weeks and this issue has been blocking progress.
      03929463
  2. 16 3月, 2018 8 次提交
  3. 15 3月, 2018 4 次提交
  4. 14 3月, 2018 12 次提交
  5. 13 3月, 2018 10 次提交
  6. 12 3月, 2018 1 次提交