Sha256: 1887819f2c90baf7d7ec24ddd4d2521780d9cff1f97959841d3e5b41e72b48f2
Contents?: true
Size: 1.93 KB
Versions: 1
Compression:
Stored size: 1.93 KB
Contents
#!/usr/bin/env ruby # This script is used in the development environment with Docker to check if the # app database exists, and runs the database setup if it doesn't, as it is the # case when the project runs for the first time on the development machine. # # We are using this custom script instead of running the # `rake db:version || rake db:setup` commands, as that currently leaves a # couple of small ruby zombie processes running in the app container: require 'rubygems' require 'rake' require 'bundler' Bundler.setup(:default) require 'active_record' require 'pg' exit begin connection_tries ||= 3 ActiveRecord::Base.establish_connection && ActiveRecord::Migrator.current_version 0 rescue PG::ConnectionBad unless (connection_tries -= 1).zero? puts "Retrying DB connection #{connection_tries} more times..." sleep ENV.fetch('APP_SETUP_WAIT', '5').to_i retry end 1 rescue ActiveRecord::NoDatabaseError, ActiveRecord::AdapterNotSpecified include ActiveRecord::Tasks DatabaseTasks.root = File.expand_path '../..', __FILE__ DatabaseTasks.db_dir = File.join DatabaseTasks.root, 'db' DatabaseTasks.env = ENV.fetch 'ENV', ENV.fetch('RAILS_ENV', 'development') # The App database seeder: DatabaseTasks.seed_loader = (Class.new do def load_seed seed_file_path = File.join DatabaseTasks.db_dir, 'seeds.rb' raise "Seed file '#{seed_file_path}' does not exist" unless File.file?(seed_file_path) load seed_file_path end end).new # Add model dirs to the autoload_paths for the seeder to run smoothly: ActiveSupport::Dependencies.autoload_paths << File.join(DatabaseTasks.root, 'app', 'models', 'concerns') ActiveSupport::Dependencies.autoload_paths << File.join(DatabaseTasks.root, 'app', 'models') return 2 unless DatabaseTasks.create_current return 3 unless DatabaseTasks.load_schema_current return 4 unless DatabaseTasks.load_seed 0 ensure ActiveRecord::Base.clear_all_connections! end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sidekiq-unique-jobs-4.0.18 | rails_example/bin/check_or_setup_db |