Class: Brut::CLI::Apps::DB::Status
Instance Attribute Summary
#parent_command
Instance Method Summary
collapse
#accepts, #args_description, #argv, #commands, #delegate_to_command, #detailed_description, #env, #env_vars, #execute, #name, #options, #opts, #puts, #stdin, #system!, #theme
Instance Method Details
#bootstrap? ⇒ Boolean
13
|
# File 'lib/brut/cli/apps/db.rb', line 13
def bootstrap? = false
|
#default_rack_env ⇒ Object
12
|
# File 'lib/brut/cli/apps/db.rb', line 12
def default_rack_env = "development"
|
#description ⇒ Object
11
|
# File 'lib/brut/cli/apps/db.rb', line 11
def description = "Check the status of the database and migrations"
|
#run ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/brut/cli/apps/db.rb', line 15
def run
database_name = URI(Brut.container.database_url).path.gsub(/^\//,"")
connection = Brut.container.sequel_db_handle
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
}
puts status_table(server_up: true, database_exists: true, database_name:, migrations_run:, migration_files:).render
0
rescue Sequel::DatabaseConnectionError => ex
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)
puts status_table(server_up: true, database_exists: false, database_name:, migrations_run: [], migration_files: []).render
puts [
theme.warning.render("Try creating the database with"),
theme.code.render("brut db create"),
].join(" ")
0
rescue => ex2
puts status_table(server_up: false, database_exists: false, database_name:, migrations_run: [], migration_files: []).render
puts theme.error.render("Database server is not running at #{uri_no_database}: #{ex2.message}")
puts theme.error.render("This could be a problem with your dev environment generally, or your .env.test or .env.test.local files")
1
end
end
|