Commit Graph

86855 Commits

Author SHA1 Message Date
Jean Boussier
08b2dd6ae7
Merge pull request #47651 from rrunyon/assert-deprecation-warning
Add missing deprecation warning assertion in test
2023-03-13 14:01:48 +01:00
Jean Boussier
7a8d999916
Merge pull request #47510 from fatkodima/optimize-slow-ar-tests
Optimize slow tests in activerecord
2023-03-13 13:59:48 +01:00
fatkodima
fe97e26785 Optimize slow tests in activerecord 2023-03-13 14:07:28 +02:00
Guillermo Iguaran
6c12baf30f
Merge pull request #47622 from p8/railties/thor-about-task
Use Thor for built-in about task
2023-03-13 00:56:11 -07:00
zzak
c95ed22027
Merge pull request #47653 from zzak/association-basics-entryable-table
Convert Entryable comment definition to HTML table
2023-03-13 15:18:33 +09:00
zzak
1b4ea69789
Convert Entryable comment definition to HTML table 2023-03-13 14:33:19 +09:00
Rick Runyon
98de4c00c9 [Fix #47628] Assert deprecation warning on initializing MemCacheStore with Dalli::Client 2023-03-12 21:59:22 -04:00
Yasuo Honda
3025eaa091
Merge pull request #46192 from alpaca-tc/support_unique_constraints
Add support for unique constraints (PostgreSQL-only).
2023-03-12 18:31:38 +09:00
Jonathan Hefner
11378519e7
Merge pull request #47636 from jonathanhefner/action_controller-remove-obsolete-_normalize_args
Remove obsolete `AC::Rendering#_normalize_args`
2023-03-11 21:14:48 -06:00
Vipul A M
58597c1051
Merge pull request #47642 from koic/update_repo_org_of_minitest 2023-03-12 00:12:48 +05:30
Koichi ITO
383981b932 Update GitHub organization of Minitest [ci skip]
https://github.com/seattlerb/minitest is changed to
https://github.com/minitest/minitest.
2023-03-12 03:23:44 +09:00
Jonathan Hefner
8542b748ba
Merge pull request #47641 from p8/railties/remove-deprecation-require
Remove unused require of "active_support/deprecation" in DBconsole
2023-03-11 12:22:24 -06:00
Matthew Draper
511ffed752
Merge pull request #47438 from benedikt/arel-documentation
Adds documentation for Arel::Nodes::Node
2023-03-12 03:34:06 +10:30
Petrik
37352665a7 Remove unused require of "active_support/deprecation" in DBconsoleCommand
In 7a26f2625533a0d45c0a1efbd264d3eb7462ee7b the usage of
`ActiveSupport::Deprecation.warn` in `DBconsoleCommand` was replaced with
`Rails.deprecator.warn`, which is already required by Rails::Command.
2023-03-11 16:57:58 +01:00
Xavier Noria
3531ca6853 Iterate instructions for custom namespaces in Rails < 7.1 2023-03-11 06:43:40 +01:00
Jonathan Hefner
4bd6251a15 Remove obsolete AC::Rendering#_normalize_args
The sole purpose of `ActionController::Rendering#_normalize_args` is to
store the given block in `options[:update]`.  This behavior was added
long ago in 6923b392b740f2346326634532b40cf24a0f26ef (as [part of
`ActionController::Base#_normalize_options`][part-of]) to support RJS.
Rails no longer supports RJS, so this override is no longer necessary.

[part-of]: 6923b392b7 (diff-febf2f89e7c197d6a9a7077c96031c68b2b7ac4d8ce7ec634de92b164e5f69adR100)
2023-03-10 15:51:54 -06:00
Eileen M. Uchitelle
1df6ad0ecc
Merge pull request #47632 from Shopify/configure-query-constraints-for-composite-pk
Use composite `primary_key` value as a fallback for `query_constraints_list
2023-03-10 14:21:55 -05:00
Jonathan Hefner
88c12a7bea Remove obsolete assert_not_deprecated
Follow-up to e9bc620f786d7da9afb82ec13ca3ec249f856c0c and
3ec629784cac7a8b518feb402475153465cd8e96.

`assert_not_deprecated` without any arguments will test against
`ActiveSupport::Deprecation.instance`, whereas `Enumerable#sum` would
use `ActiveSupport.deprecator`.  However, the `Enumerable#sum` override
was removed in 3ec629784cac7a8b518feb402475153465cd8e96, so we can
simply remove `assert_not_deprecated`.
2023-03-10 12:55:30 -06:00
Nikita Vasilevsky
8b43c13e53 Use composite primary_key value as a fallback for query_constraints_list
Given a model with a composite primary key, the `query_constraints_list`
should equal the `primary_key` value to enable capabilities managed by
`query_constraints_list` such as `destroy`, `update`, `delete` and others.
2023-03-10 18:31:02 +00:00
Eileen M. Uchitelle
62e36149c5
Merge pull request #47625 from Shopify/add-model-with-a-composite-primary-key
Define `ActiveRecord::Base#id` API for composite primary key models
2023-03-10 10:48:44 -05:00
Nikita Vasilevsky
fb127c0d42 Define ActiveRecord::Base#id API for composite primary key models
Given a model with a composite primary key:
```ruby
class Order < ActiveRecord::Base
  self.primary_key = [:shop_id, :id]
end
```

`ActiveRecord::Base#id` method will return an array of values for every
column of the primary key.

```ruby
order = Order.create!(shop_id: 1, id: 2)
order.id # => [1, 2]
```

The `id` column is accessible through the `read_attribute` method:

```ruby
order.read_attribute(:id) # => 2
```
2023-03-10 14:42:57 +00:00
Petrik
e95402606a Use Thor for built-in about task
Currently we use both Thor and Rake for `bin/rails` commands.
We eventually want to get all the built-ins task promoted to Thor Commands.
This migrates the `about` task to Thor.
2023-03-10 10:35:44 +01:00
alpaca-tc
d849ee04c6 Add support for unique constraints (PostgreSQL-only).
```ruby
add_unique_key :sections, [:position], deferrable: :deferred, name: "unique_section_position"
remove_unique_key :sections, name: "unique_section_position"
```

See PostgreSQL's [Unique Constraints](https://www.postgresql.org/docs/current/ddl-constraints.html#DDL-CONSTRAINTS-UNIQUE-CONSTRAINTS) documentation for more on unique constraints.

By default, unique constraints in PostgreSQL are checked after each statement.
This works for most use cases, but becomes a major limitation when replacing
records with unique column by using multiple statements.

An example of swapping unique columns between records.

```ruby
old_item = Item.create!(position: 1)
new_item = Item.create!(position: 2)

Item.transaction do
  old_item.update!(position: 2)
  new_item.update!(position: 1)
end
```

Using the default behavior, the transaction would fail when executing the
first `UPDATE` statement.

By passing the `:deferrable` option to the `add_unique_key` statement in
migrations, it's possible to defer this check.

```ruby
add_unique_key :items, [:position], deferrable: :immediate
```

Passing `deferrable: :immediate` does not change the behaviour of the previous example,
but allows manually deferring the check using `SET CONSTRAINTS ALL DEFERRED` within a transaction.
This will cause the unique constraints to be checked after the transaction.

It's also possible to adjust the default behavior from an immediate
check (after the statement), to a deferred check (after the transaction):

```ruby
add_unique_key :items, [:position], deferrable: :deferred
```

PostgreSQL allows users to create a unique constraints on top of the unique
index that cannot be deferred. In this case, even if users creates deferrable
unique constraint, the existing unique index does not allow users to violate uniqueness
within the transaction. If you want to change existing unique index to deferrable,
you need execute `remove_index` before creating deferrable unique constraints.

*Hiroyuki Ishii*
2023-03-10 16:09:32 +09:00
Rafael Mendonça França
2eed4dc0af
Merge pull request #47621 from p8/railties/thor-secret-task
Use Thor for built-in secret task
2023-03-09 22:24:47 -05:00
Petrik
55addc74dc Use Thor for built-in secret task
Currently we use both Thor and Rake for `bin/rails` commands.
We eventually want to get all the built-ins task promoted to Thor Commands.
This migrates the secret task to Thor.
2023-03-09 22:02:08 +01:00
Jonathan Hefner
db8f664b50
Merge pull request #47490 from lazaronixon/has_secure_password_salt
Enhance has_secure_password to also generate a password_salt method

Co-authored-by: Guillermo Iguaran <guilleiguaran@gmail.com>
2023-03-09 14:53:10 -06:00
Nixon
ebe9e575b7 Enhance has_secure_password to also generate a password_salt method 2023-03-09 16:44:10 -03:00
Jonathan Hefner
f921804182
Merge pull request #47444 from ghiculescu/rails-new-dev-path
Fix `rails new --dev APP_PATH` command crashing

Co-authored-by: Jean Boussier <jean.boussier@gmail.com>
2023-03-09 11:02:44 -06:00
Eileen M. Uchitelle
bde7821fbd
Merge pull request #47609 from Shopify/factor-out-column-def
Factor out the `valid_column_definition_options` method to AbstractAdapter class
2023-03-09 11:17:08 -05:00
Jean Boussier
2d6ce962b0 Fix a typo TLS -> LTS 2023-03-09 15:18:03 +01:00
Jean Boussier
03e0bd52e0
Merge pull request #47461 from Shopify/docker-node-latest-lts
Use an actual version in .node-version
2023-03-09 14:42:26 +01:00
Jean Boussier
e8638c9a94 Use an actual version in .node-version
`"lts"` isn't supported by all version managers, and even if
it was, it's a moving target, so it might build differently
on different machines based on how the version manager
refresh it's definition list.
2023-03-09 14:21:07 +01:00
Matthew Draper
7048f30991
Merge pull request #47493 from olefriis/quote_binary_strings
Quote binary strings in Arel
2023-03-09 21:21:33 +10:30
Ole Friis Østergaard
f4242739aa Move SQLite3 blob encoding to ActiveModel 2023-03-09 09:23:00 +00:00
Alex Ghiculescu
eded54b4c0 Fix rails new --dev APP_PATH command crashing
ref: https://github.com/rails/rails/issues/47435#issuecomment-1436530001

- `rails new APP_PATH --dev` works fine.
- `rails new --dev APP_PATH` does not work.

For most other flags, putting the APP_PATH before or after the flags has the same effect. It's just the prelease ones that have issues, because we have to rengerate the command so as to call `bundle exec rails new ...` a second time.

Prior to this PR, the command that was being called was `bundle exec rails new APP_PATH APP_PATH`, and that doesn't work. Now it will get called as `bundle exec rails new APP_PATH --dev APP_PATH` which is fine.

I haven't been able to find a way to write an automated test for this, but you can use the replication steps in https://github.com/rails/rails/issues/47435 to verify that the issue is fixed.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-03-08 15:44:17 -07:00
Hormoz Kheradmand
cdb895774d
Factor out valid_column_definition_options
Shopify is implementing a custom ActiveRecord adapter to integrate
with [Vitess](https://vitess.io/), and we would like to overload the
`valid_{column,table}_definition_options` methods and add
additional valid options for schema migrations.

For example:

```ruby
module ActiveRecord
  module ConnectionAdapters
    class VitessMysql2Adapter < Mysql2Adapter
      ...

      def valid_table_definition_options
        super + [:skip_vschema_migrations, :sharding_keys, :auto_increment]
      end

      def valid_column_definition_options
        super + [:skip_vschema_migrations, :sharding_keys, :auto_increment]
      end
    end
  end
end
```

This is the simplest possible change and factors out the various `valid_{table,column,primary_key}_definition_options` to be a public
method on an adapter instance.
2023-03-08 13:40:20 -08:00
Eileen M. Uchitelle
3dd5d4900d
Merge pull request #47606 from eileencodes/fix-schema-cache-file-test
Fix schema cache file test
2023-03-08 14:48:37 -05:00
eileencodes
857b4af56a
Fix schema cache file test
This test was leaving behind the directory and was never verifying the
file existed after dump was called. We can't use a tempfile because it
will be created automatically and this is testing that
`SchemaCache#open` will create the file if it doesn't exist.
2023-03-08 14:11:56 -05:00
Eileen M. Uchitelle
9898468fb4
Merge pull request #47605 from eileencodes/make-some-db-task-methods-private
Make some database tasks methods private
2023-03-08 12:07:45 -05:00
eileencodes
3bfd559b6a
Make some database tasks methods private
These were never supposed to be public and they aren't very useful
outside of database tasks so make them private.
2023-03-08 12:06:05 -05:00
Sam Ruby
6f50d40d30
Lockdown rails app in production for security (#47594)
Current Dockerfile generated by Rails runs as a non-root user
which prevents modification of the operating system but leaves
wide open all gems and the application itself.

This change locks down the application gems and only opens up
access to the following directories: db, log, storage, tmp

This is a even more secure alternative to

https://github.com/rails/rails/pull/47580
2023-03-08 14:37:18 +01:00
Guillermo Iguaran
18ae56a878
Merge pull request #47590 from zzak/rdoc-task-output-dir
Look for created.rid in api_dir (output dir)
2023-03-07 19:47:17 -08:00
Yasuo Honda
717c599446
Merge pull request #47595 from fatkodima/missing-openssl-require
Add missing `openssl` require to `activerecord/encryption/config.rb` file
2023-03-08 08:22:05 +09:00
fatkodima
e3640557ef Add missing openssl require to activerecord/encryption/config.rb file 2023-03-07 17:13:36 +02:00
Eileen M. Uchitelle
308f1de709
Merge pull request #47592 from sato11/doc-authenticate-with-http-token
Give documentational consistency to authenticate_with_http_token
2023-03-07 09:39:45 -05:00
Ole Friis Østergaard
d624a8e260 Ensure BigDecimals are not binary-encoded
In Ruby 2.7, `BigDecimal#to_s` generates ASCII-8BIT-encoded strings.
We don't want those to get hex-encoded in the generated SQL.
2023-03-07 09:38:21 +00:00
Ole Friis Østergaard
20c3eae1e5 Quote binary strings for SQLite3 and MySQL
We should properly hex-encode binary strings for SQLite3 and MySQL.
For e.g. MySQL, _not_ doing that _may_ work, but it will also
produce database warnings.
2023-03-07 09:38:21 +00:00
Yasuo Honda
01193171f2
Merge pull request #47591 from sampatbadhe/patch-3
Use cached instance of o.index
2023-03-07 14:01:52 +09:00
Junichi Sato
aacd909b7f
Give documentational consistency to authenticate_with_http_token [ci-skip] 2023-03-07 12:21:54 +09:00
sampatbadhe
0bf7afccd1 Use cached instance of o.index 2023-03-07 07:21:36 +05:30