Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rails 6: ActiveRecord

Rails 6: ActiveRecord

Ee8543e8f5554aaeabb6d140fa07b919?s=128

Nikolay Sverchkov

November 30, 2019
Tweet

Transcript

  1. NIKOLAY SVERCHKOV @ssnickolay ACTIVE RECORD 6+

  2. #saintprubyconf @ssnickolay

  3. @ssnickolay RAILS 6.0 MULTIPLE DATABASE SUPPORT

  4. @ssnickolay gem ‘octopus’

  5. @ssnickolay gem ‘octopus’ FOCUSED ON

  6. @ssnickolay RAILS 6.0: MULTI DB MULTI DB = DB SHARDING

    = + + + VERTICAL OR HORIZONTAL PARTITIONING / REPLICATION
  7. @ssnickolay RAILS 6.0: MULTI DB RAILS DID NOT HAVE ADEQUATE*

    MULTI DB SUPPORT *https://github.com/ankane/multiverse
  8. @ssnickolay RAILS 6.0: MULTI DB MULTI DB !!= DATABASE SHARDING

  9. @ssnickolay AT LEAST 12 HUGE PRS FROM @EILEENCODES RAILS 6.0:

    MULTI DB
  10. WHEN YOU RELEASE THE NEW FEATURE

  11. @ssnickolay RAILS 6.0: MULTI DB MULTI DB !!= DATABASE SHARDING

    ?
  12. @ssnickolay RAILS 6.0: MULTI DB MULTI DB !!= DATABASE SHARDING

  13. @ssnickolay RAILS 6.0: BULK INSERTS # Insert multiple records, performing

    an upsert # when records have duplicate ISBNs Book.upsert_all([ { title: 'Rework', author: 'David', isbn: '1' }, { title: 'Eloquent Ruby', author: 'Russ', isbn: '1' } ], unique_by: { columns: %w[ isbn ] }) *gem ‘activerecord-import`
  14. @ssnickolay RAILS 6.0: update Rails 4.0.2 update_attributes(column: value) update(column: value)

    Rails 6+ update(column: value) Deprecate `update_attributes`
  15. @ssnickolay RAILS 6.0: update Rails 4.0.2 update_attributes(column: value) update(column: value)

    Rails 6+ update(column: value) Deprecate `update_attributes`
  16. @ssnickolay RAILS 6.0: create_or_find_by find_or_create_by vs create_or_find_by

  17. @ssnickolay find_or_create_by def find_or_create_by!(attributes, &block) find_by(attributes) !|| create!(attributes, &block) end

  18. @ssnickolay find_or_create_by def find_or_create_by!(attributes, &block) find_by(attributes) !|| <Вот-Тут-> create!(attributes, &block)

    end
  19. @ssnickolay RAILS 6.0: create_or_find_by def create_or_find_by(attributes, &block) transaction(requires_new: true) {

    create(attributes, &block) } rescue ActiveRecord!::RecordNotUnique find_by!(attributes) end
  20. @ssnickolay RAILS 6.0: create_or_find_by def create_or_find_by(attributes, &block) transaction(requires_new: true) {

    create(attributes, &block) } rescue ActiveRecord!::RecordNotUnique <Вот-Тут-> find_by!(attributes) end
  21. @ssnickolay RAILS 6.0: Other • Make t.timestamps with precision by

    default • Add support for UNLOGGED Postgresql tables • Add support for annotating queries generated by ActiveRecord::Relation with SQL comments • Make it possible to override the implicit order column • …