This past January, Richard Schneeman came up with a idea for preventing undesired destructive actions on the production database.
It was implemented via the introduction of a key/value table to store internal Active Record values (namely “ar_internal_metadata”). This table stores the “environment” that was used when migrating the database. Before executing any tests, it will read this value, compare it agains the list of “protected_environments”, and abort the operation if it’s unsafe.
However, people expressed some concerns related to the database pollution this creates.
I would like to share a proposal:
Before doing any destructive action, Rails should check if the configuration of the connection that is being used is the same as the one in the list of “protected_environments” and prompt for confirmation: “it seems you are trying to execute db:drop task using the same configuration as the production database, do you want to continue? [Y/n]”.
In addition, if we decide to go down this road, “protected_environments” could be marked in the “config/database.yml” configuration file.