aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/tasks/database_tasks_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Replace shallow mocks with Ruby classesutilum2018-07-101-1/+11
| | | | | | | While preparing this I realised that some stubbed returns values serve no purpose, so this patch drops those as well. Step 3 in #33162
* Reduce mocking by testing value instead of method callutilum2018-07-091-10/+22
| | | | Step 2 in #33162
* Remove unnecessary Mocha stubsutilum2018-07-071-6/+6
| | | | | | Step 1 in #33162 [utilum + bogdanvlviv]
* assert_called_withutilum2018-04-261-25/+38
|
* assert_calledutilum2018-04-261-20/+21
|
* assert_not_calledutilum2018-04-261-12/+12
|
* Fix two-level database configurations with URLsEugene Kenny2018-03-311-10/+52
| | | | | | | | | An entry in `ActiveRecord::Base.configurations` can either be a connection spec ("two-level") or a hash of specs ("three-level"). We were detecting two-level configurations by looking for the `database` key, but the database can also be specified as part of the `url` key, which meant we incorrectly treated those configurations as three-level.
* Add tests for new rake taskseileencodes2018-03-211-1/+128
|
* Revert "Merge pull request #32075 from eileencodes/delete-default-configuration"eileencodes2018-02-221-0/+16
| | | | | | | | | | This reverts commit 16f279ebd474626577ced858e3626ac4535a33df, reversing changes made to 6c6a30a7c357ce1eafa093d77d2b08684fe50887. The config can be named anything, not just default (although all generated apps will be named default). We can't just delete configs that don't have a database because that will break three-tier configs. Oh well.
* Delete default configurationeileencodes2018-02-211-16/+0
| | | | | | | 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.
* Refactor migration to move migrations paths to connectioneileencodes2018-01-181-41/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Clear dirty `schema_cache` after `dump_schema_cache`Ryuta Kamizono2017-12-151-0/+1
| | | | | | | `dump_schema_cache` fills `schema_cache` even if the test that modifies the schema has properly cleared the schema cache. Fixes #31463.
* Convert protected_environments to an array of stringsbogdanvlviv2017-12-121-2/+19
| | | | | | | These changes prevent ignoring environments name of which is a `Symbol` ``` config.active_record.protected_environments = ['staging', :production] ```
* Fix `bin/rails db:migrate` with specified `VERSION`bogdanvlviv2017-11-061-4/+145
| | | | | | Ensure that `bin/rails db:migrate` with specified `VERSION` reverts all migrations only if `VERSION` is `0`. Raise error if target migration doesn't exist.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-021-1/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
|
* Also raise error when VERSION is nilRafael Mendonça França2017-04-271-1/+2
| | | | Fix #28905
* Refactor DatabaseTasksMigrateTest#test_migrate_receives_correct_env_varsbogdanvlviv2017-04-261-1/+16
| | | | | Add cases to ensure that environment variables VERBOSE and VERSION have correct typecast.
* Fixes #28359Philippe Guay2017-03-261-0/+8
| | | | | | | | | | | | | | | | 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
* sqlite3_mem tests are broken since 79887593c18919fed49f441d64236362cb755872Akira Matsuda2017-01-101-0/+2
| | | | | since 79887593c18919fed49f441d64236362cb755872, create_all task recreates the connection to AR::Base which doesn't connect to the in_memory database that is set up for tests
* Dump schema cache for custom connectionKir Shatrov2017-01-011-0/+10
| | | | | | | | | 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.
* Make ActiveRecord structure load/dump configurableKir Shatrov2016-12-221-3/+3
| | | | | | | | 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.
* Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
|
* improve error message when include assertions failMichael Grosser2016-09-161-1/+1
| | | | | | assert [1, 3].includes?(2) fails with unhelpful "Asserting failed" message assert_includes [1, 3], 2 fails with "Expected [1, 3] to include 2" which makes it easier to debug and more obvious what went wrong
* Add three new rubocop rulesRafael Mendonça França2016-08-161-17/+17
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* modernizes hash syntax in activerecordXavier Noria2016-08-061-2/+2
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-73/+73
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* We are erroring due to nested transaction failures from mysql on ↵Vipul A M2016-05-061-0/+2
| | | | | | | | test_migrate_clears_schema_cache_afterward test. Disable transactions for this test. Fixes #24391
* Added notice when a database is successfully created or dropped.bogdanvlviv2016-04-171-0/+7
|
* Make 'migrate' clear the schema cache afterwardChris Arcand2016-03-241-2/+13
| | | | | | | | | | | | | | | | | | | 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).
* Creates development and test databases in db:migrate taskRafael Mendonça França2016-03-141-6/+14
| | | | | | | | | | | | | | | | This reverts a334425caff9b2140d5e99fcfc2eb8c4ab10bdfa. 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.
* Merge pull request #22967 from schneems/schneems/generic-metadataSean Griffin2016-01-081-0/+28
|\ | | | | Prevent destructive action on production database
| * Use hash like syntax for InternalMetadataschneems2016-01-081-1/+1
| | | | | | | | Discussion: https://github.com/rails/rails/pull/22967#discussion_r49137035
| * Prevent destructive action on production databaseschneems2016-01-071-0/+28
| | | | | | | | | | | | | | This PR introduces a key/value type store to Active Record that can be used for storing internal values. It is an alternative implementation to #21237 cc @sgrif @matthewd. It is possible to run your tests against your production database by accident right now. While infrequently, but as an anecdotal data point, Heroku receives a non-trivial number of requests for a database restore due to this happening. In these cases the loss can be large. To prevent against running tests against production we can store the "environment" version that was used when migrating the database in a new internal table. Before executing tests we can see if the database is a listed in `protected_environments` and abort. There is a manual escape valve to force this check from happening with environment variable `DISABLE_DATABASE_ENVIRONMENT_CHECK=1`.
* | Remove legacy mysql adapterRyuta Kamizono2015-12-211-1/+0
|/ | | | Follow up to #22642.
* Allow global migrations_path configuration with using value from ↵Tobias Bielohlawek2015-09-071-1/+3
| | | | database_tasks instead of Migrator
* Fixes reference for schema_format to AR::Base from AS::BaseJames Cox2015-03-031-0/+16
|
* schema loading rake tasks maintain database connection for current env.Yves Senn2014-09-031-0/+1
| | | | | | | | | | [Joshua Cody & Yves Senn] Closes #16757. Prior to this patch schema loading rake tasks had the potential to leak a connection to a different database. This had side-effects when rake tasks operating on the current connection (like `db:seed`) were chained.
* Add ActiveRecord::Tasks::DatabaseTasks.migrateJack Danger Canty2014-07-311-0/+13
| | | | | | This extracts the logic that was embedded in a Rake task into a static method. Bonus: the first test for `rake db:migrate`
* add `bin/rake db:purge` task to empty the current database.Yves Senn2014-06-171-0/+28
|
* fix typo in test method names. [ci skip]Yves Senn2014-06-171-4/+4
|
* create/drop test and development databases only if RAILS_ENV is nilDamien Mathieu2014-01-081-2/+24
| | | | Closes #13625
* Fix failure introduced from #13488schneems2013-12-251-1/+1
|
* require the files we testAaron Patterson2013-11-251-0/+1
|
* Abort a rake task when missing db/structure.sql like `db:schema:load` task.kennyj2013-05-011-0/+7
|
* Raise a specific exception with a useful message if a rake task is requested ↵Daniel Azuma2013-01-301-0/+6
| | | | for an unknown adapter
* Bring back "database already exists" messages when running rake tasksCarlos Antonio da Silva2013-01-121-7/+7
| | | | | | | | | | When running tasks such "rake db:setup", instead of showing messages like "db_development already exists", it was showing a big stack trace and a message "Couldn't create database for ..." with the configuration options, a very confusing message with a big trace. This brings back the functionality present in 3-2, showing the same message.
* Merge pull request #6838 from kennyj/added_registration_taskCarlos Antonio da Silva2012-07-071-0/+16
|\ | | | | Allow to register database tasks from different adapters
| * Added a feature to add a database task. e.g. OracleDatabaseTaskskennyj2012-06-241-0/+16
| |