aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/railties
Commit message (Collapse)AuthorAgeFilesLines
* Add `environment` as dependency of `load_config` (#31135)Yuji Yaginuma2017-11-141-24/+24
| | | | | | | | | | | | Currently the environment is not loaded in some db tasks. Therefore, if use encrypted secrets values in `database.yml`, `read_encrypted_secrets` will not be true, so the value can not be used correctly. To fix this, added `environment` as dependency of `load_config`. It also removes explicit `environment` dependencies that are no longer needed. Fixes #30717
* Merge pull request #30414 from bogdanvlviv/clear-mysql_database_tasksRafael França2017-11-091-18/+0
|\ | | | | Simplify implementation of `MySQLDatabaseTasks`
| * Simplify implementation of `MySQLDatabaseTasks`bogdanvlviv2017-10-301-18/+0
| | | | | | | | | | | | Don't process MySQL ERROR 1045, raise error instead Make behavior of `MySQLDatabaseTasks` more consistent with behavior of `PostgreSQLDatabaseTasks`
* | Fix `bin/rails db:migrate` with specified `VERSION`bogdanvlviv2017-11-061-4/+15
|/ | | | | | 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.
* [Active Record] require => require_relativeAkira Matsuda2017-10-212-4/+4
| | | | This basically reverts 9d4f79d3d394edb74fa2192e5d9ad7b09ce50c6d
* Fix `bin/rails db:setup` and `bin/rails db:test:prepare` create wrong ↵bogdanvlviv2017-10-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | 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.
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-194-0/+8
|
* [Active Record] require => require_relativeAkira Matsuda2017-07-012-4/+4
|
* Also raise error when VERSION is nilRafael Mendonça França2017-04-271-2/+2
| | | | Fix #28905
* Fixes #28359Philippe Guay2017-03-261-2/+5
| | | | | | | | | | | | | | | | 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
* Fix `rake db:migrate:status` with subdirectoriesRyuta Kamizono2017-03-041-17/+2
| | | | | | | | | | | | `db:migrate` supports subdirectories and have a test. https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/test/cases/migrator_test.rb#L78-L85 But `db:migrate:status` doesn't work with subdirectories. It is due to `Dir.foreach(path)` is not the same with `Dir["#{path}/**/[0-9]*_*.rb"]`. I extracted `migration_files` and sharing it in the both to fix the issue. And added tests for `db:migrate:status`.
* Deprecate `supports_migrations?` on connection adaptersRyuta Kamizono2017-02-271-2/+1
| | | | | | | `supports_migrations?` was added at 4160b518 to determine if schema statements (`create_table`, `drop_table`, etc) are implemented in the adapter. But all tested databases has been supported migrations since a4fc93c3 at least.
* Remove deprecated db:test:clone* tasksRafael Mendonça França2017-01-031-24/+0
|
* Dump schema cache for custom connectionKir Shatrov2017-01-011-4/+1
| | | | | | | | | 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.
* Privatize unneededly protected methods in Active RecordAkira Matsuda2016-12-241-0/+2
|
* Describe what we are protectingAkira Matsuda2016-12-231-0/+2
|
* Use YAML to serialize schema cacheKir Shatrov2016-11-271-8/+8
|
* Add three new rubocop rulesRafael Mendonça França2016-08-161-1/+1
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* revises most Lint/EndAlignment offensesXavier Noria2016-08-071-7/+7
| | | | Some case expressions remain, need to think about those ones.
* applies remaining conventions across the projectXavier Noria2016-08-062-9/+9
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-2/+2
|
* modernizes hash syntax in activerecordXavier Noria2016-08-061-41/+41
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-062-65/+65
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Check if the logger exists before trying to use itRafael Mendonça França2016-07-171-1/+1
|
* issue FileUtils commands directly in Rake tasksXavier Noria2016-04-111-1/+1
| | | | | Rake includes (an extended version of) FileUtils in tasks. It is more idiomatic that they use this provided interface.
* Check for protected environments before trying to load structure.sql filePrathamesh Sonpatki2016-04-101-1/+1
| | | | | | - Check for protected environments while running `db:structure:load` similar to how `db:schema:load` behaves. - Followup of https://github.com/rails/rails/pull/24399.
* Prevent db:schema:load to protected environmentsJerry Cheung2016-04-011-1/+1
| | | | | | | Follow up to https://github.com/rails/rails/pull/22967 to protect against loading a schema on accident in production. cc @schneems
* Creates development and test databases in db:migrate taskRafael Mendonça França2016-03-141-2/+2
| | | | | | | | | | | | | | | | 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.
* Add environment back to db:structure:loadAndrew White2016-01-231-1/+1
| | | | | | Because of the changes in #22967 the assumption in #18907 is no longer true because the internal metadata feature for Active Record requires a working environment.
* Allow manually setting environment valueschneems2016-01-111-0/+6
| | | | | | | | If for some reason some one is not able to set the environment from a migration this gives us an escape valve to manually set the environment for the database see https://github.com/rails/rails/pull/22967#issuecomment-170251635. We will also fix the migration case, but this will ensure there is always a way to set the environment. cc/ @sgrif
* Merge pull request #22967 from schneems/schneems/generic-metadataSean Griffin2016-01-081-5/+13
|\ | | | | Prevent destructive action on production database
| * Prevent destructive action on production databaseschneems2016-01-071-5/+13
| | | | | | | | | | | | | | 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`.
* | Refer to rails command instead of rake in a bunch of placesDavid Heinemeier Hansson2015-12-181-1/+1
|/ | | | Still more to do. Please assist!
* Revert "Merge pull request #22502 from maclover7/remove-deprecation-notice"Arthur Neves2015-12-111-0/+8
| | | | | | | This reverts commit c2e70ca9b042a3461aac0dc073a80e84bd77eb57, reversing changes made to b0e5fc2737ed0b2f67f9b9538d01e084545493fd. this broke the build
* Merge pull request #22502 from maclover7/remove-deprecation-noticeArthur Nogueira Neves2015-12-111-8/+0
|\ | | | | Remove unused deprecation notice
| * Remove unused deprecation noticeJon Moss2015-12-051-8/+0
| | | | | | | | | | The `rake db:test:*` tasks were deprecated in #13528, but were undeprecated and added back in via #17739.
* | Make `db:migrate:status` to render `1_some.rb` format migrate files.yui-knk2015-11-021-5/+7
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `1_valid_people_have_last_names.rb` and `20150823202140_create_users.rb` are valid migration file name. But `1_valid_people_have_last_names.rb` is rendered as `********** NO FILE **********` when `rake db:migrate:status`. Fix to this bug, this commit includes * define some API private methdos and a Constant `match_to_migration_filename?`, `parse_migration_filename`, and `MigrationFilenameRegexp` * use these methods in `db:migrate:status` task Example: These files are in `db/migrate` * 1_valid_people_have_last_names.rb * 20150819202140_irreversible_migration.rb * 20150823202140_add_admin_flag_to_users.rb * 20150823202141_migration_tests.rb * 2_we_need_reminders.rb * 3_innocent_jointable.rb we can migrate all of them. Before ```shell $ bundle exec rake db:migrate:status ... Status Migration ID Migration Name -------------------------------------------------- up 001 ********** NO FILE ********** up 002 ********** NO FILE ********** up 003 ********** NO FILE ********** up 20150819202140 Irreversible migration up 20150823202140 Add admin flag to users up 20150823202141 Migration tests ``` After ```shell $ bundle exec rake db:migrate:status ... Status Migration ID Migration Name -------------------------------------------------- up 001 Valid people have last names up 002 We need reminders up 003 Innocent jointable up 20150819202140 Irreversible migration up 20150823202140 Add admin flag to users up 20150823202141 Migration tests ```
* fix typo in `db:purge` description [ci skip]yuuji.yaginuma2015-10-281-1/+1
|
* Fix out of sync commentBrandon Conway2015-09-231-1/+1
| | | It appears that as of version 4 the `db:test:prepare` task no longer depends on the `abort_if_pending_migrations` task, which leaves this comment out of sync.
* introduce `conn.data_source_exists?` and `conn.data_sources`.Yves Senn2015-09-221-1/+1
| | | | | | | | | | | | | | | | | These new methods are used from the Active Record model layer to determine which relations are viable to back a model. These new methods allow us to change `conn.tables` in the future to only return tables and no views. Same for `conn.table_exists?`. The goal is to provide the following introspection methods on the connection: * `tables` * `table_exists?` * `views` * `view_exists?` * `data_sources` (views + tables) * `data_source_exists?` (views + tables)
* Merge pull request #21529 from rngtng/move-migrations-paths-to-database-taskYves Senn2015-09-091-7/+7
|\ | | | | | | Use `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` explicit for db tasks
| * Use `ActiveRecord::Tasks::DatabaseTasks.migrations_paths` instead of ↵Tobias Bielohlawek2015-09-071-9/+8
|/ | | | `Migrator.migrations_paths`
* [ci skip] Replace `AR` with `Active Record` in task descyui-knk2015-09-071-1/+1
| | | | | Many user look `desc` of rake task and they are not familiar with `AR`. `Active Record` is more familiar word.
* follow-up to 2183caa, always reenable the task. #20743Yves Senn2015-06-301-3/+3
|
* `dump_schema_after_migration` applies migration tasks other than db:migrateYves Senn2015-06-301-9/+12
| | | | | | | | | | | | | Closes #20743. The task `db:_dump` now only dumps the schema if `ActiveRecord::Base.dump_schema_after_migration` is true. This has effects: - `db:migrate:up` - `db:migrate:down` - `db:forward` - `db:rollback`
* Fix descriptions of databases.rake [ci skip]Mehmet Emin İNAÇ2015-06-171-11/+11
| | | | revert create and drop task descriptions
* Small refactor on db:resetArthur Neves2015-06-151-4/+1
| | | | | | | | | | | | db:reset should not prematurely load the environment, so, for instance, if there is any initializer that touches th DB, it will not touch that before droping it. Also this makes the code simpler. This changed was made back in 15fb4302b6ff16e641b6279a3530eb8ed97f2899 , not sure why. But I am pretty much sure we should do it like this, as drop and setup should load its dependencies tasks if necessary.
* make sure to load_config for db:abort_if_pending_migrationsSteven Davidovitz2015-05-041-1/+1
|
* Revert "Merge pull request #17920 from ↵Yves Senn2015-04-271-1/+1
| | | | | | | | | | | | | | | calebthompson/dont-rely-on-environment-task-for-schema-load" This reverts commit 08ff4ccbbb3fb143a02e6752efb974a4bcfcd3bb, reversing changes made to 6c9ed6dbc62450cdb87559afd15798305e069146. Caused by #17920. Closes #19545. This patch introduced regressions because initializers were no longer loaded. Specifically missing inflections result in broken restores of the database.
* Don't invoke sql_runtime if logger is not set to infoeileencodes2015-04-041-1/+1
| | | | | | | | | `sql_runtime` was getting invoked even when the logger was set to fatal. This ensures that does not happen by checking that the logger is set to info level before logging the view runtime. This reduces the number of times `sql_runtime` is called for integration tests with a fatal logger from 6 to 2.