Commit Graph

89149 Commits

Author SHA1 Message Date
Stephen Margheim
236a144b50 Allow SQLite3 busy_handler to be configured with simple max number of retries
Retrying busy connections without delay is a preferred practice for performance-sensitive applications. Add support for a `database.yml` `retries` integer, which is used in a simple `busy_handler` function to retry busy connections without exponential backoff up to the max number of `retries`
.
2023-09-22 11:55:05 +02:00
Ryuta Kamizono
d39ea2b2cd
Merge pull request #49344 from aidanharan/skip-tests-unless-supports-insert-on-duplicate-update
Skip unless adapter supports insert on duplicate update
2023-09-22 15:58:02 +09:00
Xavier Noria
26d24d6dc3 Let these example match the ones in config/application.rb 2023-09-21 21:20:23 +02:00
Xavier Noria
8eed5083b7 Reword stuff related to config.autoload_lib 2023-09-21 21:14:03 +02:00
Carlos Antonio da Silva
c864a37550
Merge pull request #49338 from jean-francois-labbe/document-rails-new-with-specific-version
[ci skip] Document how to rails new with a specific version
2023-09-21 15:09:10 -03:00
Jean-Francois Labbé
90d5a5c2ab [CI skip] Update rails new USAGE with specific version request 2023-09-21 20:00:49 +02:00
Hartley McGuire
23f130c2f3
Merge pull request #49342 from skipkayhil/hm-doc-callbacks
Add links to Callbacks, note example definition [ci skip]
2023-09-21 11:10:19 -04:00
Carlos Antonio da Silva
585e0ca284
Merge pull request #49345 from aidanharan/regex-escape-remove-adapter-check
Cleaned up test that was missing regex escaping
2023-09-21 11:38:17 -03:00
Aidan Haran
e985cb2a75 Regex escape the table columns in query 2023-09-21 11:14:41 +01:00
Aidan Haran
4381416f59 Skip unless adapter supports insert on duplicate update 2023-09-21 10:40:03 +01:00
Jean Boussier
d56db8ff17
Merge pull request #49335 from Shopify/remove-ar-case-equal
Get rid of ActiveRecord::Core#===
2023-09-21 09:26:58 +02:00
Jean Boussier
31482d2867 Get rid of ActiveRecord::Core#===
This was added back in 0.9.5 because at the time single associations (e.g. has_one)
didn't directly return the record but a proxy

https://github.com/rails/rails/commit/97849debf33

But toaward 3.1, we got rid of that proxy: 1644663ba7
and the associated test was deleted.

However the `===` method stayed.

This has been around for so long that removing it may
break some rare applications, but I doubt it would be hard to
fix, and this isn't a documented behavior.

Co-Authored-By: Nate Matykiewicz <natematykiewicz@gmail.com>
2023-09-21 08:53:28 +02:00
Hartley McGuire
b5dbcb1a3e
Add links to Callbacks, note example definition
Reading this doc left me confused where PersonRecord was defined, this
commit is intended to make it easier to find where it is.
2023-09-20 21:54:31 -04:00
hachi8833
4fb4af7312 [Docs][Tests] Add tests for validates_exclusion_of to 7.1.0beta1 Active Model 2023-09-21 10:33:58 +09:00
Aaron Patterson
0f92f8bf91
Merge pull request #49290 from fractaledmind/ar-sqlite3-returning-columns
Add SQLite3 support for `supports_insert_returning?`
2023-09-20 16:21:39 -07:00
Hartley McGuire
35b280fcc2
Refactor Router#find_routes to be lazier
Previously, `#find_routes` would take all of the routes that match the
current request and eagerly generate `MatchData` and `path_parameters`
for each route.

This commit changes `#find_routes` to only perform the computation one
route at a time, since the computation will never be needed for routes
in the list after `#serve` returns.

This change improves the performance of `RouteSet#call` by ~10% when
`#find_routes` finds two routes, and ~60% when `#find_routes` finds ten
routes.

Before:

```
Warming up --------------------------------------
  10 matching routes     1.182k i/100ms
   2 matching routes     1.967k i/100ms
   1 matching routes     2.221k i/100ms
Calculating -------------------------------------
  10 matching routes     11.846k (± 3.7%) i/s -     60.282k in   5.095922s
   2 matching routes     19.871k (± 3.5%) i/s -    100.317k in   5.054796s
   1 matching routes     21.904k (± 3.8%) i/s -    111.050k in   5.077449s

Comparison:
   1 matching routes:    21904.0 i/s
   2 matching routes:    19870.6 i/s - 1.10x  slower
  10 matching routes:    11845.9 i/s - 1.85x  slower
```

After:

```
Warming up --------------------------------------
  10 matching routes     1.888k i/100ms
   2 matching routes     2.215k i/100ms
   1 matching routes     2.312k i/100ms
Calculating -------------------------------------
  10 matching routes     18.623k (± 3.7%) i/s -     94.400k in   5.076043s
   2 matching routes     22.210k (± 3.6%) i/s -    112.965k in   5.092873s
   1 matching routes     22.953k (± 4.1%) i/s -    115.600k in   5.045017s

Comparison:
   1 matching routes:    22952.9 i/s
   2 matching routes:    22210.4 i/s - same-ish: difference falls within error
  10 matching routes:    18622.8 i/s - 1.23x  slower
```

Benchmark:

```
require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem "actionpack", path: "~/src/github.com/skipkayhil/rails"
  gem "benchmark-ips"
end

require "action_dispatch"

routes = ActionDispatch::Routing::RouteSet.new
routes.draw do
  get "/a", to: ->(e) { [200, {}, ["a"]] }

  2.times do |i|
    is = "b" + i.to_s
    get "/b", to: ->(e) { [200, {}, [is]] }
  end

  10.times do |i|
    is = "c" + i.to_s
    get "/c", to: ->(e) { [200, {}, [is]] }
  end
end

one_env = {
  "REQUEST_METHOD" => "GET",
  "SCRIPT_NAME" => "",
  "rack.input" => File.open("/dev/null"),
  "PATH_INFO" => "/a",
}.freeze

two_env = {
  "REQUEST_METHOD" => "GET",
  "SCRIPT_NAME" => "",
  "rack.input" => File.open("/dev/null"),
  "PATH_INFO" => "/b",
}.freeze

ten_env = {
  "REQUEST_METHOD" => "GET",
  "SCRIPT_NAME" => "",
  "rack.input" => File.open("/dev/null"),
  "PATH_INFO" => "/c",
}.freeze

raise unless routes.call(one_env.dup)[2] == ["a"]
raise unless routes.call(two_env.dup)[2] == ["b0"]
raise unless routes.call(ten_env.dup)[2] == ["c0"]

require "benchmark/ips"

Benchmark.ips do |x|
  x.report("10 matching routes") { routes.call(ten_env.dup) }
  x.report("2 matching routes") { routes.call(two_env.dup) }
  x.report("1 matching routes") { routes.call(one_env.dup) }
  x.compare!
end
```
2023-09-20 17:25:11 -04:00
fatkodima
69b32bd95b Fix MySQL expression index dumping with escaped quotes 2023-09-20 20:30:21 +03:00
Stephen Margheim
9bbbf4b8b9 The SQLite3 adapter now supports supports_insert_returning?
Implementing the full `supports_insert_returning?` contract means the SQLite3 adapter supports auto-populated columns (#48241) as well as custom primary keys.
2023-09-20 19:28:17 +02:00
Guillermo Iguaran
c8830a2bba
Merge pull request #49287 from fractaledmind/ar-sqlite3-concatentation
Ensure the SQLite3 adapter handles default functions with the `||` concatenation operator
2023-09-20 09:20:23 -07:00
Guillermo Iguaran
a02444723e
Merge pull request #49325 from mattbrictson/bugs/fix-missing-concurrent-constant
Fix uninitialized constant error on Puma boot
2023-09-20 08:57:05 -07:00
Petrik de Heus
6f27e92db8
Merge pull request #49329 from p8/guides/strict-loading-with-mode
Improve `strict_loading` documentation [ci-skip]
2023-09-20 17:54:23 +02:00
Matt Brictson
39ccb97e3c
Fix uninitialized constant error on Puma boot
Before, using the default `puma/config.rb` generated by `rails new`,
Puma would fail to boot in production with this error:

```
./config/puma.rb:16:in `block in _load_from': uninitialized constant Puma::DSL::Concurrent (NameError)
	from ./config/puma.rb:16:in `fetch'
	from ./config/puma.rb:16:in `_load_from'
```

This was because `Concurrent.physical_processor_count` was being
referenced before the `Concurrent` constant was initialized.

Fix by requiring `concurrent-ruby` just before the `Concurrent` constant
is needed.

Fixes #49323
2023-09-20 06:54:30 -07:00
Petrik
677fa58873 Improve strict_loading documentation [ci-skip]
Expand examples by adding singular associations.
Expand the guides with `strict_loading!`.
Also add `to_a` to code examples as loading the associations is required
to raise the errors.
2023-09-20 13:54:32 +02:00
Stephen Margheim
828eec6707 Ensure the SQLite3 adapter handles default functions with the || concatenation operator
Previously, this default function would produce the static string `"'Ruby ' || 'on ' || 'Rails'"`.
Now, the adapter will appropriately receive and use `"Ruby on Rails"`.

```ruby
change_column_default "test_models", "ruby_on_rails", -> { "('Ruby ' || 'on ' || 'Rails')" }
```
2023-09-20 09:13:46 +02:00
Guillermo Iguaran
0723e6c658
Merge pull request #49318 from yahonda/add_changelog_entry_for_bigdecimal
Add CHANGELOG entry to add bigdecimal as Active Support dependency
2023-09-19 23:03:23 -07:00
Guillermo Iguaran
3c7a8d7d8d
Merge pull request #49311 from paulreece/change_db_dockerfile
This enhancement automatically updates the Dockerfile to the desired db.
2023-09-19 22:16:50 -07:00
Yasuo Honda
b3df4f25ac
Merge pull request #49164 from lsylvester/dump-postgresql-schemas
dump PostgreSQL schemas as part of the schema dump
2023-09-20 10:00:03 +09:00
Lachlan Sylvester
5f6efdab0f dump PostgreSQL schemas as part of the schema dump 2023-09-20 10:24:07 +10:00
Yasuo Honda
bc8da7abdd Add CHANGELOG entry to add bigdecimal as Active Support dependency
Follow up https://github.com/rails/rails/pull/49152
https://github.com/rails/rails/pull/49039

- `bigdecimal_to_d.rb`
```
require 'bigdecimal/util'
p "Ruby version: #{RUBY_VERSION}"
p "BigDecimal version: #{BigDecimal::VERSION}"
p "123.455.to_d(5): #{123.455.to_d(5)}"
```

- Ruby 2.7 and 3.0 rounds down
```
$ ruby bigdecimal_to_d.rb
"Ruby version: 2.7.8"
"BigDecimal version: 2.0.0"
"123.455.to_d(5): 0.12345e3"
```

```
$ ruby bigdecimal_to_d.rb
"Ruby version: 3.0.6"
"BigDecimal version: 3.0.0"
"123.455.to_d(5): 0.12345e3"
```

- Ruby 3.1 and 3.2 rounds up

```
$ ruby bigdecimal_to_d.rb
"Ruby version: 3.1.4"
"BigDecimal version: 3.1.1"
"123.455.to_d(5): 0.12346e3"
```

```
$ ruby bigdecimal_to_d.rb
"Ruby version: 3.2.2"
"BigDecimal version: 3.1.3"
"123.455.to_d(5): 0.12346e3"
```
2023-09-20 08:26:09 +09:00
paulreece
ac9f08d1c3 This enhancement automatically updates the Dockerfile to the desired db when using db:system:change. 2023-09-19 15:33:36 -04:00
Guillermo Iguaran
42523a01db
Merge pull request #49317 from yahonda/ruby33_range_overlap
Use Ruby 3.3 `Range#overlap?` if available
2023-09-19 12:18:30 -07:00
Adrianna Chang
a907b36957
Merge pull request #49321 from adrianna-chang-shopify/ac-remove-blank-line-mailer-guides
Remove blank line in Action Mailer Basics guide [ci skip]
2023-09-19 15:16:13 -04:00
Adrianna Chang
e1d160d0ba
Remove blank line in Action Mailer Basics guide 2023-09-19 15:02:20 -04:00
Adrianna Chang
b2e003c594
Merge pull request #49320 from ansonhoyt/patch-1
Add `*_deliver` callback examples to the guides [ci skip]
2023-09-19 11:38:20 -04:00
Anson Hoyt
19c996f763
Add *_deliver callback examples [ci skip]
Examples based on the conversation in https://github.com/rails/rails/pull/47630.
2023-09-19 10:47:16 -04:00
Yasuo Honda
fa81b7946a
Merge pull request #49251 from alpaca-tc/fix-unique-keys
`#unique_keys` returns the renamed column name
2023-09-19 21:58:06 +09:00
alpaca-tc
ff8a051081 #unique_keys returns the renamed column name
follow-up #46192

Fixed a bug where `unique_keys` returned the old column name after the column specified in add_unique_key was renamed.
Since `pg_attribute.attname` may return the old column name after renaming a column, match `attrelid, attnum` in the process of getting the list of column names.
2023-09-19 21:45:11 +09:00
Adrianna Chang
603b7845eb
Merge pull request #49316 from hachi8833/fix_activesupport_changelog
[ci skip][docs]Fix Active Support changelog (7.1 beta1)
2023-09-19 08:39:29 -04:00
Yasuo Honda
1d76d45411 Use Ruby 3.3 Range#overlap? if available
This commit uses Ruby 3.3 `Range#overlap?` that has been added to Ruby via https://github.com/ruby/ruby/pull/8242 .
Rails 7.1 renames `Range#overlaps?` to `Range#overlap?` via https://github.com/rails/rails/pull/48565 ,
This commit is not feasible to backport because there is no `Range#overlap?` in Rails 7.0.z

This commit addresses the CI faiilure at https://buildkite.com/rails/rails/builds/99745#018a9ea8-82f0-40a6-90c3-cdaa6dabebab/1092-1095
because without this commit, it shows `warning: method redefined; discarding old overlap?`.
```ruby
$ ruby -v
ruby 3.3.0dev (2023-09-16T05:57:19Z master e9b503f1bb) [x86_64-linux]
$ RAILS_STRICT_WARNING=true bundle exec ruby -w -Itest test/core_ext/range_ext_test.rb
/home/yahonda/src/github.com/rails/rails/activesupport/lib/active_support/core_ext/range/overlap.rb:7: warning: method redefined; discarding old overlap?
Running 46 tests in a single process (parallelization threshold is 50)
Run options: --seed 583

\# Running:

..............................................

Finished in 0.011672s, 3940.9670 runs/s, 4883.3722 assertions/s.
46 runs, 57 assertions, 0 failures, 0 errors, 0 skips
```
2023-09-19 19:47:35 +09:00
hachi8833
233c550777 Fix Active Support changelog 2023-09-19 15:58:39 +09:00
Petrik de Heus
ebcd7233ea
Merge pull request #49313 from tnir/tn-replace-firebug-in-security-guides [ci-skip]
doc: Firebug was replaced by Firefox/Chrome DevTools
2023-09-18 19:36:53 +02:00
Petrik de Heus
defe6aeea7
Merge pull request #49294 from seanpdoyle/action-view-local-assigns-documentation
Add documentation for `locals:` and `local_assigns` [ci skip]
2023-09-18 19:16:13 +02:00
Takuya Noguchi
f8e1e20341 Firebug was replaced by Firefox/Chrome DevTools
https://getfirebug.com/index.html
https://hacks.mozilla.org/2017/10/saying-goodbye-to-firebug/
https://firefox-source-docs.mozilla.org/devtools-user/
https://developer.chrome.com/docs/devtools/

Signed-off-by: Takuya Noguchi <takninnovationresearch@gmail.com>
2023-09-19 00:26:43 +09:00
Sean Doyle
8b77436dbc Add documentation for locals: and local_assigns [ci skip]
Expand the documentation for [local_assigns][] to mention potential
integrations with [Ruby 3.1's pattern matching
assignment][pattern-matching].

Expand the Action View Overview guides to describe calls to `render`
with `locals:` options, along with the existence of the `local_assigns`
method. Also outline potential integrations with Ruby 3.1's pattern
matching assignment.

[local_assigns]: https://api.rubyonrails.org/classes/ActionView/Template.html#method-i-local_assigns
[pattern-matching]: https://docs.ruby-lang.org/en/master/syntax/pattern_matching_rdoc.html
2023-09-18 08:31:03 -04:00
Xavier Noria
a967d355c6
Merge pull request #49309 from rails/doc-normalizes
Document any callable can normalize AR attributes
2023-09-17 19:28:55 +02:00
dhh
af20a14e3a Make example align with most common demo runs 2023-09-17 09:17:51 -07:00
Xavier Noria
7a7d1185b3 Document any callable can normalize AR attributes 2023-09-17 10:31:49 +02:00
Jonathan Hefner
8e939586af
Merge pull request #49307 from rubys/rm-more-blank-lines
eliminate extra blank lines in dockerfile template (part 2)
2023-09-16 14:51:08 -05:00
Sam Ruby
1437ff7899 Sorry I didn't catch these the first time, but two more... 2023-09-16 15:22:21 -04:00
Jean Boussier
65f43d7530
Merge pull request #49292 from victormours/clarify-backoff-strategy-for-activejob-retries
Clarify that the default retry strategy uses polynomial backoff instead of exponential backoff
2023-09-16 21:02:21 +02:00