aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/tasks/mysql_database_tasks.rb
Commit message (Collapse)AuthorAgeFilesLines
* MySQL: Check error number instead of a messageyuuji.yaginuma2019-07-111-1/+3
| | | | To be able to check regardless of locale.
* Enable `Layout/EmptyLinesAroundAccessModifier` copRyuta Kamizono2019-06-131-1/+0
| | | | | | | | | | | We sometimes say "✂️ newline after `private`" in a code review (e.g. https://github.com/rails/rails/pull/18546#discussion_r23188776, https://github.com/rails/rails/pull/34832#discussion_r244847195). Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style `EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059). That cop and enforced style will reduce the our code review cost.
* Extract `truncate` and `truncate_tables` into database statementsRyuta Kamizono2019-03-171-10/+0
| | | | This is to easier make `truncate_tables` to bulk statements.
* Allow `truncate` for SQLite3 adapter and add `rails db:seed:replant` (#34779)Bogdan2019-03-041-0/+10
| | | | | | | | | | | | | * Add `ActiveRecord::Base.connection.truncate` for SQLite3 adapter. SQLite doesn't support `TRUNCATE TABLE`, but SQLite3 adapter can support `ActiveRecord::Base.connection.truncate` by using `DELETE FROM`. `DELETE` without `WHERE` uses "The Truncate Optimization", see https://www.sqlite.org/lang_delete.html. * Add `rails db:seed:replant` that truncates database tables and loads the seeds Closes #34765
* Enable `Performance/UnfreezeString` copyuuji.yaginuma2018-09-231-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In Ruby 2.3 or later, `String#+@` is available and `+@` is faster than `dup`. ```ruby # frozen_string_literal: true require "bundler/inline" gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end Benchmark.ips do |x| x.report('+@') { +"" } x.report('dup') { "".dup } x.compare! end ``` ``` $ ruby -v benchmark.rb ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] Warming up -------------------------------------- +@ 282.289k i/100ms dup 187.638k i/100ms Calculating ------------------------------------- +@ 6.775M (± 3.6%) i/s - 33.875M in 5.006253s dup 3.320M (± 2.2%) i/s - 16.700M in 5.032125s Comparison: +@: 6775299.3 i/s dup: 3320400.7 i/s - 2.04x slower ```
* Turn on performance based copsDillon Welch2018-07-231-3/+1
| | | | | | | | | | | | | | | | Use attr_reader/attr_writer instead of methods method is 12% slower Use flat_map over map.flatten(1) flatten is 66% slower Use hash[]= instead of hash.merge! with single arguments merge! is 166% slower See https://github.com/rails/rails/pull/32337 for more conversation
* Simplify implementation of `MySQLDatabaseTasks`bogdanvlviv2017-10-301-45/+0
| | | | | | 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-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `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
* [Active Record] require => require_relativeAkira Matsuda2017-10-211-1/+1
| | | | This basically reverts 9d4f79d3d394edb74fa2192e5d9ad7b09ce50c6d
* Use frozen-string-literal in ActiveRecordKir Shatrov2017-07-191-0/+2
|
* Merge branch 'master' into require_relative_2017Xavier Noria2017-07-021-1/+1
|\
| * 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.
| * Merge pull request #29540 from kirs/rubocop-frozen-stringMatthew Draper2017-07-021-0/+1
| |\ | | | | | | | | | Enforce frozen string in Rubocop
| | * Enforce frozen string in RubocopKir Shatrov2017-07-011-0/+1
| | |
| * | Merge pull request #29506 from pat/frozen-string-literalsMatthew Draper2017-07-021-1/+1
| |\ \ | | |/ | |/| | | | Make ActiveSupport frozen-string-literal friendly.
| | * Make ActiveRecord frozen string literal friendly.Pat Allan2017-06-201-1/+1
| | |
* | | [Active Record] require => require_relativeAkira Matsuda2017-07-011-1/+1
|/ /
* | PR ReviewEdouard CHIN2017-06-211-2/+2
| |
* | 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
* Respect 'ignore_tables' in MySQL structure dumpGuillermo Iguaran2017-05-151-0/+6
|
* 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).
* Make ActiveRecord structure load/dump configurableKir Shatrov2016-12-221-2/+4
| | | | | | | | 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.
* Use Regexp#match? rather than Regexp#===Ryuta Kamizono2016-10-261-1/+1
| | | | Follow up to 99cf7558000090668b137085bfe6bcc06c4571dc.
* Fix broken heredoc indentation caused by rubocop auto-correctRyuta Kamizono2016-09-031-1/+1
| | | | | | All indentation was normalized by rubocop auto-correct at 80e66cc4d90bf8c15d1a5f6e3152e90147f00772. But heredocs was still kept absolute position. This commit aligns heredocs indentation for consistency.
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-58/+58
|
* applies new string literal convention in activerecord/libXavier Noria2016-08-061-28/+28
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* systematic revision of =~ usage in ARXavier Noria2016-07-231-1/+1
| | | | | Where appropriatei, prefer the more concise Regexp#match?, String#include?, String#start_with?, or String#end_with?
* Merge pull request #23301 from ppworks/improve_mysqldumpArthur Nogueira Neves2016-06-171-0/+1
|\ | | | | Improve mysqldump
| * Skip comments when exec mysqldumpNaoto Koshikawa2016-01-281-0/+1
| |
* | Fix typo `--ssl-cipher`Ryuta Kamizono2016-03-061-1/+1
|/ | | | Follow up to #22543.
* Remove legacy mysql adapterAbdelkader Boudih2015-12-171-2/+0
|
* Remove `DEFAULT_CHARSET` and `DEFAULT_COLLATION` in `MySQLDatabaseTasks`Ryuta Kamizono2015-11-021-8/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Merge pull request #20569 from theSteveMitchell/masterYves Senn2015-09-221-9/+18
|\ | | | | | | Check mysql structure_load for errors
| * Check response of structure_load for mysql_database_tasks and make ↵Steve Mitchell2015-09-181-9/+19
|/ | | | structure_dump consistent
* Fix undefined method error on exceptionDavid Rodríguez2015-07-111-1/+1
| | | | | | The `error` method is not defined, in general, for exceptions. Instead, print the exception message. This error was hiding actual meaningful DB configuration errors. See http://stackoverflow.com/questions/18774463.
* Changed mysqldump to include sprocs and functionsJonathan Worek2015-05-221-0/+1
|
* Add full set of MySQL CLI options to support SSL authentication when using ↵Alex Coomans2015-05-121-9/+15
| | | | db:structure dump and load
* activerecord: rake db:create shows underlying error message.Paul Annesley2014-11-041-0/+1
|
* fix, mysql `db:purge` respects `Rails.env`.Yves Senn2014-07-241-1/+1
| | | | | | | | | | | | | | | | | | | | Previously this method always established a connection to the test database. This resulted in buggy behavior when combined with other tasks like `bin/rake db:schema:load`. This was one of the reasons why #15394 (22e9a91189af2c4e6217a888e77f22a23d3247d1) was reverted: > I’ve replicated it on a new app by the following commands: 1) rails generate model post:title, 2) rake db:migrate, 3) rake db:schema:load, 4) rails runner ‘puts Post.first’. The last command goes boom. Problem is that rake db:schema:load wipes the database, and then doesn’t actually restore it. This is all on MySQL. There’s no problem with SQLite. -- DHH https://github.com/rails/rails/commit/22e9a91189af2c4e6217a888e77f22a23d3247d1#commitcomment-6834245
* /mysql/i -> MySQL, Spell correct in continuation to #15555Akshay Vishnoi2014-06-141-1/+1
|
* Convert Fixnum into String the port number in MySQLKenta Okamoto2013-10-181-1/+2
|
* `rake db:create` does not change permissions of root user.Yves Senn2013-03-171-1/+3
| | | | | | | | Closes #8079. I had to rework some of the tests because the mock allowed any arguments for `connection.exeucte`. I think this is very dangerous as there could anything be executed without the tests noticing it.
* rake db:structure:dump warns when `mysqldump` is not in PATH.Yves Senn2013-03-061-1/+4
| | | | | | | | Closes #9518. The rake task used to fail silently and left an empty `structure.sql`. It's confusing for users to get to the root of the problem. The warning message tells them where to look.
* Improve mysql database tasks handling to ensure we always rescue from an ↵Carlos Antonio da Silva2013-01-151-9/+13
| | | | | | | | | | exception We were previously rescuing "nil" when no exception class was found. This does work in 1.9.3, but does not in 2.0, raising an exception asking for a class or module to be given to the rescue clause. Thanks @yahonda for catching this.
* Fix AR tests due to Mysql constant not being definedCarlos Antonio da Silva2013-01-121-5/+5
|
* Bring back "database already exists" messages when running rake tasksCarlos Antonio da Silva2013-01-121-9/+9
| | | | | | | | | | 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.
* Correct default charset/collation for mysql dbsJeremy Kemper2012-09-211-6/+9
|
* Use default charset/collation only if *neither* is specified. Otherwise we ↵Jeremy Kemper2012-09-211-4/+7
| | | | set utf8_unicode_ci collation on latin1 table.
* Use configuration['encoding'], because database configuration use not ↵kennyj2012-09-121-3/+3
| | | | charset but encoding.
* Use native mysqldump command for 'rake db:structure:dump'.kennyj2012-09-121-9/+19
|