Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Update psql drop_command to force dropdb #81

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions lib/hanami/cli/commands/app/db/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Drop < App::Command
desc "Delete database"

# @api private
def call(**)
if database.drop_command
def call(force: false)
if database.drop_command(force)
Andsbf marked this conversation as resolved.
Show resolved Hide resolved
out.puts "=> database #{database.name} dropped"
else
out.puts "=> failed to drop #{database.name}"
Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/cli/commands/app/db/utils/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def create_command
end

# @api private
def drop_command
def drop_command(force: false)
raise Hanami::CLI::NotImplementedError
end

Expand Down
6 changes: 4 additions & 2 deletions lib/hanami/cli/commands/app/db/utils/postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ def create_command
end

# @api private
def drop_command
system(cli_env_vars, "dropdb #{escaped_name}")
def drop_command(force: false)
command = force ? "dropdb --force" : "dropdb"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what would be your favourite flavour here this or that:

                command = "dropdb"

                if force
                  command << " --force"
                end


system(cli_env_vars, "#{command} #{escaped_name}")
end

# @api private
Expand Down
2 changes: 1 addition & 1 deletion lib/hanami/cli/commands/app/db/utils/sqlite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create_command
end

# @api private
def drop_command
def drop_command(**)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like "unlink" doesn't support any params, so nothing to do here
https://apidock.com/ruby/Pathname/unlink

file_path.unlink
true
end
Expand Down