Add modular safeguard support

未關閉
#659 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
35/100
Issue 類型
功能
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
rails, ruby
領域
databases, testing

研究方向

從 issue 中描述的 DatabaseCleaner::Safeguard::CHECKS 和現有的 ActiveRecord::Tasks::DatabaseTasks.check_protected_environments! 機制開始。檢查測試套件並執行 bin/rspec,以了解目前的 safeguard 行為;當 safeguards 可以模組化,從而無需僅依賴 ENV 變數即可提供 ORM 專用的 checks 時,即可視為完成。

由索引模型根據 Issue 內容生成。

描述

My team recently came across a really nasty issue where spring kept our ActiveRecord::Base.connection_config cached. In that case, the current ENV var based safeguards failed us (luckily nobody was seriously injured).

For example,

# First, let's run a console
> DATABASE_URL=$(heroku config:get DATABASE_URL -a my-prod-app) bin/rails console

# :tada: we're running tests against the old DATABASE_URL even though it's not set
> bin/rspec

There are lots of different ways to get into this scenario (like other code loaders or multiple ORMs that use other variables). While checking for the ENV vars works for some low hanging fruit, it doesn't let ORMs (or maybe even other app/test frameworks) make more intelligent decisions.

We actually just added this to our test suite and it works great (based on the idea in https://github.com/DatabaseCleaner/database_cleaner/pull/521#issuecomment-380757595)

# Simplified version
DatabaseCleaner::Safeguard::CHECKS << Class.new do
	def run
    	# Prevent running tests against protected environments
        #   - This is the same mechanism that the `rake` tasks use so you can't
        #     run destructive operations like `db:reset` against production
        ::ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
    end
end

I think it could be very useful to modularize the concept of a Safeguard so that various ORM modules could provide their own (the above case could something like DatabaseCleaner::ActiveRecord::Safeguard::ProtectedEnvironment).

I would be more than willing to work on this, but wanted to gauge interest and possibly talk about some design decisions before going ahead with it.

主要語言
Ruby
星號
3k
分支
486
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 提供 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 沒有貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

DatabaseCleaner/database_cleaner 的其他 Issue

查看 DatabaseCleaner/database_cleaner 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。