Skip to content

Commit

Permalink
Update "force" to be option of Hanami::CLI::Commands::App::DB::Drop
Browse files Browse the repository at this point in the history
Give the DB drop command the option to force drop the Database
  • Loading branch information
Andsbf committed Jun 29, 2023
1 parent 1871506 commit 0fec282
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
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)
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 --force #{escaped_name}")
def drop_command(force: false)
command = force ? "dropdb --force" : "dropdb"

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(**)
file_path.unlink
true
end
Expand Down

0 comments on commit 0fec282

Please sign in to comment.