Class: ReactOnRails::Dev::DatabaseChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/react_on_rails/dev/database_checker.rb

Overview

DatabaseChecker validates that the Rails database is properly set up before starting the development server.

This prevents confusing errors when running bin/dev on a fresh checkout or after database cleanup.

Checks performed:

  1. Database exists and is accessible

  2. Migrations are up to date (optional warning)

Can be disabled via:

  • Environment variable: SKIP_DATABASE_CHECK=true

  • CLI flag: bin/dev –skip-database-check

  • Configuration: ReactOnRails.configure { |c| c.check_database_on_dev_start = false }

Note: This check spawns a Rails runner process which adds ~1-2 seconds to startup. Disable it if this overhead is unacceptable for your workflow.

Class Method Summary collapse

Class Method Details

.check_database(skip: false) ⇒ Boolean

Check if the database is set up and accessible

Parameters:

  • skip (Boolean) (defaults to: false)

    if true, skip the check entirely

Returns:

  • (Boolean)

    true if database is ready (or check was skipped), false otherwise



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/react_on_rails/dev/database_checker.rb', line 32

def check_database(skip: false)
  return true if should_skip_check?(skip)

  print_checking_message
  result = run_database_check

  case result[:status]
  when :ok
    print_database_ok
    check_pending_migrations
    true
  when :error
    print_database_error(result[:error])
    false
  when :not_rails_app
    print_skipped_message("bin/rails not found — skipping database check")
    true
  else
    print_skipped_message(result[:error] || "unexpected status: #{result[:status]}")
    true
  end
end