# user.uuid==object.owner_uuid.
has_many(:permissions,
->{where(link_class: 'permission')},
# user.uuid==object.owner_uuid.
has_many(:permissions,
->{where(link_class: 'permission')},
# If async is true at create or update, permission graph
# update is deferred allowing making multiple calls without the performance
# If async is true at create or update, permission graph
# update is deferred allowing making multiple calls without the performance
self.where(sql_conds,
user_uuids: all_user_uuids.collect{|c| c["target_uuid"]},
permission_link_classes: ['permission'])
self.where(sql_conds,
user_uuids: all_user_uuids.collect{|c| c["target_uuid"]},
permission_link_classes: ['permission'])
# Dig into the error to determine if it is specifically calling out a
# (owner_uuid, name) uniqueness violation. In this specific case, and
# the client requested a unique name with ensure_unique_name==true,
# Dig into the error to determine if it is specifically calling out a
# (owner_uuid, name) uniqueness violation. In this specific case, and
# the client requested a unique name with ensure_unique_name==true,
detail = err.result.error_field(PG::Result::PG_DIAG_MESSAGE_DETAIL)
raise unless /^Key \(owner_uuid, name\)=\([a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}, .*?\) already exists\./.match detail
detail = err.result.error_field(PG::Result::PG_DIAG_MESSAGE_DETAIL)
raise unless /^Key \(owner_uuid, name\)=\([a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{15}, .*?\) already exists\./.match detail
new_name = "#{name_was} (#{db_current_time.utc.iso8601(3)})"
if new_name == name
# If the database is fast enough to do two attempts in the
new_name = "#{name_was} (#{db_current_time.utc.iso8601(3)})"
if new_name == name
# If the database is fast enough to do two attempts in the
+ # Make sure this is correctly sorted by key, because we merge in
+ # whatever is in the database on top of it, this will be the order
+ # that gets used downstream rather than the order the keys appear
+ # in the database.