class DatabasesController
Public Instance Methods
create()
click to toggle source
# File lib/ecrire/onboarding/controllers/databases_controller.rb, line 7 def create info ||= { 'adapter' => 'postgresql', 'database' => database, 'user' => user, 'password' => password, 'encoding' => 'utf8' } begin ActiveRecord::Base.configurations = { 'development' => info, 'test' => info, 'production' => info } ActiveRecord::Base.establish_connection ActiveRecord::Base.connection migrate! rescue Exception => e @exception = e ActiveRecord::Base.clear_all_connections! render 'index' and return end redirect_to '/users' end
index()
click to toggle source
# File lib/ecrire/onboarding/controllers/databases_controller.rb, line 5 def index; end
Private Instance Methods
database()
click to toggle source
# File lib/ecrire/onboarding/controllers/databases_controller.rb, line 60 def database @database ||= "ecrire" db_params.fetch(:name, @database) end
db_params()
click to toggle source
# File lib/ecrire/onboarding/controllers/databases_controller.rb, line 46 def db_params params.fetch(:database, {}) end
migrate!()
click to toggle source
# File lib/ecrire/onboarding/controllers/databases_controller.rb, line 37 def migrate! ActiveRecord::Tasks::DatabaseTasks.database_configuration = ActiveRecord::Base.configurations ActiveRecord::Migrator.migrations_paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true ActiveRecord::Migrator.migrate(ActiveRecord::Migrator.migrations_paths, ENV["VERSION"] ? ENV["VERSION"].to_i : nil) do |migration| ENV["SCOPE"].blank? || (ENV["SCOPE"] == migration.scope) end end
password()
click to toggle source
# File lib/ecrire/onboarding/controllers/databases_controller.rb, line 55 def password @password ||= SecureRandom.hex(16) db_params.fetch(:password, @password) end
user()
click to toggle source
# File lib/ecrire/onboarding/controllers/databases_controller.rb, line 50 def user @user ||= "ecrire#{SecureRandom.hex(2)}" db_params.fetch(:user, @user) end