1 Rails 6.1로 업그레이드하기
기존 애플리케이션을 업그레이드하는 경우, 업그레이드를 진행하기 전에 충분한 테스트 커버리지를 확보하는 것이 좋습니다. 아직 Rails 6.0으로 업그레이드하지 않았다면 먼저 6.0으로 업그레이드하고, Rails 6.1로 업데이트를 시도하기 전에 애플리케이션이 예상대로 작동하는지 확인해야 합니다. 업그레이드 시 주의해야 할 사항 목록은 Ruby on Rails 업그레이드 가이드에서 확인할 수 있습니다.
2 주요 기능
2.1 Per-database 연결 전환
Rails 6.1은 데이터베이스별로 연결을 전환할 수 있는 기능을 제공합니다. 6.0에서는 reading role로 전환하면 모든 데이터베이스 연결도 reading role로 전환되었습니다. 이제 6.1에서는 configuration에서 legacy_connection_handling을 false로 설정하면, Rails는 해당 abstract class에서 connected_to를 호출하여 단일 데이터베이스에 대한 연결을 전환할 수 있게 해줍니다.
2.2 Horizontal Sharding
Rails 6.0은 데이터베이스를 기능적으로 분할(여러 파티션, 다른 스키마)할 수 있는 기능을 제공했지만 horizontal sharding(동일한 스키마, 여러 파티션)을 지원하지는 못했습니다. Active Record의 모델이 클래스당 역할당 하나의 연결만 가질 수 있었기 때문에 Rails는 horizontal sharding을 지원할 수 없었습니다. 이제 이 문제가 해결되어 Rails에서 horizontal sharding을 사용할 수 있게 되었습니다.
2.3 Strict Loading Associations
Strict loading associations을 사용하면 모든 association이 eager하게 로드되도록 보장하고 N+1 문제가 발생하기 전에 방지할 수 있습니다.
2.4 Delegated Types
Delegated Types는 단일 테이블 상속(single-table inheritance)의 대안입니다. 이는 슈퍼클래스가 자신의 테이블로 표현되는 구체적인 클래스가 될 수 있도록 하는 클래스 계층 구조를 표현하는데 도움을 줍니다. 각 서브클래스는 추가 속성을 위한 자체 테이블을 가집니다.
2.5 Destroy Associations Async
Destroy associations async는 애플리케이션이 background job에서 association을 destroy할 수 있는 기능을 추가합니다. 이를 통해 데이터를 삭제할 때 발생할 수 있는 timeout과 기타 성능 문제를 방지할 수 있습니다.
3 Railties
자세한 변경 사항은 Changelog를 참조하세요.
3.1 제거된 기능들
더 이상 사용되지 않는
rake notestask들이 제거되었습니다.rails dbconsole명령에서 더 이상 사용되지 않는connection옵션이 제거되었습니다.rails notes에서 더 이상 사용되지 않는SOURCE_ANNOTATION_DIRECTORIES환경 변수 지원이 제거되었습니다.rails server 명령에서 더 이상 사용되지 않는
server인자가 제거되었습니다.서버 IP를 지정하기 위해
HOST환경 변수를 사용하는 더 이상 사용되지 않는 기능이 제거되었습니다.더 이상 사용되지 않는
rake dev:cachetask들이 제거되었습니다.더 이상 사용되지 않는
rake routestask들이 제거되었습니다.더 이상 사용되지 않는
rake initializerstask들이 제거되었습니다.
3.2 사용 중단(Deprecations)
ActiveRecord::Base#find_each는ActiveRecord::Batches#find_each대신 사용되어 왔으며, 자동으로 대체될 것입니다.after_commit특별 콜백에서has_many through관계를 사용하면 경고가 발생됩니다. 레코드와 연결된 상태는 트랜잭션의 일부로 먼저 업데이트 되어야 하므로after_commit에서 읽으면 오래된 결과가 반환될 수 있습니다. 가능하다면 다른 콜백이나after_save_commit을 대신 사용하십시오.validates_comparison_of로 검증된BigDecimal속성에는 경고가 표시됩니다. Rails 7.2에서는 2.0이나 0.5와 같은Rational비교자가 문자열이나 숫자로 변환될 때 반올림 대신 자동으로 정확한 소수점 값으로 변환됩니다.pluralize,singularize,camelize,underscore,humanize,titleize,titlecase,tableize,classify,dasherize,parameterize,deconstantize,foreign_key,constantize의 코어 확장 버전은 더 이상 사용되지 않습니다. 대신 String 클래스의 직접 호출이나Object#send을 사용하세요.트랜잭션 내에서
strict_loading이 활성화된 레코드의 지연된 preload는 경고를 발생시키고 Rails 7.2에서는 에러가 발생합니다. 트랜잭션 내에서는 지연된 preload가 안전하지 않습니다. 대신 eager loading을 사용하세요.
3.3 주목할 만한 변경사항
4 Action Cable
자세한 변경사항은 Changelog를 참조해 주세요.
4.1 삭제
4.2 지원 중단 내용
액션의 암묵적 렌더링은 deprecated 되었습니다.
render호출(implicitrender포함)을 선언하지 않은 경우 현재는 경고 메시지를 표시하고, 나중에는 새로운 메이저 버전에서 404 오류를 발생시킬 예정입니다. linkActionDispatch::Request#formats호출시Accept헤더의 와일드카드 유형 지원이 지원 중단(deprecated)됩니다. Content negotiation에 기반하여 구체적인 포맷을 지정해야 합니다. linkActionDispatch::Request#formats에서 지원하지 않는 mime type를 고려하는 것이 deprecated 됩니다. Content negotiation에 기반하여 실제로 지원하는 포맷을 지정해야 합니다. linkRails.application.executor.wrap이 deprecated 되었으며,Rails.application.executor.active로 대체되었습니다. link
4.3 주요 변경사항
5 Action Pack
자세한 변경사항은 Changelog를 참조하세요.
5.1 삭제 사항
더 이상 사용되지 않는
ActionDispatch::Http::ParameterFilter가 제거되었습니다.더 이상 사용되지 않는 controller 레벨의
force_ssl이 제거되었습니다.
5.2 폐기 예정
-
config.action_dispatch.return_only_media_type_on_content_type설정은 폐기될 예정입니다.
5.3 주요 변경사항
-
ActionDispatch::Response#content_type이 전체 Content-Type 헤더를 반환하도록 변경되었습니다.
6 Action View
자세한 변경사항은 Changelog를 참조하세요.
6.1 제거된 기능
ActionView::Template::Handlers::ERB에서 deprecated된escape_whitelist제거.ActionView::Resolver에서 deprecated된find_all_anywhere제거.ActionView::Template::HTML에서 deprecated된formats제거.ActionView::Template::RawFile에서 deprecated된formats제거.ActionView::Template::Text에서 deprecated된formats제거.ActionView::PathSet에서 deprecated된find_file제거.ActionView::LookupContext에서 deprecated된rendered_format제거.ActionView::ViewPaths에서 deprecated된find_file제거.ActionView::Base#initialize의 첫 번째 인자로ActionView::LookupContext가 아닌 객체를 전달하는 deprecated된 지원 제거.ActionView::Base#initialize에서 deprecated된format인자 제거.deprecated된
ActionView::Template#refresh제거.deprecated된
ActionView::Template#original_encoding제거.deprecated된
ActionView::Template#variants제거.deprecated된
ActionView::Template#formats제거.deprecated된
ActionView::Template#virtual_path=제거.deprecated된
ActionView::Template#updated_at제거.ActionView::Template#initialize에서 필수였던 deprecated된updated_at인자 제거.deprecated된
ActionView::Template.finalize_compiled_template_methods제거.deprecated된
config.action_view.finalize_compiled_template_methods제거.블록과 함께
ActionView::ViewPaths#with_fallback을 호출하는 deprecated된 지원 제거.render template:에 절대 경로를 전달하는 deprecated된 지원 제거.render file:에 상대 경로를 전달하는 deprecated된 지원 제거.두 개의 인자를 받지 않는 template handler에 대한 지원 제거.
ActionView::Template::PathResolver에서 deprecated된 pattern 인자 제거.일부 view helper에서 object의 private method를 호출하는 deprecated 지원이 제거되었습니다.
6.2 Deprecations(지원 중단)
Rails의 한 버전에서 다른 버전으로 복잡한 패턴을 지원하는 것은 어려운 일입니다. Deprecation cycle은 삭제된 기능이 있는 코드를 업데이트하기 위한 시간을 제공하기 위해 존재합니다.
Feature가 deprecate된다는 것은 다음 주요 버전에서 이 feature가 완전히 제거될 것임을 의미합니다. Deprecation warning은 이 feature가 제거되기 전에 해당 코드를 업데이트할 수 있도록 알림을 제공합니다.
Deprecation warning은 Rails 어플리케이션의 config.active_support.deprecation 설정으로 제어할 수 있습니다. deprecation warning을 조정할 수 있는 몇 가지 선택지가 있습니다:
:silent- deprecation warning을 기록하지 않습니다.:notify- deprecation warning을ActiveSupport::Deprecation.behavior에 등록된 알림(notification) 처리기로 보냅니다. 기본적으로 이것은 deprecation message를stderr로 보냅니다.:log- deprecated된 호출을logger에 기록합니다.:raise- deprecated된 코드가 사용될 때 예외를 발생시킵니다.
production에서는 기본값으로 :log가, development와 test에서는 :stderr가 각각 기본값으로 설정되어 있습니다.
6.3 주목할 만한 변경사항
ActionView::Base하위 클래스에서#compiled_method_container를 구현하도록 요구합니다.ActionView::Template#initialize에서locals인자가 필수로 변경되었습니다.javascript_include_tag와stylesheet_link_tagasset helper들이 모던 브라우저에게 asset 프리로딩에 대한 힌트를 제공하는link헤더를 생성합니다. 이는config.action_view.preload_links_header를false로 설정하여 비활성화할 수 있습니다.
7 Action Mailer
자세한 변경사항은 Changelog를 참조하세요.
7.1 제거 항목
- 더 이상 사용되지 않는
ActionMailer::Base.receive를 제거하고 Action Mailbox를 사용하도록 변경되었습니다.
7.2 지원 중단 공지 (Deprecations)
7.3 주목할 만한 변경사항
8 Active Record
자세한 변경사항은 Changelog를 참조하세요.
8.1 Removals
ActiveRecord::ConnectionAdapters::DatabaseLimits에서 deprecated된 메서드들을 제거했습니다.column_name_lengthtable_name_lengthcolumns_per_tableindexes_per_tablecolumns_per_multicolumn_indexsql_query_lengthjoins_per_querydeprecated된
ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_multi_insert?를 제거했습니다.deprecated된
ActiveRecord::ConnectionAdapters::AbstractAdapter#supports_foreign_keys_in_create?를 제거했습니다.deprecated된
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter#supports_ranges?를 제거했습니다.deprecated된
ActiveRecord::Base#update_attributes와ActiveRecord::Base#update_attributes!를 제거했습니다.ActiveRecord::ConnectionAdapter::SchemaStatements#assume_migrated_upto_version에서 deprecated된migrations_path인자를 제거했습니다.deprecated된
config.active_record.sqlite3.represent_boolean_as_integer를 제거했습니다.ActiveRecord::DatabaseConfigurations에서 deprecated된 메서드들을 제거했습니다.fetcheachfirstvalues[]=deprecated된
ActiveRecord::Result#to_hash메서드를 제거했습니다.ActiveRecord::Relation메서드에서 안전하지 않은 raw SQL 사용에 대한 deprecated된 지원을 제거했습니다.
8.2 사용 중단 예정(Deprecations)
ActiveRecord::Base.allow_unsafe_raw_sql이 사용 중단 예정입니다.connected_to의databasekwarg가 사용 중단 예정입니다.legacy_connection_handling이 false로 설정된 경우connection_handlers가 사용 중단 예정입니다.
8.3 주목할 만한 변경사항
MySQL: Uniqueness validator가 이제 데이터베이스 기본 collation을 따르며, 더 이상 기본적으로 대소문자를 구분하는 비교를 강제하지 않습니다.
relation.create가 더 이상 초기화 블록과 callback에서 클래스 레벨 쿼리 메서드로 scope를 유출하지 않습니다.이전:
User.where(name: "John").create do |john| User.find_by(name: "David") # => nil end이후:
User.where(name: "John").create do |john| User.find_by(name: "David") # => #<User name: "David", ...> endNamed scope chain이 더 이상 클래스 레벨 쿼리 메서드로 scope를 유출하지 않습니다.
class User < ActiveRecord::Base scope :david, -> { User.where(name: "David") } end이전:
User.where(name: "John").david # SELECT * FROM users WHERE name = 'John' AND name = 'David'이후:
User.where(name: "John").david # SELECT * FROM users WHERE name = 'David'where.not이 이제 NOR 대신 NAND 조건을 생성합니다.이전:
User.where.not(name: "Jon", role: "admin")
# SELECT * FROM users WHERE name != 'Jon' AND role != 'admin'
이후:
User.where.not(name: "Jon", role: "admin")
# SELECT * FROM users WHERE NOT (name = 'Jon' AND role = 'admin')
- 새로운 데이터베이스별 connection 처리를 사용하기 위해서는 애플리케이션에서
legacy_connection_handling을 false로 변경하고connection_handlers의 deprecated된 접근자를 제거해야 합니다.connects_to와connected_to의 public 메서드는 변경이 필요하지 않습니다.
9 Active Storage
자세한 변경사항은 Changelog를 참조하세요.
9.1 삭제된 기능
ActiveStorage::Transformers::ImageProcessing에:combine_options작업을 전달하는 deprecated된 지원이 제거되었습니다.deprecated된
ActiveStorage::Transformers::MiniMagickTransformer가 제거되었습니다.deprecated된
config.active_storage.queue가 제거되었습니다.deprecated된
ActiveStorage::Downloading이 제거되었습니다.
9.2 Deprecations
-
Blob.create_after_upload가Blob.create_and_upload로 교체되어 Deprecate됩니다. (Pull Request)
9.3 주목할 만한 변경사항
- 새로운 blob을 생성하고 주어진
io를 서비스에 업로드하는Blob.create_and_upload를 추가했습니다. (Pull Request) ActiveStorage::Blob#service_name컬럼이 추가되었습니다. 업그레이드 후 마이그레이션을 실행해야 합니다. 해당 마이그레이션을 생성하려면bin/rails app:update를 실행하세요.
10 Active Model
자세한 변경사항은 Changelog를 참조하세요.
10.1 삭제사항
10.2 폐기 예정 기능(Deprecations)
추후 삭제될 예정인
ActiveRecord::ModelSchema::ClassMethods#sequence_name=대신ActiveRecord::Base.sequence_name=를 사용하세요.추후 삭제될 예정인
ActiveRecord::Base.lookup_ancestors=대신에ActiveRecord::Base.allow_deprecated_singular_associations_name=를 사용하세요.Rails.application.config.active_record.use_yaml_unsafe_load는 사용되지 않으며 제거될 예정입니다.config.active_record.use_yaml_unsafe_load = true를config.active_record.yaml_column_permitted_classes로 대체하세요.Rails 7.0에서 폐기 예정이었던
ActiveRecord::Base.filter_attributes는 삭제될 예정입니다.ActiveRecord::Base.default_filter_attributes를 대신 사용하세요.Rails 7.0에서 폐기 예정이었던
ActiveRecord::Base.filter_parameters는 삭제될 예정입니다.ActiveRecord::Base.default_filter_parameters를 대신 사용하세요.rewhere가 내부적으로 사용되지 않는다는 점과 더 명확한 대안이 있다는 점 때문에rewhere는 폐기 예정입니다.unscope(:where).where또는except(:where).where를 대신 사용하세요.rewhere!가 내부적으로 사용되지 않는다는 점과 더 명확한 대안이 있다는 점 때문에rewhere!는 폐기 예정입니다.unscope!(:where).where!또는except!(:where).where!를 대신 사용하세요.where.not이 지원 중단되면서where.not은 폐기 예정입니다.where메소드에서 직접 부정 조건을 정의하세요.
10.3 주목할 만한 변경사항
- Active Model의 error들이 이제 객체가 되어, 애플리케이션에서 모델이 발생시킨 error들을 더 쉽게 다루고 상호작용할 수 있는 인터페이스를 제공합니다. 이 기능은 query 인터페이스를 포함하고, 더 정확한 테스팅과 error 세부사항에 대한 접근을 가능하게 합니다.
11 Active Support
자세한 변경사항은 Changelog를 참조하세요.
11.1 Removals
config.i18n.fallbacks가 비어있을 때I18n.default_locale로 폴백하는 deprecated된 기능 제거.deprecated된
LoggerSilence상수 제거.deprecated된
ActiveSupport::LoggerThreadSafeLevel#after_initialize제거.deprecated된
Module#parent_name,Module#parent,Module#parents제거.deprecated된
active_support/core_ext/module/reachable파일 제거.deprecated된
active_support/core_ext/numeric/inquiry파일 제거.deprecated된
active_support/core_ext/array/prepend_and_append파일 제거.deprecated된
active_support/core_ext/hash/compact파일 제거.deprecated된
active_support/core_ext/hash/transform_values파일 제거.deprecated된
active_support/core_ext/range/include_range파일 제거.deprecated된
ActiveSupport::Multibyte::Chars#consumes?와ActiveSupport::Multibyte::Chars#normalize제거.deprecated된
ActiveSupport::Multibyte::Unicode.pack_graphemes,ActiveSupport::Multibyte::Unicode.unpack_graphemes,ActiveSupport::Multibyte::Unicode.normalize,ActiveSupport::Multibyte::Unicode.downcase,ActiveSupport::Multibyte::Unicode.upcase,ActiveSupport::Multibyte::Unicode.swapcase제거.deprecated된
ActiveSupport::Notifications::Instrumenter#end=제거.
11.2 Deprecations
ActiveSupport::Multibyte::Unicode.default_normalization_form이 Deprecate 되었습니다.
11.3 주요 변경사항
12 Active Job
자세한 변경사항은 Changelog를 참조하세요.
12.1 삭제(Removals)
The
assert_template/assert_no_templateassertions in controllers and integration tests were moved to a gem at rails/rails-controller-testing. (Pull Request)컨트롤러와 통합 테스트에서
assert_template/assert_no_templateassertion이 rails/rails-controller-testing gem으로 이동되었습니다. (Pull Request)Removed deprecated
assigns()andassert_assigns_notin functional tests. (Pull Request)기능 테스트에서 더 이상 사용되지 않는
assigns()와assert_assigns_not가 제거되었습니다. (Pull Request)Removed deprecated
xml_http_request()andxhr()methods in integration tests, and useget()/post()/ etc with thexhr: trueparameter. (Pull Request)통합 테스트에서 더 이상 사용되지 않는
xml_http_request()와xhr()메서드가 제거되었으며, 대신xhr: true파라미터와 함께get()/post()/ 기타 메서드를 사용하세요. (Pull Request)Removed deprecated
find_eachargumentconditionsinActiveRecord::Batches. (Pull Request)ActiveRecord::Batches에서 더 이상 사용되지 않는find_each인자conditions가 제거되었습니다. (Pull Request)Removed deprecated behaviour allowing nested arrays to be passed as query values in
ActiveRecord::Relation#where. (Pull Request)ActiveRecord::Relation#where에서 query 값으로 중첩 배열을 전달할 수 있었던 더 이상 사용되지 않는 동작이 제거되었습니다. (Pull Request)Removed deprecated
ActiveRecord::Base.disable_implicit_join_references=. (Pull Request)더 이상 사용되지 않는
ActiveRecord::Base.disable_implicit_join_references=가 제거되었습니다. (Pull Request)The
only_pathoption is no longer supported in*_pathroute helper methods. Callurl_forinstead. (Pull Request)*_path라우트 헬퍼 메서드에서only_path옵션이 더 이상 지원되지 않습니다. 대신url_for를 호출하세요. (Pull Request)
12.2 Deprecation
config.active_job.return_false_on_aborted_enqueue가 Deprecate되었습니다.
12.3 주목할 만한 변경사항
- Job enqueuing이 중단된 경우
false를 반환합니다.
13 Action Text
자세한 변경사항은 Changelog를 참조하세요.
13.1 삭제
13.2 지원 중단(Deprecation) 예정
13.3 주요 변경사항
Rich text content의 존재 여부를 확인하기 위해 rich text 속성 이름 뒤에
?를 추가하는 메서드가 추가되었습니다. (Pull Request)trix editor를 찾아 주어진 HTML 콘텐츠를 채우는
fill_in_rich_text_areasystem test case 헬퍼가 추가되었습니다. (Pull Request)데이터베이스 fixture에서
<action-text-attachment>요소를 생성하는ActionText::FixtureSet.attachment가 추가되었습니다. (Pull Request)
14 Action Mailbox
자세한 변경사항은 Changelog를 참조하세요.
14.1 제거
ActionDispatch::Http::ParameterFilter는 제거되었습니다. 대신ActiveSupport::ParameterFilter를 사용하세요. (Pull Request)ActiveRecord::ConnectionAdapters::SQLite3Adapter#valid_alter_table_type?메서드가 제거되었습니다. (Pull Request)suffix가 없는 Top Level
HashWithIndifferentAccess클래스가 제거되었습니다.ActiveSupport::HashWithIndifferentAccess를 대신 사용하세요. (Pull Request)config.action_view.raise_on_missing_translations설정이 제거되었습니다.config.i18n.raise_on_missing_translations설정을 대신 사용하세요. (Commit)rake dev:cache태스크가 제거되었습니다.rails dev:cache를 대신 사용하세요. (Pull Request)draft?메서드를 호출했을 때 deprecation warning 없이 실패하는 대신,draft_status메서드를 제거했습니다. (Pull Request)Mode::CLASSES가 "Class already defined" 에러가 발생하지 않도록 제거되었습니다. (Pull Request)Model.reorder(nil)이Model.reorder({})처럼 동작하던 것이 제거되었습니다. (Pull Request)
14.2 Deprecation 알림
Rails.application.credentials.action_mailbox.api_key와MAILGUN_INGRESS_API_KEY가 deprecated되었습니다. 대신Rails.application.credentials.action_mailbox.signing_key와MAILGUN_INGRESS_SIGNING_KEY를 사용하세요.
14.3 주목할 만한 변경사항
15 Ruby on Rails 가이드
자세한 변경 사항은 Changelog를 참조하세요.
15.1 주목할만한 변경사항
16 공로
Rails를 안정적이고 강력한 프레임워크로 만들기 위해 많은 시간을 투자한 수많은 사람들을 보려면 Rails에 기여한 전체 명단을 참조하세요. 그들 모두에게 찬사를 보냅니다.