Skip to content

Commit

Permalink
Added simple task to enter db console using your already configured d…
Browse files Browse the repository at this point in the history
…atabase. Fixes #516 (#592)
  • Loading branch information
jwoertink authored Jan 5, 2021
1 parent 5f51beb commit efe1d8a
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/avram/tasks/db/console.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class Db::Console < LuckyCli::Task
summary "Access PostgreSQL console"

def help_message
<<-TEXT
#{summary}
Enters the postgres REPL. Check config/database.cr
for database configuration.
Examples:
lucky db.console
TEXT
end

def call
puts banner_message
system("psql #{Avram::Migrator::Runner.credentials.url_without_query_params}")
end

private def banner_message
String.build do |str|
str << banner_header
str << banner_help
end
end

private def banner_header
<<-MESSAGE.colorize(:green)
Entering PSQL for #{Avram::Migrator::Runner.db_name}
MESSAGE
end

private def banner_help
<<-MESSAGE.colorize.dim
Type '\\q' or 'exit' to leave
MESSAGE
end
end

0 comments on commit efe1d8a

Please # to comment.