Class: ASpaceEnvironment

Inherits:
Object
  • Object
show all
Defined in:
backend/app/lib/bootstrap.rb

Class Method Summary collapse

Class Method Details

.demo_db?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'backend/app/lib/bootstrap.rb', line 62

def self.demo_db?
  AppConfig[:db_url] =~ /aspacedemo=true/
end

.environmentObject



43
44
45
# File 'backend/app/lib/bootstrap.rb', line 43

def self.environment
  @environment
end

.init(environment = :auto) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'backend/app/lib/bootstrap.rb', line 48

def self.init(environment = :auto)
  return if @environment      # Already initialised

  if environment != :auto
    @environment = environment
  elsif ENV["ASPACE_INTEGRATION"] == "true"
    @environment = :integration
  else
    @environment = :production
  end

  prepare_database
end

.prepare_databaseObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'backend/app/lib/bootstrap.rb', line 66

def self.prepare_database
    if @environment == :integration && demo_db?
      # For integration, use an in-memory database instead.
      AppConfig[:db_url] = "jdbc:derby:memory:integrationdb;create=true;aspacedemo=true"
    end

    if @environment != :unit_test
      FileUtils.mkdir_p(AppConfig[:data_directory])

      if demo_db?
        # Try to discourage Derby from locking whole tables.
        java.lang.System.set_property("derby.locks.escalationThreshold", "2147483647")

        Sequel.connect(AppConfig[:db_url]) do |db|
          puts "Running database migrations for demo database"
          DBMigrator.setup_database(db)
          puts "All done."
        end

        puts <<~EOF
          
          ************************************************************************
          ***
          *** WARNING: Running against the demo database, which is not intended
          *** for production use.
          ***
          *** Please see the README.md file for instructions on configuring MySQL.
          ***
          ************************************************************************
          
        EOF
      end
    end
  end

end