-
-
Notifications
You must be signed in to change notification settings - Fork 162
4.0 Upgrade Guide
We've dropped support for MRI < 2.3, which obviously means that the prerequisite is to upgrade your Ruby, if you're on < 2.3.
First step is to upgrade all rom gems from the previous release and fix all deprecation warnings, first upgrade these gems:
rom 3.3.1rom-repository 1.4.0rom-sql 1.3.4
In 4.0 rom gem is a meta-gem which depends on latest rom-core, rom-mapper, rom-repository and rom-changeset, to upgrade tweak your Gemfile:
- Set
gem "rom", "~> 4.0" - Set
gem "rom-sql", "~> 2.0" - Remove
rom-repository - Remove
rom-mapper - (optional) if you're using
dry-validation, bump it to~> 0.11.1 - (optional) if you're using
dry-types, you need to upgrade to~> 0.12
Before 4.0, relations without explicit classes or definitions in the setup DSL, would be inferred based on information in the database schema. This feature, despite being useful in some rare cases, caused a lot of confusion for many people, and in case of large schemas caused performance problems. Because of this, the feature was removed.
This means you need to define which relations you want to use via explicit relation classes or using setup DSL.
Starting with 4.0, composing relations require associations. This means Relation#combine
and Relation#wrap will only work if you have associations defined in relation classes.
# in 3.x this works
users.combine(many: { tasks: [tasks.for_users, task_id: :id] })
# in 4.x you must define an association, ie:
class Users < ROM::Relation[:sql]
schema(infer: true) do
associations { has_many :tasks }
end
end
# then just:
users.combine(:tasks)Notice that you can still provide custom query logic for associations via new :override option in association DSL.
In repositories you no longer need to declare which relations a repo will use:
# 3.x
class UserRepo < ROM::Repository[:users]
relations :tasks, :posts
end
# 4.x
class UserRepo < ROM::Repository[:users]
endRepository#command was removed in favor of Relation#command, ie:
# 3.x
user_repo.command(:create).call(name: "Jane")
# 4.0
users.command(:create).call(name: "Jane")Repository#changeset was removed in favor of Relation#changeset, but the method has a different signature now:
:create
# 3.x
user_repo.changeset(:create, name: "Jane").commit
# in 4.0
users.changeset(:create, name: "Jane").commit:update
# 3.x
user_repo.changeset(:update, 1, name: "Jane").commit
# in 4.0
users.by_pk(1).changeset(:update, name: "Jane").commit:delete
# 3.x
user_repo.changeset(:delete, 1).commit
# in 4.0
users.by_pk(1).changeset(:delete).commitFor more information see Changeset docs.
-
Command#transactionis gone, useRelation#transactioninstead. See Transaction docs -
PG::JSONArray,PG::JSONBArray,PG::JSONHash, andPG::JSONBHashtypes are gone, usePG::JSONandPG::JSONBinstead - The
pg_hstoreextension isn't loaded automatically now, use the:extensionoption in configuration, to load it on demand
Important: you may start seeing various deprecation warnings from Sequel, it is recommended to fix them all in preparation for Sequel 5, which we will fully support in rom-sql 2.1.
Please go through the changelogs too: