Class: Brut::CLI::Apps::DB::Status
- Defined in:
- lib/brut/cli/apps/db.rb
Instance Method Summary collapse
Methods inherited from Command
#after_bootstrap, args, #args, #before_execute, command_name, default_env, #delegate_to_commands, description, detailed_description, env_var, #err, #global_options, #initialize, name_matches?, option_parser, #options, opts, #out, requires_project_env, requires_project_env?, #system!
Methods included from Framework::Errors
Methods included from I18n::ForCLI
Methods included from I18n::BaseMethods
#l, #t, #t_direct, #this_field_value
Methods included from ExecutionResults
#abort_execution, #as_execution_result, #cli_usage_error, #continue_execution, #show_cli_usage, #stop_execution
Constructor Details
This class inherits a constructor from Brut::CLI::Command
Instance Method Details
#execute ⇒ Object
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/brut/cli/apps/db.rb', line 255 def execute database_name = URI(Brut.container.database_url).path connection = Brut.container.sequel_db_handle out.puts "Database Server is Up" out.puts "Database #{database_name} exists" migrations_run = if connection.table_exists?("schema_migrations") connection["select filename from schema_migrations order by filename"].all.map { |_| _[:filename] } else [] end migration_files = Dir[Brut.container.migrations_dir / "*.rb"].map { |file| filename = Pathname(file).basename.to_s } max_length = migration_files.map(&:length).max printf_string = "%-#{max_length}s - %s\n" migration_files.each do |filename| applied = migrations_run.include?(filename) printf(printf_string,filename,applied ? "✅ APPLIED" : "❌ NOT APPLIED") end 0 end |
#handle_bootstrap_exception(ex) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/brut/cli/apps/db.rb', line 231 def handle_bootstrap_exception(ex) case ex when Sequel::DatabaseConnectionError uri_no_database = URI(Brut.container.database_url.to_s) database_name = uri_no_database.path.gsub(/^\//,"") uri_no_database.path = "" begin connection = Sequel.connect(uri_no_database.to_s) out.puts "Database Server is Up" out.puts "Database #{database_name} does not exist" rescue => ex err.puts ex. end stop_execution when Sequel::DatabaseError if ex.cause.kind_of?(PG::UndefinedTable) err.puts "Migrations need to be run" continue_execution else super end end end |