Skip to content
Open
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
36 changes: 36 additions & 0 deletions lib/hanami/cli/commands/app/db/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,42 @@ module DB
# @since 2.2.0
# @api private
class Command < App::Command
# Overloads {Hanami::CLI::Commands::App::DB::Command#call} to allow skipping test
# database operations
#
# Adds `--skip-test-db` option flag
#
# @since 3.0.0
# @api private
module SkipTestDB
# @since 3.0.0
# @api private
def self.prepended(klass)
# This module is included each time the class is inherited
# Without this check, the --skip-test-db option is duplicated each time
unless klass.options.map(&:name).include?(:skip_test_db)
klass.option :skip_test_db, type: :flag, default: false, desc: "Skip test database operations"
end
end

# @since 3.0.0
# @api private
def call(*args, **opts)
if opts[:skip_test_db]
ENV["HANAMI_CLI_DB_COMMAND_RE_RUN_IN_TEST"] = "false"
end

super
end
end

# @since 3.0.0
# @api private
def self.inherited(klass)
super
klass.prepend(SkipTestDB)
end

option :app, required: false, type: :flag, default: false, desc: "Use app database"
option :slice, required: false, desc: "Use database for slice"

Expand Down
Loading