- 13 5月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
This is the opposite direction of #39039. #39111 fixes `minimum` and `maximum` on date columns with type casting by column type on the database. But column type has no information for time zone aware attributes, it means that attribute type should always be precedence over column type. I've realized that fact in the related issue report #39248. I've reverted the expectation of #39039, to make time zone aware attributes works.
-
- 10 5月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
Since MySQL 8.0.12, MySQL supports `ALGORITHM=INSTANT` DDL option. https://dev.mysql.com/doc/refman/8.0/en/innodb-online-ddl-operations.html#online-ddl-index-operations
-
由 Ryuta Kamizono 提交于
I've found the bug when I'm refactoring index creation code in #39203.
-
- 07 5月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
It is possible to unscope only the column in the specified table. ```ruby posts = Post.joins(:comments).group(:"posts.hidden") posts = posts.where("posts.hidden": false, "comments.hidden": false) posts.count # => { false => 10 } # unscope both hidden columns posts.unscope(where: :hidden).count # => { false => 11, true => 1 } # unscope only comments.hidden column posts.unscope(where: :"comments.hidden").count # => { false => 11 } ``` Co-authored-by: NSlava Korolev <korolvs@gmail.com>
-
- 05 5月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
```ruby steve = Person.find_by(name: "Steve") david = Author.find_by(name: "David") relation = Essay.where(writer: steve) # Before relation.rewhere(writer: david).to_a # => [] # After relation.rewhere(writer: david).to_a # => [david] ``` For now `rewhere` only works for truly column names, doesn't work for alias attributes, nested conditions, associations. To fix that, need to build new where clause first, and then get attribute names from new where clause.
-
由 akinomaeni 提交于
before ``` p Knot.create => #<Knot id: 1, created_at: "2016-05-05 01:29:47"> ``` after ``` p Knot.create => #<Knot id: 1, created_at: "2016-05-05 01:29:47.116928000"> ```
-
- 02 5月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
The type information for type casting is entirely separated to type object, so if anyone does passing a column to `type_cast` in Rails 6, they are likely doing something wrong. See the comment for more details: https://github.com/rails/rails/blob/28d815b89487ce4001a3f6f0ab684e6f9c017ed0/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb#L33-L42 This also deprecates passing legacy binds (an array of `[column, value]` which is 4.2 style format) to query methods on connection. That legacy format was kept for backward compatibility, instead of that, I've supported casted binds format (an array of casted values), it is easier to construct binds than existing two binds format.
-
- 30 4月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
`allowed_index_name_length` was used for internal temporary operations in SQLite3, since index name in SQLite3 must be globally unique and SQLite3 doesn't have ALTER TABLE feature (so it is emulated by creating temporary table with prefix). `allowed_index_name_length` was to reserve the margin for the prefix, but actually SQLite3 doesn't have a limitation for identifier name length, so the margin has removed at 36901e6e. Now `allowed_index_name_length` is no longer relied on by any adapter, so I'd like to remove the internal specific method which is no longer used.
-
- 27 4月, 2020 1 次提交
-
-
由 Ryuta Kamizono 提交于
`in_clause_length` was added at c5a284f8 to address to Oracle IN clause length limitation. Now `in_clause_length` is entirely integrated in Arel visitor since #35838 and #36074. Since Oracle visitors are the only code that rely on `in_clause_length`. so I'd like to remove that from Rails code base, like has removed Oracle visitors (#38946).
-
- 25 4月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
Currently, `count` and `average` always returns numeric value, but `sum`, `maximum`, and `minimum` not always return numeric value if aggregated on custom attribute type. I think that inconsistent behavior is surprising: ```ruby # All adapters except postgresql adapter are affected # by custom type casting. Book.group(:status).sum(:status) # => { "proposed" => "proposed", "published" => nil } ``` That is caused by fallback looking up cast type to `type_for(column)`. Now all supported adapters can return numeric value without that fallback, so I think we can remove that, it will also fix aggregate functions to return numeric value consistently.
-
由 Ryuta Kamizono 提交于
This allows to work `author.books.insert_all` as expected. Co-authored-by: NJosef Šimánek <josef.simanek@gmail.com>
-
- 20 4月, 2020 1 次提交
-
-
由 Islam Taha 提交于
Update activerecord changelog Specify DB name in changelog and fix typo
-
- 16 4月, 2020 1 次提交
-
-
由 eileencodes 提交于
This PR allows for passing `if_exists` options to the `remove_index` method so that we can ignore already removed indexes. This work follows column `if/if_not_exists` from #38352 and `:if_not_exists` on `add_index` from #38555. We've found this useful at GitHub, there are migrations where we don't want to raise if an index was already removed. This will allow us to remove a monkey patch on `remove_index`. I considered raising after the `index_name_for_remove` method is called but that method will raise if the index doesn't exist before we get to execute. I have a commit that refactors this but after much consideration this change is cleaner and more straightforward than other ways of implementing this. This change also adds a little extra validation to the `add_index` test. Fix `nodoc` on edited methods.
-
- 15 4月, 2020 2 次提交
-
-
由 Ryuta Kamizono 提交于
-
由 Ryuta Kamizono 提交于
This removes ibm_db, informix, mssql, oracle, and oracle12 Arel visitors which are not used in the code base. Actually oracle and oracle12 visitors are used at oracle-enhanced adapter, but now I think that those visitors should be in the adapter's repo like sqlserver adapter and the dedicated Arel visitor (https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/master/lib/arel/visitors/sqlserver.rb), otherwise it is hard to find a bug and review PRs for the oracle visitors (e.g. #35838, #37646), since we don't have knowledge and environment enough for Oracle.
-
- 14 4月, 2020 1 次提交
-
-
由 Josh 提交于
Previously, if `build_association` was called multiple times for a `has_one` association but never committed to the database, the first newly-associated record would trigger `touch` during the attempted removal of the record. For example: class Post < ActiveRecord::Base has_one :comment, inverse_of: :post, dependent: :destroy end class Comment < ActiveRecord::Base belongs_to :post, inverse_of: :comment, touch: true end post = Post.create! comment_1 = post.build_comment comment_2 = post.build_comment When `comment_2` is initialized, the `has_one` would attempt to destroy `comment_1`, triggering a `touch` on `post` from an association record that hasn't been committed to the database. This removes the attempt to delete an associated `has_one` unless it’s persisted.
-
- 29 3月, 2020 1 次提交
-
-
由 Prathamesh Sonpatki 提交于
When we try to create a table which already exists which also adds indexes, then the `if_not_exists` option passed to `create_table` is not extended to indexes. So the migration results into an error if the table and indexes already exist. This change extends the `if_not_exists` support to `add_index` so that if the migration tries to create a table which also has existing indexes, error won't be raised. Also as a side-effect individual `add_index` calls will also accept `if_not_exists` option and respect it henceforth. [Prathamesh Sonpatki, Justin George]
-
- 27 3月, 2020 1 次提交
-
-
由 eileencodes 提交于
This reverts commit f265e0dd, reversing changes made to 08dfa921. Reverted due to surprising behavior for applications. We need to deprecate this behavior first instead of raising by default.
-
- 25 3月, 2020 1 次提交
-
-
由 Alexey Vasiliev 提交于
-
- 21 3月, 2020 1 次提交
-
-
由 Joel Blum 提交于
fix insert_all enum test fix rubocop, change test to double quotes Update activerecord/test/cases/insert_all_test.rb fix inser_all_enum_values test: double quotes and order relation before pluck Co-Authored-By: NRyuta Kamizono <kamipo@gmail.com> change insert_all_enum_values test to not skip duplicates so it works across adapters
-
- 20 3月, 2020 1 次提交
-
-
由 eileencodes 提交于
With a multiple database application `db:rollback` becomes problematic. We can't rollback just the primary, that doesn't match the behavior in the other tasks. We can't rollback a migration for every database, that is unexpected. To solve this I handled `db:rollback` the same way I handled `:up` and `:down`. If `db:rollback` is called for a multi-db application then it will raise an error recommending you use `db:rollback:[NAME]` instead. Calling `db:rollback:primary` or `db:rollback:animals` will rollback the migration for the number of steps specified. Closes: #38513 Follow-up to: #34078
-
- 19 3月, 2020 3 次提交
-
-
由 Eugene Kenny 提交于
When called on a loaded relation, `pick` will now use the existing results instead of making another query, just like `pluck` does.
-
由 Dylan Thacker-Smith 提交于
If a transaction is wrapped in a Timeout.timeout(duration) block, then the transaction will be committed when the transaction block is exited from the timeout, since it uses `throw`. Ruby code doesn't have a way to distinguish between a block being exited from a `return`, `break` or `throw`, so fixing this problem for the case of `throw` would require a backwards incompatible change for block exited with `return` or `break`. As such, the current behaviour so it can be changed in the future.
-
由 Carlos Antonio da Silva 提交于
-
- 18 3月, 2020 1 次提交
-
-
由 ak 提交于
This behaviour is in rails/activerecord/lib/active_record/enum.rb #serialize(value) line no 143 if value is not present in mapping we are sending the value back , which in mysql returns unrelated record. I have changed to return nil is value is not present in mapping Implemented code review changes Improved test case coverage [ci skip] - cosmetic changes for better readibility of change log Signed-off-by: Nak <atulkanswal@gmail.com>
-
- 28 2月, 2020 2 次提交
-
-
由 Kyle Thompson 提交于
-
由 Kyle Thompson 提交于
-
- 27 2月, 2020 1 次提交
-
-
由 eileencodes 提交于
Behavior has not changed here but the previous API could be misleading to people who thought it would switch connections for only that class. `connected_to` switches the context from which we are getting connections, not the connections themselves. Co-authored-by: NJohn Crepezzi <john.crepezzi@gmail.com>
-
- 25 2月, 2020 4 次提交
-
-
由 Ryuta Kamizono 提交于
-
由 eileencodes 提交于
Applications can now connect to multiple shards and switch between their shards in an application. Note that the shard swapping is still a manual process as this change does not include an API for automatic shard swapping. Usage: Given the following configuration: ```yaml production: primary: database: my_database primary_shard_one: database: my_database_shard_one ``` Connect to multiple shards: ```ruby class ApplicationRecord < ActiveRecord::Base self.abstract_class = true connects_to shards: { default: { writing: :primary }, shard_one: { writing: :primary_shard_one } } ``` Swap between shards in your controller / model code: ```ruby ActiveRecord::Base.connected_to(shard: :shard_one) do # Read from shard one end ``` The horizontal sharding API also supports read replicas. See guides for more details. This PR also moves some no-doc'd methods into the private namespace as they were unnecessarily public. We've updated some error messages and documentation. Co-authored-by: NJohn Crepezzi <john.crepezzi@gmail.com>
-
由 eileencodes 提交于
I have so. many. regrets. about using `spec_name` for database configurations and now I'm finally putting this mistake to an end. Back when I started multi-db work I assumed that eventually `connection_specification_name` (sometimes called `spec_name`) and `spec_name` for configurations would one day be the same thing. After 2 years I no longer believe they will ever be the same thing. This PR deprecates `spec_name` on database configurations in favor of `name`. It's the same behavior, just a better name, or at least a less confusing name. `connection_specification_name` refers to the parent class name (ie ActiveRecord::Base, AnimalsBase, etc) that holds the connection for it's models. In some places like ConnectionHandler it shortens this to `spec_name`, hence the major confusion. Recently I've been working with some new folks on database stuff and connection management and realize how confusing it was to explain that `db_config.spec_name` was not `spec_name` and `connection_specification_name`. Worse than that one is a symbole while the other is a class name. This was made even more complicated by the fact that `ActiveRecord::Base` used `primary` as the `connection_specification_name` until #38190. After spending 2 years with connection management I don't believe that we can ever use the symbols from the database configs as a way to connect the database without the class name being _somewhere_ because a db_config does not know who it's owner class is until it's been connected and a model has no idea what db_config belongs to it until it's connected. The model is the only way to tie a primary/writer config to a replica/reader config. This could change in the future but I don't see value in adding a class name to the db_configs before connection or telling a model what config belongs to it before connection. That would probably break a lot of application assumptions. If we do ever end up in that world, we can use name, because tbh `spec_name` and `connection_specification_name` were always confusing to me.
-
由 Kyle Thompson 提交于
-
- 22 2月, 2020 1 次提交
-
-
由 Kevin Deisz 提交于
-
- 21 2月, 2020 1 次提交
-
-
由 Carlos Antonio da Silva 提交于
Follow-up of ac9b11a8.
-
- 20 2月, 2020 1 次提交
-
-
由 eileencodes 提交于
Add `#strict_loading` to any record to prevent lazy loading of associations. `strict_loading` will cascade down from the parent record to all the associations to help you catch any places where you may want to use `preload` instead of lazy loading. This is useful for preventing N+1's. Co-authored-by: NAaron Patterson <aaron.patterson@gmail.com>
-
- 06 2月, 2020 1 次提交
-
-
由 Sebastián Palma 提交于
indexes in a table. Currently the pg_class catalog is filtered out to retrieve the indexes in a table by its relkind value. Which in versions lower than 11 of PostgreSQL is always `i` (lower case). But since version 11, PostgreSQL supports partitioned indexes referenced with a relkind value of `I` (upper case). This makes any feature within the current code base to exclude those partitioned indexes. The solution proposed is to make use of the `IN` clause to filter those relkind values of `i` and/or `I` when retrieving a table indexes.
-
- 31 1月, 2020 1 次提交
-
-
由 Carlos Antonio da Silva 提交于
Follow-up c280ae72.
-
- 30 1月, 2020 1 次提交
-
-
由 eileencodes 提交于
This PR adds support for `if_exists` on `remove_column` and `if_not_exists` on `add_column` to support silently ignoring migrations if the remove tries to remove a non-existent column or an add tries to add an already existing column. We (GitHub) have custom monkey-patched support for these features and would like to upstream this behavior. This matches the same behavior that is supported for `create_table` and `drop_table`. The behavior for sqlite is different from mysql/postgres and sqlite for remove column and that is reflected in the tests.
-
- 29 1月, 2020 1 次提交
-
-
由 Larry Reid 提交于
-
- 24 1月, 2020 1 次提交
-
-
由 Carlos Antonio da Silva 提交于
Follow-up of 1ee4a881.
-