Do not make config dependent on DB ids

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the architecture category.

Last Updated: 2021-05-15

In my global config file for Oxbridge Notes I had:

config.admin_seller_id = 7312

This code was then consumed within scopes:

scope :admin, -> { where(id: Config["admin_seller_id"]) }

This admin_seller_id was my production DB id. However, my local and test env, constantly changing as they were (e.g. with new seeds or records generated in DB transactions), could not guarantee this constancy. Thus my admin scope did not work in other environments.

It would have been wiser to bind on the email of that seller, since that could be constant.


Do not make configuration options dependent on database ids, since these will vary randomly from environment to environment.