aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/mysql2
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #22122 from ↵Sean Griffin2015-10-301-0/+28
|\ | | | | | | | | samphilipd/sam/manual_locking_on_schema_migrations Make migrations concurrent safe (using advisory locks)
| * Use advisory locks to prevent concurrent migrationsSam Davies2015-10-301-0/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Addresses issue #22092 - Works on Postgres and MySQL - Uses advisory locks because of two important properties: 1. The can be obtained outside of the context of a transaction 2. They are automatically released when the session ends, so if a migration process crashed for whatever reason the lock is not left open perpetually - Adds get_advisory_lock and release_advisory_lock methods to database adapters - Attempting to run a migration while another one is in process will raise a ConcurrentMigrationError instead of attempting to run in parallel with undefined behavior. This could be rescued and the migration could exit cleanly instead. Perhaps as a configuration option? Technical Notes ============== The Migrator uses generate_migrator_advisory_lock_key to build the key for the lock. In order to be compatible across multiple adapters there are some constraints on this key. - Postgres limits us to 64 bit signed integers - MySQL advisory locks are server-wide so we have to scope to the database - To fulfil these requirements we use a Migrator salt (a randomly chosen signed integer with max length of 31 bits) that identifies the Rails migration process as the owner of the lock. We multiply this salt with a CRC32 unsigned integer hash of the database name to get a signed 64 bit integer that can also be converted to a string to act as a lock key in MySQL databases. - It is important for subsequent versions of the Migrator to use the same salt, otherwise different versions of the Migrator will not see each other's locks.
* | Fix test failures caused by #19501Sean Griffin2015-10-291-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The first one is quite straightforward. We want to give the proper error message in the case where a top level constant exists, but we're looking for a nested one. We just need to port over the change to use `subclass.name` into these changes. The second set of failures, which are only present in the mysql adapter tests, are stranger to me. The failure occurs because we were previously comparing `subclass.name == self.name` instead of `subclass == self`. However, I don't think that we need to support creating anonymous classes which share a table with a class that uses STI, overrides `name` to return the same name as athe class that we have no other relationship with, when not assigned to a constant so it could never be used anyway... The commits around why that exist give no context, and I think they're just poorly written tests (WTF does `test_schema` mean anyway, and why does calling `.first` on some anonymous class test it?). We'll just disable STI on that class.
* | tests, no every adapter supports "connection.version"Yves Senn2015-10-291-11/+12
|/ | | | | | | | | | | | | | | | | | | | | | | | This solves the following issue: ``` $ bin/test Using sqlite3 /Users/senny/Projects/rails/activerecord/test/cases/adapters/mysql2/sp_test.rb:16:in `<class:Mysql2StoredProcedureTest>': undefined method `version' for #<ActiveRecord::ConnectionAdapters::SQLite3Adapter:0x007f8bab4b5b70> (NoMethodError) from /Users/senny/Projects/rails/activerecord/test/cases/adapters/mysql2/sp_test.rb:5:in `<top (required)>' from /Users/senny/Projects/rails/activesupport/lib/active_support/dependencies.rb:302:in `require' from /Users/senny/Projects/rails/activesupport/lib/active_support/dependencies.rb:302:in `block in require' from /Users/senny/Projects/rails/activesupport/lib/active_support/dependencies.rb:268:in `load_dependency' from /Users/senny/Projects/rails/activesupport/lib/active_support/dependencies.rb:302:in `require' from /Users/senny/Projects/rails/railties/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files' from /Users/senny/Projects/rails/railties/lib/rails/test_unit/test_requirer.rb:10:in `each' from /Users/senny/Projects/rails/railties/lib/rails/test_unit/test_requirer.rb:10:in `require_files' from /Users/senny/Projects/rails/railties/lib/rails/test_unit/minitest_plugin.rb:69:in `plugin_rails_init' from /Users/senny/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.3.3/lib/minitest.rb:73:in `block in init_plugins' from /Users/senny/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.3.3/lib/minitest.rb:71:in `each' from /Users/senny/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.3.3/lib/minitest.rb:71:in `init_plugins' from /Users/senny/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.3.3/lib/minitest.rb:122:in `run' from bin/test:19:in `<main>' ```
* Merge pull request #21932 from kamipo/add_stored_procedure_test_in_mysql2Sean Griffin2015-10-201-0/+29
|\ | | | | Add stored procedure test in mysql2
| * Add stored procedure test in mysql2Ryuta Kamizono2015-10-151-0/+29
| |
* | Fix to correctly schema dump the `tinyblob`Ryuta Kamizono2015-10-151-1/+1
|/ | | | | | Currently `tinyblob` is dumped to `t.binary "tiny_blob", limit: 255`. But `t.binary ... limit: 255` is generating SQL to `varchar(255)`. It is incorrect. This commit fixes this problem.
* Refactor `table_exists?` in AbstractMysqlAdapterRyuta Kamizono2015-09-201-8/+0
| | | | | | `table_exists?` calls `tables` twice when passed `'dbname.tblname'` arg. This change is that `table_exists?` execute only once query always and extra args of `tables` is removed.
* Merge pull request #17696 from kamipo/unsigned_integer_supportJeremy Daer2015-09-191-2/+37
|\ | | | | | | Add `unsigned` support for numeric data types in MySQL
| * Add `unsigned` types for numeric data types in MySQLRyuta Kamizono2015-09-181-0/+13
| | | | | | | | | | | | | | | | | | | | | | In the case of using `unsigned` as the type: create_table :foos do |t| t.unsigned_integer :unsigned_integer t.unsigned_bigint :unsigned_bigint t.unsigned_float :unsigned_float t.unsigned_decimal :unsigned_decimal, precision: 10, scale: 2 end
| * Add `unsigned` support for numeric data types in MySQLRyuta Kamizono2015-09-181-2/+24
| | | | | | | | | | | | | | | | | | | | | | Example: create_table :foos do |t| t.integer :unsigned_integer, unsigned: true t.bigint :unsigned_bigint, unsigned: true t.float :unsigned_float, unsigned: true t.decimal :unsigned_decimal, unsigned: true, precision: 10, scale: 2 end
* | Should test both mysql adaptersRyuta Kamizono2015-09-201-10/+8
|/ | | | | Some test cases are testing only mysql adapter. We should test mysql2 adapter also.
* Add a native JSON data type support in MySQLRyuta Kamizono2015-08-181-0/+172
| | | | | | | | | | As of MySQL 5.7.8, MySQL supports a native JSON data type. Example: create_table :json_data_type do |t| t.json :settings end
* use `assert_not` instead of `refute` as mentioned in our guides.Yves Senn2015-08-131-1/+1
| | | | | | | | | | | As described in the "Follow Coding Conventions" section in our contribution guide (http://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#follow-the-coding-conventions) we favor `assert_not` over `refute`. While we don't usually make stylistic changes on it's own I opted to do it in this case. The reason being that test cases are usually copied as a starting point for new tests. This results in a spread of `refute` in files that have been using it already.
* Remove @connection instance variable only when definedYasuo Honda2015-07-261-2/+2
|
* Ensure that microsecond precision is only used for version of mysql that ↵Jori Hardman2015-07-201-0/+21
| | | | support it. Fixes #19711
* make it possible to run AR tests with bin/testYves Senn2015-06-1114-75/+70
|
* If specify `strict: :default` explicitly, do not set sql_mode.Ryuta Kamizono2015-05-261-0/+9
| | | | Related with #17370.
* More exercise the create index sql testsRyuta Kamizono2015-05-041-0/+37
|
* Merge pull request #17569 from kamipo/dump_table_optionsRafael Mendonça França2015-05-031-0/+42
|\ | | | | | | Correctly dump `:options` on `create_table` for MySQL
| * Correctly dump `:options` on `create_table` for MySQLRyuta Kamizono2015-05-031-0/+42
| |
* | Remove unused requireRyuta Kamizono2015-05-031-1/+0
|/
* Use `use_transactional_tests` in Active RecordPrem Sichanugrist2015-04-101-1/+1
| | | | | | `use_transactional_fixtures` was deprecated in favor of `use_transactional_tests` in Rails 5.0. This removes one warning while running test suite.
* Merge pull request #17574 from kamipo/charset_collation_optionsJeremy Kemper2015-04-071-0/+54
|\ | | | | | | Add charset and collation options support for MySQL string and text columns.
| * Add `:charset` and `:collation` options support for MySQL string and text ↵Ryuta Kamizono2015-03-061-0/+54
| | | | | | | | | | | | | | | | | | | | | | columns Example: create_table :foos do |t| t.string :string_utf8_bin, charset: 'utf8', collation: 'utf8_bin' t.text :text_ascii, charset: 'ascii' end
* | Closes rails/rails#18864: Renaming transactional fixtures to transactional testsBrandon Weiss2015-03-163-3/+3
|/ | | | | | | | | | | | | | | | | | | | | | | | | I’m renaming all instances of `use_transcational_fixtures` to `use_transactional_tests` and “transactional fixtures” to “transactional tests”. I’m deprecating `use_transactional_fixtures=`. So anyone who is explicitly setting this will get a warning telling them to use `use_transactional_tests=` instead. I’m maintaining backwards compatibility—both forms will work. `use_transactional_tests` will check to see if `use_transactional_fixtures` is set and use that, otherwise it will use itself. But because `use_transactional_tests` is a class attribute (created with `class_attribute`) this requires a little bit of hoop jumping. The writer method that `class_attribute` generates defines a new reader method that return the value being set. Which means we can’t set the default of `true` using `use_transactional_tests=` as was done previously because that won’t take into account anyone using `use_transactional_fixtures`. Instead I defined the reader method manually and it checks `use_transactional_fixtures`. If it was set then it should be used, otherwise it should return the default, which is `true`. If someone uses `use_transactional_tests=` then it will overwrite the backwards-compatible method with whatever they set.
* Add `SchemaMigration.create_table` support any unicode charsets for MySQL.Ryuta Kamizono2015-02-261-2/+2
| | | | | | | | | | | | | | | | | MySQL unicode support is not only `utf8mb4`. Then, The index length problem is not only `utf8mb4`. http://dev.mysql.com/doc/refman/5.6/en/charset-unicode.html SELECT * FROM information_schema.character_sets WHERE maxlen > 3; +--------------------+----------------------+------------------+--------+ | CHARACTER_SET_NAME | DEFAULT_COLLATE_NAME | DESCRIPTION | MAXLEN | +--------------------+----------------------+------------------+--------+ | utf8mb4 | utf8mb4_general_ci | UTF-8 Unicode | 4 | | utf16 | utf16_general_ci | UTF-16 Unicode | 4 | | utf16le | utf16le_general_ci | UTF-16LE Unicode | 4 | | utf32 | utf32_general_ci | UTF-32 Unicode | 4 | +--------------------+----------------------+------------------+--------+
* Prefer `drop_table if_exists: true` over raw SQLRyuta Kamizono2015-02-181-1/+1
| | | | | Lowercase raw SQL has been replaced by 07b659c already. This commit replaces everything else of raw SQL.
* prefer `drop_table if_exists: true` over raw SQL.Yves Senn2015-02-181-1/+1
| | | | | | | /cc @yahonda This makes it easier for third party adapters to run our tests, even if that database does not support IF EXISTS.
* Extract `DateTimePrecisionTest`Ryuta Kamizono2015-02-131-84/+0
| | | | The datetime precision tests for any adapters is duplicated.
* Refactor microsecond precision to be database agnosticSean Griffin2015-02-102-14/+4
| | | | | | | | | | The various databases don't actually need significantly different handling for this behavior, and they can achieve it without knowing about the type of the object. The old implementation was returning a string, which will cause problems such as breaking TZ aware attributes, and making it impossible for the adapters to supply their logic for time objects.
* Respect the database default charset for `schema_migrations` table.Ryuta Kamizono2015-02-081-4/+12
| | | | | | The charset of `version` column in `schema_migrations` table is depend on the database default charset and collation rather than the encoding of the connection.
* tests, use `drop_table if_exists: true` in our test suite.Yves Senn2015-01-201-1/+1
|
* Merge pull request #18067 from ↵Rafael Mendonça França2015-01-021-0/+87
|\ | | | | | | | | | | | | | | | | kamipo/format_datetime_string_according_to_precision Format the datetime string according to the precision of the datetime field. Conflicts: activerecord/CHANGELOG.md
| * Format the datetime string according to the precision of the datetime field.Ryuta Kamizono2015-01-021-0/+17
| | | | | | | | | | | | | | | | | | Incompatible to rounding behavior between MySQL 5.6 and earlier. In 5.5, when you insert `2014-08-17 12:30:00.999999` the fractional part is ignored. In 5.6, it's rounded to `2014-08-17 12:30:01`: http://bugs.mysql.com/bug.php?id=68760
| * Allow precision option for MySQL datetimes.Ryuta Kamizono2015-01-021-0/+70
|/
* Stop relying on columns for type information in mysql2 casting testsSean Griffin2015-01-011-4/+2
| | | | | | The column itself has no actual impact on the return value. These were actually testing the behavior of the type object, which is sufficiently covered elsewhere.
* Go through normal `where` logic when preloading associationsSean Griffin2014-12-261-1/+1
| | | | | | | | | | This will allow eager type casting to take place as needed. There doesn't seem to be any particular reason that the `in` statement was forced for single values, and the commit message where it was introduced gives no context. See https://github.com/rails/rails/commit/d90b4e2615e8048fdeffc6dffe3246704adee01f
* Fix undesirable RangeError by Type::Integer. Add Type::UnsignedInteger.Ryuta Kamizono2014-12-121-0/+30
|
* Failure to rollback t.timestamps when within a change_table migrationnoam2014-12-031-1/+1
| | | | | | | | | | | | | When running the following migration: change_table(:table_name) { |t| t/timestamps } The following error was produced: wrong number of arguments (2 for 1) .... /connection_adapters/abstract/schema_statements.rb:851:in `remove_timestamps' This is due to `arguments` containing an empty hash as its second argument.
* Pass symbol as an argument instead of a blockErik Michaels-Ober2014-11-293-6/+4
|
* synchronize code and docs for `timestamps` and `add_timestamps`.Yves Senn2014-11-201-1/+1
| | | | | | | | This makes the following changes: * warn if `:null` is not passed to `add_timestamps` * `timestamps` method docs link to `add_timestamps` docs * explain where additional options go * adjust examples to include `null: false` (to prevent deprecation warnings)
* Build fix when running in isolationArun Agrawal2014-11-141-0/+1
| | | | | `Computer` class needs to be require See #17217 for more details
* add a truncate method to the connectionAaron Patterson2014-09-221-0/+13
| | | | | | it doesn't work on SQLite3 since it doesn't support truncate, but that's OK. If you call truncate on the connection, you're now bound to that database (same as if you use hstore or any other db specific feature).
* MySQL: skip GTID-unsafe statement tests when enforce_gtid_consistency is enabledJeremy Kemper2014-09-011-6/+8
|
* Clear schema cache before each testAkira Matsuda2014-09-011-0/+1
|
* MySQL: set connection collation along with the charsetJeremy Kemper2014-08-301-0/+5
| | | | | | | | | | Sets the connection collation to the database collation configured in database.yml. Otherwise, `SET NAMES utf8mb4` will use the default collation for that charset (utf8mb4_general_ci) when you may have chosen a different collation, like utf8mb4_unicode_ci. This only applies to literal string comparisons, not column values, so it is unlikely to affect you.
* Merge pull request #16481 from sgrif/sg-change-default-timestampsDavid Heinemeier Hansson2014-08-171-1/+1
|\ | | | | Change the default `null` value for timestamps
| * Change the default `null` value for timestampsSean Griffin2014-08-121-1/+1
| | | | | | | | | | | | | | As per discussion, this changes the model generators to specify `null: false` for timestamp columns. A warning is now emitted if `timestamps` is called without a `null` option specified, so we can safely change the behavior when no option is specified in Rails 5.
* | [ci skip] fix spelling of overrideAkshay Vishnoi2014-08-131-1/+1
|/