Anything that creates an incremental key will not work as soon as you start using replication. I am using something that creates a unique SHA prefix like git. It does not give you an integer key, but it can be easily changed. Also, uniqueness is not guaranteed, but you have much less chance of a collision than using the magnifying key. My model has the following things:
before_create :set_short_id
def set_short_id
prefix_length = 5
sha = Digest::SHA1.hexdigest(self.to_json)
short_id = nil
while short_id.nil? || Ticket.first(:short_id => short_id)
short_id = sha.first(prefix_length)
prefix_length += 1
end
self.short_id = short_id
end
def to_param
short_id
end
That means my urls look like a myawesomeblog.com/posts/47cc6little better.
Emily source
share