Commit Graph

23066 Commits

Author SHA1 Message Date
Jean Boussier a1c0173ee3 Move the database version cache from schema cache to pool config
Ref: https://github.com/rails/rails/pull/49378

As discussed with Matthew Draper, we have a bit of a chicken and egg
problem with the schema cache and the database version.

The database version is stored in the cache to avoid a query,
but the schema cache need to query the schema version in the database
to be revalidated.

So `check_version` depends on `schema_cache`, which depends on
`Migrator.current_version`, which depends on `configure_connection`
which depends on `check_version`.

But ultimately, we think storing the server version in the cache
is incorrect, because upgrading a DB server is orthogonal from
regenerating the schema cache.

So not persisting the version in cache is better. Instead we store
it in the pool config, so that we only check it once per process
and per database.
2023-09-28 15:18:38 +02:00
Nikita Vasilevsky 1f51409215
Use `id` in favor of `send(primary_key)`
There is no reason to send `primary_key` to the record to get the value
of the primary key. `id` method does exactly that and it's a better
abstraction. By implication it also fixes the problem with composite
primary keys.
2023-09-27 16:43:54 +00:00
Rafael Mendonça França 5d48062099
Merge pull request #49403 from fractaledmind/fix-49373
Fix the problem of database connections leaking between tests
2023-09-27 10:58:44 -04:00
Nikita Vasilevsky 92a8513995
[ci skip] do not use backticks in docs 2023-09-27 13:22:13 +00:00
Stephen Margheim 7dd068c949 Fix the problem of database connections leaking between tests 2023-09-27 11:56:00 +02:00
Rafael Mendonça França fb6c6007d0
Development of Rails 7.2 starts now
🎉
2023-09-27 03:59:11 +00:00
Rafael Mendonça França e57a936879
Merge pull request #49397 from hatsu38/fix_typo-author_name-in_md
[skip ci] Docs: Fix typo in author name Paul Coelho -> Paulo Coelho
2023-09-26 23:23:26 -04:00
Rafael Mendonça França e5386cb402
Preparing for 7.1.0.rc1 release 2023-09-27 03:08:31 +00:00
hatsu38 c0d8528b24 [skip ci] Docs: Fix typo in author name Paul Coelho -> Paulo Coelho 2023-09-27 12:00:55 +09:00
Rafael Mendonça França 60002c3af6
Fix some more quotes 2023-09-26 21:59:18 +00:00
Rafael Mendonça França acfa045405
Revert typography change in user facing errors
This change would force a lot of existing applications and libraries
to update their tests.

We included it in the beta to collect feedback from the community and
we had some comments about how negative this change would be.

Developers that care about the typography of their error messages
can easily change it in their applications using the translation
files, so there is no need to inflict pain in the upgrade process
by changing the default in the framework.

Revert "Merge PR #45463"

This reverts commit 9f60cd8dc7, reversing
changes made to 35d574dbfd.
2023-09-26 21:45:03 +00:00
Rafael Mendonça França a8e7c2dd99
Merge pull request #49395 from ipc103/remove-dirty-current-transactions-stub
Remove unneeded stub from adapter test
2023-09-26 17:12:51 -04:00
Jonathan Hefner 5fcc61076d Use monospace font for code snippets and options [ci-skip] 2023-09-26 15:48:31 -05:00
Ryuta Kamizono a86d4d7bbd Add a CHANGELOG entry for #49383
And restore updating old ones in the CHANGELOG.
2023-09-27 02:36:51 +09:00
Ian Candy a09fcd599d Removes unneccessary stub
We were reviewing this test while doing some work around transaction
tracking and noticed that the comment here seemed to no longer be the case.
`materialize_transactions` doesn't actually dirty the transaction anymore, so
it shouldn't be required to stub this out. Indeed, the tests continue to pass
without this method stub.

Co-authored-by: Daniel Colson <composerinteralia@github.com>
2023-09-26 13:03:50 -04:00
Felix Tscheulin 468d3d0deb
Fix duplicate escaping of quotes for check constraint expressions in MySQL schema
Mysql automatically escapes quotes in generated check constraints expressions.
When Rails dumps the schema (into schema.rb) the generated schema also contains,
the quotes with duplicated escaping (\\\\').
To fix this, we remove the escaping, that MySQL provides from the fetched
expression.
2023-09-26 16:19:37 +00:00
Rafael Mendonça França 5dfded9e33
Remove connection created in the test
This will avoid those connection leaking to other tests.

They cause problem because the fixtures loading will try to open
a transaction on all the active connections and since those connections
use a database pointing to a temp file that doesn't exist anymore
if any transaction try to start on them it will fail.

Fixes #49373.
2023-09-26 16:00:40 +00:00
Ryuta Kamizono 4d42741a53 Fix typo "an unique" -> "a unique" [ci skip] 2023-09-26 19:58:49 +09:00
Ryuta Kamizono b2790b6680 Rename back unique keys to unique constraints
As we (I and @yahonda) talked about the naming in person, naming unique
constraints as unique keys is very confusing to me.
All documents and descriptions says it's unique constraints, but naming
unique keys leads to misunderstanding it's a short-hand of unique
indexes.
Just naming it unique constraints is not misleading.
2023-09-26 17:52:09 +09:00
Rafael Mendonça França 92742751a9
Don't leak database connection to other tests 2023-09-26 01:59:13 +00:00
Rafael Mendonça França 3721fdce48
Remove erroneous committed file 2023-09-26 00:00:12 +00:00
Rafael Mendonça França 4c72cc2b04
Merge pull request #48615 from Edouard-chin/ec-logger
Add a public API for broadcasting logs
2023-09-25 17:13:58 -04:00
Edouard CHIN 1fbd812c47
Add a public API for broadcasting logs:
- ## Context

  While working on https://github.com/rails/rails/pull/44695, I
  realised that Broadcasting was still a private API, although it’s
  commonly used. Rafael mentioned that making it public would require
  some refactor because of the original implementation which was hard
  to understand and maintain.

  ### Changing how broadcasting works:

  Broadcasting in a nutshell worked by “transforming” an existing
  logger into a broadcasted one.
  The logger would then be responsible to log and format its own
  messages as well as passing the message along to other logger it
  broadcasts to.

  The problem with this approach was the following:

  - Heavy use of metaprogramming.
  - Accessing the loggers in the broadcast wasn’t possible.
    Removing a logger from the broadcast either.
  - More importantly, modifying the main logger (the one that broadcasts
    logs to the others) wasn’t possible and the main source of
    misunderstanding.

    ```ruby
      logger = Logger.new(STDOUT)
      stderr_logger = Logger.new(STDER))
      logger.extend(AS::Logger.broadcast(stderr_logger))

      logger.level = DEBUG # This modifies the level on all other loggers
      logger.formatter = … # Modified the formatter on all other loggers
    ```

  To keep the contract unchanged on what Rails.logger returns, the new
  BroadcastLogger class implement duck typing with all methods
  that has the vanilla Ruby Logger class.

  It's a simple and boring PORO that keeps an array of all the loggers
  that are part of the broadcast and iterate over whenever a log is
  sent.
  Now, users can access all loggers inside the broadcast and modify
  them on the fly. They can also remove any logger from the broadcast
  at any time.

  ```ruby
  # Before

  stdout_logger = Logger.new(STDOUT)
  stderr_logger = Logger.new(STDER)
  file_logger = Logger.new(“development.log”)
  stdout_logger.extend(AS::Logger.broadcast(stderr_logger))
  stdout_logger.extend(AS::Logger.broadcast(file_logger))

  # After

  broadcast = BroadcastLogger.new(stdout_logger, stderr_logger, file_logger)
  ```

  I also think that now, it should be more clear for users that the
  broadcast sole job is to pass everything to the whole loggers in
  the broadcast. So there should be no surprise that all loggers in
  the broadcast get their level modified when they call
  `broadcast.level = DEBUG` .

  It’s also easier to wrap your head around more complex setup such
  as broadcasting logs to another broadcast:
  `broadcast.broadcast_to(stdout_logger, other_broadcast)`
2023-09-25 20:40:51 +00:00
Eileen M. Uchitelle f57d54cde4
Merge pull request #49336 from fatkodima/fix-mysql-expression-index-dumping
Fix MySQL expression index dumping with escaped quotes
2023-09-25 10:22:34 -06:00
Jean Boussier adf1c2183f Fix an incorrect `assert_equal` argument order 2023-09-25 15:57:06 +02:00
Jean Boussier 99e2999f96
Merge pull request #48462 from iamradioactive/remove_additional_query
Do not revalidate encrypted attribute with current encrypted_type
2023-09-25 13:50:07 +02:00
Stephen Margheim c6d7ffc7b8 Performance tune the SQLite3 adapter connection configuration
For Rails applications, the Write-Ahead-Log in normal syncing mode with a capped journal size, a healthy shared memory buffer and a shared cache will perform, on average, 2× better.
2023-09-24 21:34:00 +02:00
Guillermo Iguaran 7c07787a5d
Merge pull request #49352 from fractaledmind/ar-sqlite-retries
Allow SQLite3 `busy_handler` to be configured with simple max number of retries
2023-09-24 10:53:02 -07:00
hachi8833 3b028fd74e Fix: expores_in -> expires_at 2023-09-24 13:18:00 +09:00
hachi8833 16f592ffa7 Fix typo in activerecord/CHANGELOG.md 2023-09-23 14:21:58 +09:00
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
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 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
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
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
Lachlan Sylvester 5f6efdab0f dump PostgreSQL schemas as part of the schema dump 2023-09-20 10:24:07 +10: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
Xavier Noria 7a7d1185b3 Document any callable can normalize AR attributes 2023-09-17 10:31:49 +02:00
Ulysse Buonomo e890ae6c5d
Loosen test condition `Arel::Nodes::Node` descendants
Dependent gems using this test suit may override further
the default methods.

Fixes #49274
2023-09-15 22:04:37 -05:00
nikhilbhatt 726c2e4672 FIX shard_names returns duplicate shard names 2023-09-15 16:55:37 +05:30
Xavier Noria 29cb2baf92
Merge pull request #48780 from rails/ar-deadlocked
Improve the docs of ActiveRecord::TransactionRollbackError
2023-09-15 11:44:19 +02:00
Gannon McGibbon 1111ec052f Clean up old composite key code
Because where now supports tuple querying, we don't need to manually
build queries with where and or statements.
2023-09-14 22:36:18 -05:00
Rafael Mendonça França 9e34e3bdf8
Merge pull request #49262 from ipc103/transaction-instrumentation-payload-outcome
Add outcome to transaction tracking payload
2023-09-14 18:14:20 -04:00
Eileen M. Uchitelle 910eb470c5
Merge pull request #49264 from Shopify/explicitly-configured-primary-key-option-must-take-priority-in-association-primary-key
Explicit `primary_key:` option should always take priority in associations
2023-09-14 11:48:10 -04:00