Commit Graph

23111 Commits

Author SHA1 Message Date
fatkodima
bd9d7c006a Return back maximum allowed PostgreSQL table name to 63 characters 2023-10-12 20:02:12 +03:00
Earlopain
430d962a79
Fix code example for create_unlogged_tables [ci skip] 2023-10-12 16:31:23 +02:00
Ryuta Kamizono
a3695553d4
Merge pull request #49595 from jbampton/fix-grammar
test(ruby): fix grammar
2023-10-12 20:23:53 +09:00
fatkodima
796e36451f Fix detecting IDENTITY columns for PostgreSQL < 10 2023-10-12 12:30:33 +03:00
fatkodima
cb1a13aeab Fix ActiveRecord tests for PostgreSQL < 10 2023-10-12 12:29:27 +03:00
John Bampton
130c0c173a test(ruby): fix grammar 2023-10-12 16:29:58 +10:00
fatkodima
17609f4ccd Load author_addresses fixtures for ActiveRecordMessagePackTest 2023-10-11 22:57:39 +03:00
fatkodima
b8829cabec Enable Style/RedundantDoubleSplatHashBraces rubocop cop 2023-10-11 14:55:00 +03:00
Carlos Antonio da Silva
c7e3cf2561
Merge pull request #49562 from akhilgkrishnan/update-postgres-naming-to-postgresql
Update postgres naming to PostgreSQL
2023-10-10 15:51:45 -03:00
Jean Boussier
ce2eb72667
Merge pull request #49544 from hieuk09/bug/fix-sqlite3-table-name-quote
SQLite: add additional quote to table name only when it’s not quoted
2023-10-10 17:40:12 +02:00
Akhil G Krishnan
80a5fb50c2 Update postgres naming to PostgreSQL 2023-10-10 13:44:20 +05:30
Hieu Nguyen
6da327c591 SQLite - Remove quote when extracting table ref in insert query 2023-10-10 08:27:40 +08:00
Jean Boussier
a9b68558d0
Merge pull request #49488 from pjambet/pj/add-materialized-to-null-transaction
Add materialized? to NullTransaction
2023-10-09 18:45:58 +02:00
Jean Boussier
7b1bdbb177
Merge pull request #49504 from fatkodima/fix-pg-retrieving-identity-columns
Fix auto populating `IDENTITY` columns for PostgreSQL
2023-10-09 18:42:06 +02:00
Andrew Haines
63854aa473
Check if internal metadata is enabled in create_table_and_set_flags method 2023-10-09 14:39:06 +01:00
Jonathan Hefner
4c98fc27c4 Autolink references for AR::Calculations#async_* [ci-skip]
This also fixes several minor typos.
2023-10-07 12:26:33 -05:00
Jonathan Hefner
bf853ac3fe Remove unnecessary alias references [ci-skip]
RDoc lists method aliases automatically.
2023-10-07 12:26:33 -05:00
Jonathan Hefner
ed08eea99f Capitalize framework names [ci-skip] 2023-10-07 12:26:26 -05:00
Jonathan Hefner
c8b3642ede Ensure AR::Core#{slice,values_at} appear in RDoc [ci-skip]
When a `:method:` doc is immediately followed by the `private` keyword,
RDoc will hide that doc as if it were a private method.

In #48324, the `:method:` docs for `ActiveRecord::Core#slice` and
`ActiveRecord::Core#values_at` were swapped in an attempt to force
`values_at` to appear in the rendered docs.  However, doing so causes
`slice` to dissappear from the rendered docs.

To ensure that `slice` and `values_at` both appear in the rendered docs,
this commit moves their `:method:` docs away from the `private` keyword
in `ActiveRecord::Core`.
2023-10-07 12:26:14 -05:00
Jonathan Hefner
e8166c4c70 Hyphenate "database specific" [ci-skip]
"database-specific" is a compound adjective, and thus hyphenated.
2023-10-07 12:02:22 -05:00
Jonathan Hefner
77e5d4e87f Rephrase advice about forms for nested attributes [ci-skip] 2023-10-07 11:55:34 -05:00
fatkodima
6ba6aa32db Fix reverting rename_table for older migrations 2023-10-07 11:51:25 +03:00
Jason Meller
fc5c8d0cfe
Ensure #signed_id outputs url_safe strings (#49507) 2023-10-06 15:24:37 +02:00
fatkodima
f592d50837 Fix auto populating IDENTITY columns for PostgreSQL
Fixes #49502.

This bug was introduced in https://github.com/rails/rails/pull/48241. Since `IDENTITY` columns
in PostgreSQL do not have defaults, they are not auto populated via the changes made in that PR.
Thus we need to consider them separately.
2023-10-05 23:42:29 +03:00
Pierre Jambet
3d68d224a3
Add materialized? to NullTransaction
The NullTransaction implements the null object pattern for the
Transaction class, but it was missing the `materialized?` method.

This caused issues in cases where we'd want to check if the current
transaction is materialized, where we'd need to check if the connection
is open first:

```ruby
current_transaction = ActiveRecord::Base.connection.current_transaction
current_transaction.open? && current_transaction.materialized?
```

With this change we can skip the extra check on `open?`

```ruby
current_transaction = ActiveRecord::Base.connection.current_transaction
current_transaction.materialized?
```
2023-10-04 21:04:47 -04:00
Rafael Mendonça França
b71c75e467
Merge pull request #49391 from ipc103/transaction-tracking-on-reconnect
Ensure transaction tracking finishes when reconnecting
2023-10-05 01:57:26 +02:00
Ian Candy
306ef99bbb Ensure transaction tracking finishes when reconnecting
We noticed a couple of spots where transaction tracking events
were potentially incorrect.

When the connection reconnects with `restore_transactions: true`,
we were keeping the original start time for the transaction. In this case
it seems more accurate to treat these as separte transactions where the first
one finishes as incomplete.

Instead of forcing the adapter to tell the transaction manager to
suspend (or `detach` or `lost`) the transactions, we can keep that
logic encapsulated inside of the Transaction class for when to broadcast
a finish event. This means that we won't capture a finish event if you
manually call `reconnect!` without `restore_transactions: true`, but
that might be worthy of the tradeoff since this is a rare use-case anyway.

We also start raising here if the TransactionInstrumenter receives `#start`
when already started, or `#finish` when not started. This ensures that we don't
quietly end up in any weird states.

When marking that a transaction is incomplete, we also want to check
that the transaction is materialized to avoid finishing our instrumentation
if it hasn't already started. Also added a test to simulate losing a connection
without ever materializing a transaction.

Co-authored-by: Daniel Colson <composerinteralia@github.com>
2023-10-04 19:35:22 -04:00
Rafael Mendonça França
fed3125ea1
Merge pull request #49470 from rails/rm-eager-load-model-schema
Load the model schema when running test in eager load context
2023-10-04 05:51:39 -04:00
Rafael Mendonça França
1f0262aa2b
Separate the CI environment from the application CI environment
Right now we are using both to test the Rails applications we generate
and to test Rails itself. Let's keep CI for the app and BUILDKITE to
the framework.
2023-10-04 09:36:51 +00:00
Eileen M. Uchitelle
fafb6deb2f
Merge pull request #49483 from fatkodima/fix-uniq-validation-for-expr-indexes
Fix uniqueness validation to correctly work with expression indexes
2023-10-04 10:32:23 +02:00
fatkodima
ef1968bd9f Fix uniqueness validation to correctly work with expression indexes 2023-10-04 11:18:24 +03:00
Rafael Mendonça França
ec310b9361
Merge pull request #49476 from p8/activerecord/split-strict-loading-n-plus-1-test
Split strict_loading with :n_plus_one_only test
2023-10-04 04:03:55 -04:00
Petrik
d26f1a8777 Use gender neutral pronoun for author [ci skip] 2023-10-03 21:32:26 +02:00
Petrik
71d6e94097 Split strict_loading with :n_plus_one_only tests
The current test handles a lot of different cases.
Splitting it on the type of association makes the tests easier to
understand.
2023-10-03 21:07:59 +02:00
Rafael Mendonça França
70843ff7b2
Load the model schema when running test in eager load context
Some protections like the one that checks if an enum is pointing to
a valid column in the table only works when the database schema is
loaded to the model.

Before this change, if schema cache wasn't present and the right
combinations of configurations were not set, developers would only see
this exception in production.

With this change, those errors would be caught on CI, as soon the
tests are loaded.
2023-10-03 13:20:40 +00:00
Yasuo Honda
4ed6c5f3cd Ignore sqlite3 database file under the activerecord/test/storage/
This commit ignores the sqlite3 database file under the `activerecord/test/storage/`.

- Steps to reproduce

```ruby
cd activerecord
bundle update sdoc --conservative # not relevant to this issue, just to update sdoc
bin/test test/cases/schema_dumper_test.rb -n test_do_not_dump_foreign_keys_when_bypassed_by_config
git status
```

- Without this fix, `git status` shows `test/storage/` as `Untracked files`.
Here `Gemfile.lock` difference is due to `bundle update sdoc --conservative`

```ruby
$ git status
On branch main
You are currently bisecting, started from branch 'main'.
  (use "git bisect reset" to get back to the original branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  modified:   ../Gemfile.lock

Untracked files:
  (use "git add <file>..." to include in what will be committed)
  test/storage/

no changes added to commit (use "git add" and/or "git commit -a")
$
```

- With this fix, `git status` does not show any `Untracked files`.
```
$ git status
On branch add_gitignore_test_storage
You are currently bisecting, started from branch 'main'.
  (use "git bisect reset" to get back to the original branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   ../Gemfile.lock

no changes added to commit (use "git add" and/or "git commit -a")
$
```
2023-10-03 11:30:15 +09:00
Rafael Mendonça França
7d58fe941a
Fix typo 2023-10-02 11:09:57 +00:00
Jean Boussier
618db1377f Ensure PG connection is configured before looking up types
Fix: https://github.com/rails/rails/issues/49439

Because Postgres adapter types are connection dependent,
we can't lookup types without first connecting to the database.

Note, this really isn't good, ideally types should be stored in the
schema cache so that we don't have to extract types every time.
2023-10-02 09:48:09 +02:00
Rafael Mendonça França
0ba14ebab8
Revert "Merge pull request #49056 from joshuay03/raise-on-duplicate-accepts-nested-attributes-for"
This reverts commit b6166e8da2a395f55b275ac9fdc8b957fb97d54a, reversing
changes made to 5415d3a19ad4eb26a4e57bb31c06187ea5172812.
2023-10-01 20:50:23 +00:00
Niklas Häusele
898a248132
rails db:drop now removes -shm and -wal sqlite files (#49436)
fixes #49435
2023-10-01 20:03:21 +00:00
Rafael Mendonça França
db2ef1d250
Merge pull request #49417 from Edouard-chin/ec-logger-fix
Fix the BroadcastLogger being initialized too late:
2023-09-29 15:45:03 -04:00
Bart de Water
95b6fbd00f Stop building AS::Notifications::Event manually
It's possible since Rails 6 (3ea2857943dc294d7809930b4cc5b318b9c39577) to let the framework create Event objects, but the guides and docs weren't updated to lead with this example.

Manually instantiating an Event doesn't record CPU time and allocations, I've seen it more than once that people copy-pasting the example code get confused about these stats returning 0. The tests here show that - just like the apps I've worked on - the old pattern keeps getting copy-pasted.
2023-09-29 12:34:23 -04:00
Edouard CHIN
40cb50e06e Fix the BroadcastLogger being initialized too late:
- An oversight of #48615 is that it changes the `Rails.logger` to be
  a broadcast logger after the app is booted. Anything referencing
  `Rails.logger` during the boot process will get a simple logger and
  ultimately resulting in logs not being broadcasted.

  For example `ActionController::Base.logger.info("abc")` would
  just output logs in the `development.log` file, not on STDOUT.

  ----

  The only solution I could think of is to create a BroadcastLogger
  earlier at boot, and add logger to that broadcast when needed (instead
  of modiyfing the `Rails.logger` variable).
2023-09-29 15:42:47 +02:00
Jean Boussier
2da1852ac9 Delay Adapter#check_version to #configure_connection
Ideally we should be able to checkout an Adapter instance without
triggering a connection to the server.

For some adapters like Trilogy that is the case today, but only if
you have a schema cache loaded, otherwise `check_version` will trigger
a query.

I think this check can be delayed to when we actually use the connection.
2023-09-29 08:53:16 +02:00
Koichi ITO
0bdf160f3a Tweak the docs for async_* APIs [ci skip]
This PR adds period at the end of sentences to maintain consistency in the `async_*` API document.
2023-09-29 11:19:21 +09:00
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