Slide 1

Slide 1 text

NIKOLAY SVERCHKOV @ssnickolay ACTIVE RECORD 6+

Slide 2

Slide 2 text

#saintprubyconf @ssnickolay

Slide 3

Slide 3 text

@ssnickolay RAILS 6.0 MULTIPLE DATABASE SUPPORT

Slide 4

Slide 4 text

@ssnickolay gem ‘octopus’

Slide 5

Slide 5 text

@ssnickolay gem ‘octopus’ FOCUSED ON

Slide 6

Slide 6 text

@ssnickolay RAILS 6.0: MULTI DB MULTI DB = DB SHARDING = + + + VERTICAL OR HORIZONTAL PARTITIONING / REPLICATION

Slide 7

Slide 7 text

@ssnickolay RAILS 6.0: MULTI DB RAILS DID NOT HAVE ADEQUATE* MULTI DB SUPPORT *https://github.com/ankane/multiverse

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

@ssnickolay AT LEAST 12 HUGE PRS FROM @EILEENCODES RAILS 6.0: MULTI DB

Slide 10

Slide 10 text

WHEN YOU RELEASE THE NEW FEATURE

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

@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`

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

@ssnickolay RAILS 6.0: create_or_find_by find_or_create_by vs create_or_find_by

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

@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

Slide 20

Slide 20 text

@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

Slide 21

Slide 21 text

@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 • …