1. 22 3月, 2018 1 次提交
    • E
      Add ability to create/drop/migrate all dbs for a given env · 5eb4488d
      eileencodes 提交于
      `each_current_configuration` is used by create, drop, and other methods
      to find the configs for a given environment and returning those to the
      method calling them.
      
      The change here allows for the database commands to operate on all the
      configs in the environment. Previously we couldn't slice the hashes and
      iterate over them becasue they could be two tier or could be three
      tier. By using the database config structs we don't need to care whether
      we're dealing with a three tier or two tier, we can just parse all the
      configs based on the environment.
      
      This makes it possible for us to run `bin/rails db:create` and it will
      create all the configs for the dev and test environment ust like it does
      for a two tier - it creates the db for dev and test. Now `db:create`
      will create `primary` for dev and test, and `animals` for dev and test
      if our database.yml looks like:
      
      ```
      development:
        primary:
          etc
        animals:
          etc
      
      test:
        primary:
          etc
        animals:
          etc
      ```
      
      This means that `bin/rails db:create`, `bin/rails db:drop`, and
      `bin/rails db:migrate` will operate on the dev and test env for both
      primary and animals ds.
      5eb4488d
  2. 02 3月, 2018 1 次提交
  3. 23 2月, 2018 1 次提交
  4. 22 2月, 2018 1 次提交
    • E
      Delete default configuration · bf0495de
      eileencodes 提交于
      Because of this default configuration we're constantly checking if the
      database exists when looping through configurations. This is unnecessary
      and we should just delete it before we need to loop through
      configurations.
      bf0495de
  5. 06 2月, 2018 2 次提交
    • E
      Don't output information on drop if not verbose · 1dfc3a24
      eileencodes 提交于
      Followup to b988ecb9, when I cherry-picked from my parallel testing
      branch I didn't realize `drop` wasn't part of the commit.
      1dfc3a24
    • E
      Add ability to turn off verbose for database tasks · b988ecb9
      eileencodes 提交于
      You could use the `VERBOSE` env var to turn off output for migrations
      tasks but you couldn't use it for other tasks.
      
      This change moves the `verbose?` check to a method so we can also use it
      in create and drop respectively.
      
      tenderlove and I noticed this as part of the ongoing work in parallel
      testing. When the parallel tests boot the app needs to create new
      databases for each worker. The output from these is unnecessary but
      there was previously no way to turn it off. Now if `VERBOSE=false` is
      passes to `bin/rails db:create` the text "Created blah blah db" will no
      longer be output.
      b988ecb9
  6. 19 1月, 2018 1 次提交
  7. 18 1月, 2018 1 次提交
    • E
      Refactor migration to move migrations paths to connection · a2827ec9
      eileencodes 提交于
      Rails has some support for multiple databases but it can be hard to
      handle migrations with those. The easiest way to implement multiple
      databases is to contain migrations into their own folder ("db/migrate"
      for the primary db and "db/seconddb_migrate" for the second db). Without
      this you would need to write code that allowed you to switch connections
      in migrations. I can tell you from experience that is not a fun way to
      implement multiple databases.
      
      This refactoring is a pre-requisite for implementing other features
      related to parallel testing and improved handling for multiple
      databases.
      
      The refactoring here moves the class methods from the `Migrator` class
      into it's own new class `MigrationContext`. The goal was to move the
      `migrations_paths` method off of the `Migrator` class and onto the
      connection. This allows users to do the following in their
      `database.yml`:
      
      ```
      development:
        adapter: mysql2
        username: root
        password:
      
      development_seconddb:
        adapter: mysql2
        username: root
        password:
        migrations_paths: "db/second_db_migrate"
      ```
      
      Migrations for the `seconddb` can now be store in the
      `db/second_db_migrate` directory. Migrations for the primary database
      are stored in `db/migrate`".
      
      The refactoring here drastically reduces the internal API for migrations
      since we don't need to pass `migrations_paths` around to every single
      method. Additionally this change does not require any Rails applications
      to make changes unless they want to use the new public API. All of the
      class methods from the `Migrator` class were `nodoc`'d except for the
      `migrations_paths` and `migrations_path` getter/setters respectively.
      a2827ec9
  8. 07 11月, 2017 1 次提交
  9. 16 10月, 2017 2 次提交
    • B
      `ActiveRecord::Tasks::DatabaseTasks.load_schema` has always to establish database connection · 678e563d
      bogdanvlviv 提交于
        When load schema from `structure.sql`, database connection isn't
        established. `ActiveRecord::Tasks::DatabaseTasks.load_schema` has to
        establish database connection since it executes
        ```
        ActiveRecord::InternalMetadata.create_table
        ActiveRecord::InternalMetadata[:environment] = environment
        ```
      678e563d
    • B
      Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong... · 99b2bf8d
      bogdanvlviv 提交于
      Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create  wrong ar_internal_metadata's data for a test database.
      
        Before:
        ```
        $ RAILS_ENV=test rails dbconsole
        > SELECT * FROM ar_internal_metadata;
        key|value|created_at|updated_at
        environment|development|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
        ```
      
        After:
        ```
        $ RAILS_ENV=test rails dbconsole
        > SELECT * FROM ar_internal_metadata;
        key|value|created_at|updated_at
        environment|test|2017-09-11 23:14:10.815679|2017-09-11 23:14:10.815679
        ```
      
        Fixes #26731.
      99b2bf8d
  10. 24 7月, 2017 1 次提交
    • E
      Avoid modifying frozen string in check_schema_file · 2b331e90
      Eugene Kenny 提交于
      This was missed when the frozen string literal pragma was added to this
      file because the string is only modified when running in the context of
      a full Rails app, which wasn't covered by the test suite.
      2b331e90
  11. 20 7月, 2017 1 次提交
  12. 11 7月, 2017 1 次提交
    • K
      * Don't eagerly require Rails' minitest plugin. · 0d72489b
      Kasper Timm Hansen 提交于
      By making the Rails minitest behave like a standard minitest plugin
      we're much more likely to not break when people use other minitest
      plugins. Like minitest-focus and pride.
      
      To do this, we need to behave like minitest: require files up front
      and then perform the plugin behavior via the at_exit hook.
      This also saves us a fair bit of wrangling with test file loading.
      
      Finally, since the environment and warnings options have to be applied
      as early as possible, and since minitest loads plugins at_exit, they
      have to be moved to the test command.
      
      * Don't expect the root method.
      
      It's likely this worked because we eagerly loaded the Rails minitest plugin
      and that somehow defined a root method on `Rails`.
      
      * Assign a backtrace to failed exceptions.
      
      Otherwise Minitest pukes when attempting to filter the backtrace (which
      Rails' backtrace cleaner then removes).
      
      Means the exception message test has to be revised too.
      
      This is likely caused by the rails minitest plugin now being loaded for
      these tests and assigning a default backtrace cleaner.
      0d72489b
  13. 02 7月, 2017 1 次提交
  14. 01 7月, 2017 1 次提交
  15. 24 5月, 2017 1 次提交
  16. 11 5月, 2017 1 次提交
    • A
      Defer loading each DB Tasks class from AR DatabaseTasks · f73b8456
      Akira Matsuda 提交于
      Because we don't need to load tasks for DBs that we don't use for the current app.
      Also, these Tasks classes load AR::Base in their class level, and so immediately kick :active_record on_load hooks.
      This used to happen when we were loading tasks, not when we run a task.
      f73b8456
  17. 27 4月, 2017 1 次提交
  18. 27 3月, 2017 1 次提交
    • P
      Fixes #28359 · 14739b5e
      Philippe Guay 提交于
      Add stronger assertions to rake migration tasks to make sure the user is providing a numeric VERSION
      An empty string was getting converted to version = 0. This would in turn pass the presence check.
      
      Address linting warning
      
      Add test for rake task and refactor code to meet expectations
      In particular passing VERSION=0 should not raise an error.
      
      Addressed Comments for PR #28485. Trimmed empty lines + change of wording for error message
      
      Adjust test for change of wording in error message
      
      Change condition to follow rails idioms
      14739b5e
  19. 12 1月, 2017 1 次提交
  20. 04 1月, 2017 1 次提交
  21. 02 1月, 2017 1 次提交
    • K
      Dump schema cache for custom connection · 6cd75796
      Kir Shatrov 提交于
      Today `rake db:schema:cache:dump` only supports dumping cache for a
      single connection (`ActiveRecord::Base.connection`). This doesn't work
      for apps with multiple databases.
      
      This PR makes `DatabaseTasks` to provide an API for dumping schema cache
      for any connection.
      6cd75796
  22. 30 12月, 2016 1 次提交
  23. 23 12月, 2016 1 次提交
    • K
      Make ActiveRecord structure load/dump configurable · b8f74860
      Kir Shatrov 提交于
      Without this patch it's impossible to pass extra flags to
      mysqldump/pg_dump when running `rake db:structure:dump` or `load`
      
      The following config variables (`structure_load_flags` and `structure_dump_flags`)
      make it better configurable.
      b8f74860
  24. 29 10月, 2016 1 次提交
  25. 08 8月, 2016 1 次提交
  26. 07 8月, 2016 3 次提交
  27. 25 5月, 2016 2 次提交
  28. 07 5月, 2016 1 次提交
  29. 06 5月, 2016 2 次提交
  30. 18 4月, 2016 1 次提交
  31. 25 3月, 2016 1 次提交
    • C
      Make 'migrate' clear the schema cache afterward · 16dadb12
      Chris Arcand 提交于
      Without clearing the caches afterward, removals done in migrations would
      not be reflected in a separate task in the same process. That is, given
      a table with a migration to remove a column, the schema cache would
      still reflect that a table has that in something such as the
      'db:seed' task:
      
      `rake db:migrate db:seed`
      (A common thing to do in a script for a project ala `bin/setup`)
      
      vs
      
      `rake db:migrate && rake db:seed`
      (Two processes)
      
      The first would not reflect that the column was removed.
      The second would (cache reset).
      16dadb12
  32. 15 3月, 2016 1 次提交
    • R
      Creates development and test databases in db:migrate task · 6ca9031b
      Rafael Mendonça França 提交于
      This reverts a334425c.
      
      The main reason is that now the workflow is inconsistent when using
      spring.
      
      When using spring `RAILS_ENV` is always set, so only one database is
      created.
      
      This means that in development `bin/rake db:create` and `bundle exec
      rake db:create` have different results.
      
      It also breaks the `bin/setup` script since `bin/rake db:setup
      db:test:prepare` will fail.
      6ca9031b
  33. 24 2月, 2016 1 次提交
  34. 09 1月, 2016 1 次提交