Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Add modular safeguard support

Aperta
#659 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rails, ruby
Ambito
databases, testing

Direzione di ricerca

Inizia con DatabaseCleaner::Safeguard::CHECKS e con il meccanismo esistente ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!, descritto nell'issue. Esamina la suite di test ed esegui bin/rspec per comprendere il comportamento attuale dei safeguards; il lavoro è completo quando i safeguards possono essere modularizzati in modo da fornire checks specifici per l'ORM senza dipendere esclusivamente dalle variabili ENV.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Ruby
Stelle
3k
Fork
485
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DatabaseCleaner/database_cleaner

Tutte le issue di DatabaseCleaner/database_cleaner

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.