Skip to content

Initializer breaks db setup #5

@sislr

Description

@sislr

Problem

# config/allgood.rb
Database.find_each do |database|
  check "#{database.name} has a daily DB backup" do
    expect(database.last_backup_finished_at).to_be_greater_than(1.day.ago)
  end
end

breaks the db setup (using bundle exec rails db:create), since there is no access to the DB at this point. I fixed it with a rescue block for the moment:

# config/allgood.rb
begin
  if Database.table_exists?
    Database.enabled.order(name: :asc).find_each do |database|
      check "#{database.name} has a daily DB backup" do
        expect(database.last_backup_finished_at).to_be_greater_than(1.day.ago)
      end
    end
  end
rescue ActiveRecord::NoDatabaseError, ActiveRecord::ConnectionNotEstablished
  # Skip checks during setup
end

Do you have an idea how I could improve this?

Ideas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions