diff --git a/lib/hanami/cli/commands/app/db/drop.rb b/lib/hanami/cli/commands/app/db/drop.rb index de17bc97..b39a815f 100644 --- a/lib/hanami/cli/commands/app/db/drop.rb +++ b/lib/hanami/cli/commands/app/db/drop.rb @@ -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}" diff --git a/lib/hanami/cli/commands/app/db/utils/database.rb b/lib/hanami/cli/commands/app/db/utils/database.rb index 883d88db..1f56e758 100644 --- a/lib/hanami/cli/commands/app/db/utils/database.rb +++ b/lib/hanami/cli/commands/app/db/utils/database.rb @@ -68,7 +68,7 @@ def create_command end # @api private - def drop_command + def drop_command(force: false) raise Hanami::CLI::NotImplementedError end diff --git a/lib/hanami/cli/commands/app/db/utils/postgres.rb b/lib/hanami/cli/commands/app/db/utils/postgres.rb index 0f469536..51d4f7e2 100644 --- a/lib/hanami/cli/commands/app/db/utils/postgres.rb +++ b/lib/hanami/cli/commands/app/db/utils/postgres.rb @@ -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" + + system(cli_env_vars, "#{command} #{escaped_name}") end # @api private diff --git a/lib/hanami/cli/commands/app/db/utils/sqlite.rb b/lib/hanami/cli/commands/app/db/utils/sqlite.rb index c2bc465e..8bff8ee6 100644 --- a/lib/hanami/cli/commands/app/db/utils/sqlite.rb +++ b/lib/hanami/cli/commands/app/db/utils/sqlite.rb @@ -17,7 +17,7 @@ def create_command end # @api private - def drop_command + def drop_command(**) file_path.unlink true end