aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/adapters/mysql2/mysql2_adapter_test.rb
Commit message (Collapse)AuthorAgeFilesLines
* Rename error that occurs when writing on a readEileen Uchitelle2018-12-071-4/+4
| | | | | | | I originally named this `StatementInvalid` because that's what we do in GitHub, but `@tenderlove` pointed out that this means apps can't test for or explitly rescue this error. `StatementInvalid` is pretty broad so I've renamed this to `ReadOnlyError`.
* Add ability to prevent writes to a databaseEileen Uchitelle2018-11-301-0/+58
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This PR adds the ability to prevent writes to a database even if the database user is able to write (ie the database is a primary and not a replica). This is useful for a few reasons: 1) when converting your database from a single db to a primary/replica setup - you can fix all the writes on reads early on, 2) when we implement automatic database switching or when an app is manually switching connections this feature can be used to ensure reads are reading and writes are writing. We want to make sure we raise if we ever try to write in read mode, regardless of database type and 3) for local development if you don't want to set up multiple databases but do want to support rw/ro queries. This should be used in conjunction with `connected_to` in write mode. For example: ``` ActiveRecord::Base.connected_to(role: :writing) do Dog.connection.while_preventing_writes do Dog.create! # will raise because we're preventing writes end end ActiveRecord::Base.connected_to(role: :reading) do Dog.connection.while_preventing_writes do Dog.first # will not raise because we're not writing end end ```
* Fix `#columsn_for_distinct` of MySQL and PostgreSQLkg8m2018-02-271-5/+5
| | | | | | | Prevent `ActiveRecord::FinderMethods#limited_ids_for` from using correct primary key values even if `ORDER BY` columns include other table's primary key. Fixes #28364.
* 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
|
* `valid_type?` should accept only supported typesRyuta Kamizono2017-02-281-11/+0
| | | | | | | | | | | | | | | | | | | | `valid_type?` is used in schema dumper to determine if a type is supported. So if `valid_type?(:foobar)` is true, it means that schema dumper is allowed to create `t.foobar`. But it doesn't work. I think that `valid_type?` should accept only supported types. https://github.com/rails/rails/blob/v5.1.0.beta1/activerecord/lib/active_record/schema_dumper.rb#L135-L142 ```ruby columns.each do |column| raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" unless @connection.valid_type?(column.type) next if column.name == pk type, colspec = @connection.column_spec(column) tbl.print " t.#{type} #{column.name.inspect}" tbl.print ", #{format_colspec(colspec)}" if colspec.present? tbl.puts end ```
* Make pg adapter use bigserial for pk by defaultPavel Pravosud2016-12-051-0/+13
|
* normalizes indentation and whitespace across the projectXavier Noria2016-08-061-3/+3
|
* applies new string literal convention in activerecord/testXavier Noria2016-08-061-7/+7
| | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* Dont simply assume a type is a valid database type. This is only always true ↵Vipul A M2016-04-251-0/+11
| | | | | | | in the case of sqlite. Others adapters need to perform a check for validity. Add coverage for mysql2 db type validation
* Fix `NoMethodError: undefined method `fields' for nil:NilClass`Ryuta Kamizono2016-02-291-0/+18
| | | | | | | | | | | | | | | | | Currently `exec_query` raises `NoMethodError` when executing no result queries (`INSERT`, `UPDATE`, `DELETE`, and all DDL) in mysql2 adapter. ``` irb(main):002:0> conn.execute("create table t(a int)") (43.3ms) create table t(a int) => nil irb(main):003:0> conn.execute("insert into t values (1)") (19.3ms) insert into t values (1) => nil irb(main):004:0> conn.exec_query("insert into t values (1)") SQL (28.6ms) insert into t values (1) NoMethodError: undefined method `fields' for nil:NilClass ```
* Add `columns_for_distinct` for MySQL 5.7 with ONLY_FULL_GROUP_BYRyuta Kamizono2015-12-231-0/+44
In MySQL 5.7.5 and up, ONLY_FULL_GROUP_BY affects handling of queries that use DISTINCT and ORDER BY. It requires the ORDER BY columns in the select list for distinct queries, and requires that the ORDER BY include the distinct column. See https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html