Rails protects production database
Rails has a mechanism to protect production
databases to be dropped (and other destructive commands). In order to do that rails database tasks use a private database rake task check_protected_environments. Here's a db task code sample from rails code databases.rake:
task drop: [:load_config, :check_protected_environments] do
db_namespace["drop:_unsafe"].invoke
end
Under the hood it checks the database environment from a metadata table ar_internal_metadata created by rails on the first load schema attempt
SELECT * FROM ar_internal_metadata;
key | value
-------------+---------
environment | staging
Tweet