Skip to content

Commit

Permalink
Import newsletter for this week in rails
Browse files Browse the repository at this point in the history
  • Loading branch information
vipulnsward committed May 19, 2023
1 parent 1905dfa commit 7d0dc6f
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions _posts/2023-05-19-this-week-in-rails.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
---
layout: post
title: "Rails World CFP, ActiveRecord.disconnect_all!, optimized where query and more!"
categories: news
author: vipulnsward
published: true
date: 2023-05-19
---

Hello Everyone!

This is [Vipul](https://twitter.com/vipulnsward), bringing you this week's changes in the Rails codebase.

[Rails World Call for Papers now open](https://rubyonrails.org/2023/5/9/rails-world-call-for-papers-now-open)
This CFP is open until June 16, with space in the agenda for 26 talks on two tracks, and up to six workshops. Read the full announcement for more details and submit your proposal!

[Introduce ActiveRecord.disconnect_all! to close all connections from pool](https://github.com/rails/rails/pull/48220)
This change introduces a multi-db aware version of `ActiveRecord::Base.connection.disconnect!`. It also avoid connecting to the database if we weren't already.

This can be useful to reset state in multi-db applications after `establish_connection` has been used.

[Optimized where query for a range where begin and end are same](https://github.com/rails/rails/pull/48235)
This fix, optimizes the `where` query for a range where begin and end are same. For example when doing `User.where(id: 2..2)`

```sql
# before
SELECT `users`.* FROM `users` WHERE `users`.`id` BETWEEN 2 AND 2

# after
SELECT `users`.* FROM `users` WHERE `users`.`id`=2
```

Simple fix, but effective!

[Make sure curl is available in generated docker image](https://github.com/rails/rails/pull/48182)
The dockerfile template for Apps generated by Rails now includes curl package by default. This was necessary for health-checks when docker images are used to deploy with [MRSK](https://github.com/mrsked/mrsk), which uses curl.

[Return INCLUDE columns in PostgreSQL indexes as strings](https://github.com/rails/rails/pull/48037)
Support for `INCLUDE` columns for PostgreSQL was introduced in https://github.com/rails/rails/pull/44803.
This change makes sure that the columns are returned as strings instead of symbols, to keep behaviour same as what `columns` method returns.

[Discard connections which may be left in a transaction](https://github.com/rails/rails/pull/48200)
Connections are discarded in `within_transaction` if rolling back fails after the call to yield raises.
This is done to prevent a connection from being left in a transaction if the rollback actually failed.

This change causes connections to be discarded in the following additional cases where the connection may be left in a transaction:

- If beginning the transaction fails.
- If rolling back the transaction fails.
- If committing the transaction fails, then rolling back fails.

by rescuing the exceptions and discarding the connection.

[Enable passing column size to migration generator ](https://github.com/rails/rails/pull/48210)
This commit enables passing a `size` attribute to the rails migration generator so that it doesn't need to be manually added to the migration file after it is generated.

```ruby
# Before

rails generate migration CreateAuthor name:text{65535}

# After
rails generate migration CreateAuthor name:text{medium}
```

This generates a migration which includes the size attribute:

```ruby
class CreateAuthor < ActiveRecord::Migration[7.1]
def change
create_table :authors do |t|
t.text :name, size: :medium
end
end
end
```

[Content Security Policy: add :unsafe_hashes mapping](https://github.com/rails/rails/pull/48212)
This change adds the corresponding mapping for `unsafe_hashes`, which now allows us to use `:unsafe_hashes` instead of 'unsafe-hashes'

```ruby
Rails.application.configure do
config.content_security_policy do |policy|
# ...
policy.script_src :self, :strict_dynamic, :unsafe_hashes,
"'sha256-lo7ZdP6kFds+wf1WMWvn7MhcFVFJV44kAXODRevzRZ8='" # javascript:false
# ...
end
# ...
end
```

This allows us to use inline event handlers properly, which used to fail before with wrong key `unsafe-hashes` which was not supported properly before


_You can view the whole list of changes [here](https://github.com/rails/rails/compare/@%7B2023-05-05%7D...main@%7B2023-05-12%7D)._
_We had [20 contributors](https://contributors.rubyonrails.org/contributors/in-time-window/20230512-20230519) to the Rails codebase this past week!_

Until next time!

_[Subscribe](https://world.hey.com/this.week.in.rails) to get these updates mailed to you._

0 comments on commit 7d0dc6f

Please sign in to comment.