aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/tasks
Commit message (Collapse)AuthorAgeFilesLines
* 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] ```
* Merge pull request #30414 from bogdanvlviv/clear-mysql_database_tasksRafael França2017-11-091-74/+5
|\ | | | | Simplify implementation of `MySQLDatabaseTasks`
| * Simplify implementation of `MySQLDatabaseTasks`bogdanvlviv2017-10-301-72/+3
| | | | | | | | | | | | Don't process MySQL ERROR 1045, raise error instead Make behavior of `MySQLDatabaseTasks` more consistent with behavior of `PostgreSQLDatabaseTasks`
| * Raise error if unsupported charset for mysqlbogdanvlviv2017-10-301-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `blog$ bin/rails db:create` Before: ``` Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf42", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/var/run/mysqld/mysqld.sock", "database"=>"blog_development"}, {:charset=>"utf42"} (If you set the charset manually, make sure you have a matching collation) Created database 'blog_development' Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf42", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/var/run/mysqld/mysqld.sock", "database"=>"blog_test"}, {:charset=>"utf42"} (If you set the charset manually, make sure you have a matching collation) Created database 'blog_test' ``` After: ``` Unsupported charset: '"utf42"' Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf42", "pool"=>5, "username"=>"root", "password"=>nil, "socket"=>"/var/run/mysqld/mysqld.sock", "database"=>"blog_development"} rails aborted! Mysql2::Error: Unsupported charset: '"utf42"' ... (stack trace) ... bin/rails:4:in `<main>' Tasks: TOP => db:create (See full trace by running task with --trace) ``` Closes #29683 Related to #27398
* | 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.
* Unneeded Mocha stubs for Kernel#systemAkira Matsuda2017-09-251-2/+0
| | | | It's done inside each test via assert_called_with or Kernel.expects
* Fix `can't modify frozen String` error in `DatabaseTasks`yuuji.yaginuma2017-08-302-0/+35
| | | | | | | | | | | | | | | | | Without this, `db:structure:dump` task raises an error as follwing: ``` can't modify frozen String activerecord/lib/active_record/tasks/sqlite_database_tasks.rb:77:in `run_cmd_error' activerecord/lib/active_record/tasks/sqlite_database_tasks.rb:72:in `run_cmd' activerecord/lib/active_record/tasks/sqlite_database_tasks.rb:52:in `structure_dump' activerecord/lib/active_record/tasks/database_tasks.rb:219:in `structure_dump' activerecord/lib/active_record/railties/databases.rake:279:in `block (3 levels) in <main>' railties/lib/rails/commands/rake/rake_command.rb:23:in `block in perform' railties/lib/rails/commands/rake/rake_command.rb:20:in `perform' railties/lib/rails/command.rb:48:in `invoke' railties/lib/rails/commands.rb:18:in `<main>' ```
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-194-0/+8
|
* Revert "Merge pull request #29540 from kirs/rubocop-frozen-string"Matthew Draper2017-07-024-4/+0
| | | | | This reverts commit 3420a14590c0e6915d8b6c242887f74adb4120f9, reversing changes made to afb66a5a598ce4ac74ad84b125a5abf046dcf5aa.
* Enforce frozen string in RubocopKir Shatrov2017-07-014-0/+4
|
* pass `structure_dump_flags` / `structure_load_flags` options before any other:Edouard CHIN2017-06-211-2/+2
| | | | | | | - On Mysql, some command line options that affect option-file handling such as `--no-defaults` have to be passed before any other options - Modified rails to pass them right after the `mysql` command - Ref https://dev.mysql.com/doc/refman/5.7/en/option-file-options.html and https://bugs.mysql.com/bug.php?id=83386 - Ref #27437
* Remove a duplicate test of mysql_rake_testKoichi ITO2017-05-261-7/+0
|
* Respect 'ignore_tables' in SQLite structure dumpGuillermo Iguaran2017-05-151-0/+20
|
* Respect 'ignore_tables' in MySQL structure dumpGuillermo Iguaran2017-05-151-0/+16
|
* Respect `ignore_tables` in Postgres structure dumpRusty Geldmacher2017-05-151-0/+8
| | | | | | When using `sql` as the schema format, or even just doing `rake db:structure:dump`, it would be good to respect the list of ignored tables that has been configured.
* 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.
* Fix quoting in db:create grant all statement.Rune Schjellerup Philosof2017-04-201-1/+1
| | | | | | The database name used in the test would have actually shown this if it had tried to execute on a real Mysql instead of being stubbed out (dashes in database names needs quotes).
* 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
* Only remove comments before the first statementAri Pollak2017-02-241-3/+3
|
* Drop comments from structure.sql in postgresqlAri Pollak2017-02-241-3/+16
| | | | Fixes #28153.
* 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
* Remove duplicated testutilum2017-01-021-8/+0
| | | | | b8f74860b61782e3b949ade3bb51bff40899e89b provided a nicer version of `#test_structure_load` but the old version was not removed.
* 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.
* Merge pull request #27437 from kirs/structure-load-dump-flagsKasper Timm Hansen2016-12-293-4/+81
|\ | | | | Make ActiveRecord structure load/dump configurable
| * Make ActiveRecord structure load/dump configurableKir Shatrov2016-12-223-4/+81
| | | | | | | | | | | | | | | | 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.
* | assert_equal takes expectation firstAkira Matsuda2016-12-263-9/+9
|/
* 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.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-063-649/+649
|
* modernizes hash syntax in activerecordXavier Noria2016-08-064-14/+14
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-064-200/+200
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Merge pull request #23301 from ppworks/improve_mysqldumpArthur Nogueira Neves2016-06-171-4/+4
|\ | | | | Improve mysqldump
| * Skip comments when exec mysqldumpNaoto Koshikawa2016-01-281-4/+4
| |
* | PostgreSQL: Fix db:structure:load silent failure on SQL errorRalin Chimev2016-05-101-2/+2
| | | | | | | | | | | | | | | | The command line flag "-v ON_ERROR_STOP=1" should be used when invoking psql to make sure errors are not suppressed. Example: psql -v ON_ERROR_STOP=1 -q -f awesome-file.sql my-app-db Fixes #23818.
* | 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
* | Fix isolated test failures due to referencing ↵Jeremy Daer2016-04-183-0/+3
| | | | | | | | ActiveRecord::Tasks::DatabaseAlreadyExists before another test happened to make it available
* | Added notice when a database is successfully created or dropped.bogdanvlviv2016-04-174-10/+100
| |
* | 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-212-76/+72
| | | | | | | | Follow up to #22642.
* | Remove legacy mysql adapterAbdelkader Boudih2015-12-171-12/+12
|/
* Fix rake db:structure:dump on Postgres when multiple schemas are used.Nick Muerdter2015-11-191-2/+2
| | | | | | | | | | | | | | | | | | If postgresql is being used and there are multiple schemas listed on the `schema_search_path`, then `structure.sql` dumps (triggered by `rake db:structure:dump` or `config.active_record.schema_format = :sql`) began failing in Rails 4.2.5. This is due to the changes made in https://github.com/rails/rails/pull/17885 The problem is that multiple schemas were getting getting passed to `Kernel.system` as a single, space delimited string argument (for example, "--schema=foo --schema=bar"). However, with the updated array style of calling `Kernel.system`, these need to be passed as separate arguments (for example, "--schema=foo", "--schema=bar"). If they get passed as a single string, then the underlying pg_dump program isn't sure how to interpret that single argument and you'll get an error reporting: "pg_dump: No matching schemas were found"
* Fix test_database_created_by_root of mysqlyui-knk2015-11-021-1/+1
| | | | | | `DEFAULT_CHARSET` and `DEFAULT_COLLATION` in `MySQLDatabaseTasks` was changed by 322068fe85278ea26e26da6dfd7c5612dab15a72. This test case also should be changed.
* Remove `DEFAULT_CHARSET` and `DEFAULT_COLLATION` in `MySQLDatabaseTasks`Ryuta Kamizono2015-11-021-13/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit f6ca7e4e75408bc42f515fc7206d6c6ff0dce7c6. The default collation of utf8 in MySQL is the `utf8_general_ci`, and this should not be changed. This is because, the better collation in the all locales is not exists, optimal collation in own application is not known other than themselves. The `utf8_unicode_ci` is known as Japanese killer in Japan, there are serious impacts in search of Japanese. MySQL implements the `utf8_unicode_ci` according to the Unicode Collation Algorithm (UCA) described at http://www.unicode.org/reports/tr10/, but the `utf8_unicode_ci` have only partial support for the UCA, only primary level key comparison implemented (also known as L1 (Base characters) comparison). Because L1 (Base characters) comparison does not distinguish between the presence or absence of the accent, if distinction of the accent is important there is a serious impact (e.g. Japanese). Example: ``` > SHOW CREATE TABLE `dicts`\G *************************** 1. row *************************** Table: dicts Create Table: CREATE TABLE `dicts` ( `word` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL, `meaning` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci 1 row in set (0.00 sec) > INSERT INTO `dicts` VALUES ('ハハ', 'mother'), ('パパ', 'father'); Query OK, 2 rows affected (0.00 sec) > SELECT * FROM `dicts` WHERE `word` = 'ハハ'; +--------+---------+ | word | meaning | +--------+---------+ | ハハ | mother | | パパ | father | +--------+---------+ 2 rows in set (0.00 sec) > CREATE UNIQUE INDEX `unique_index_word` ON `dicts`(`word`); ERROR 1062 (23000): Duplicate entry 'ハハ' for key 'unique_index_word' ``` We should omit the collation entirely rather than providing a default. Then the choice is the responsibility of the server and MySQL distribution.