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)


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

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

.environmentObject



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

def self.environment
  @environment
end

.init(environment = :auto) ⇒ Object



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

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



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'backend/app/lib/bootstrap.rb', line 67

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 "          \n          ************************************************************************\n          ***\n          *** WARNING: Running against the demo database, which is not intended\n          *** for production use.\n          ***\n          *** Please see the README.md file for instructions on configuring MySQL.\n          ***\n          ************************************************************************\n          \n        EOF\n      end\n    end\n  end\n\nend\n"