-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added simple task to enter db console using your already configured d…
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |