Class: ASpaceEnvironment
- Inherits:
-
Object
- Object
- ASpaceEnvironment
- Defined in:
- backend/app/lib/bootstrap.rb
Class Method Summary (collapse)
-
+ (Boolean) demo_db?
-
+ (Object) download_demo_db
-
+ (Object) environment
-
+ (Object) init(environment = :auto)
-
+ (Object) prepare_database
Class Method Details
+ (Boolean) demo_db?
59 60 61 |
# File 'backend/app/lib/bootstrap.rb', line 59 def self.demo_db? AppConfig[:db_url] =~ /aspacedemo=true/ end |
+ (Object) download_demo_db
63 64 65 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 |
# File 'backend/app/lib/bootstrap.rb', line 63 def self.download_demo_db if File.exists?(File.join(Dir.tmpdir, 'data')) puts "Data directory already exists at #{File.join(Dir.tmpdir, 'data')}." AppConfig[:data_directory] = File.join(Dir.tmpdir, 'data') return end zip_file = File.join( Dir.tmpdir, "archivesspace_demo_data.zip") File.open( zip_file, 'wb' ) do |file| puts "Attempting to download data from #{AppConfig[:demo_data_url]}" open(AppConfig[:demo_data_url], 'rb') do |zip| file.write(zip.read) end end if File.exists?(zip_file) puts "Extracting data to #{Dir.tmpdir} directory" Zip::File.open(zip_file) do |zf| zf.each do |entry| entry.extract(File.join(Dir.tmpdir, entry.name)) end end AppConfig[:data_directory] = File.join(Dir.tmpdir, 'data') else puts "\n************************************************************************\n*\n* WARNING: Unable to download demo data. Using database defined in config \n*\n************************************************************************\n" end end |
+ (Object) environment
34 35 36 |
# File 'backend/app/lib/bootstrap.rb', line 34 def self.environment @environment end |
+ (Object) init(environment = :auto)
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'backend/app/lib/bootstrap.rb', line 39 def self.init(environment = :auto) return if @environment # Already initialised if environment != :auto @environment = environment elsif ENV["ASPACE_DEMO"] == 'true' download_demo_db @environment = :production else if ENV["ASPACE_INTEGRATION"] == "true" @environment = :integration else @environment = :production end end prepare_database end |
+ (Object) prepare_database
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'backend/app/lib/bootstrap.rb', line 102 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" end end end |