Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Added simple task to enter db console #592

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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