-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run db commands on test as well as development databases (#247)
It's a frustrating experience if users have to remember to run each of their `hanami db` commands again with `-e test` after running them on their development database. To improve this, update a number of commands to automatically re-run on the test database after completing their work on the development database: - `db create` - `db drop` - `db migrate` - `db prepare` - `db structure load` The re-run on test will only take place if these commands operate with the development environment. Running the commands in other environments (e.g. production or test) will run on the database in those environments **only.** To achieve this "re-run on test" behaviour, at the end of these `db` commands, we invoke another process to call the relevant `hanami db` command again, but with the `HANAMI_ENV=test` environment variable set. For this re-run, all given CLI flags are preserved, but `-e` and `--env` are of course stripped. The reason we have to take this approach is because right now there's no straightforward way to re-boot the Hanami app in a different environment, or stand up the database subsystem itself in a different environment.
- Loading branch information
Showing
12 changed files
with
308 additions
and
9 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
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
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
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
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
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
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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module RSpec | ||
module Support | ||
module HanamiCLIEnvironment | ||
# Adjusts $0 and ARGV to match the values expected when the `hanami` CLI is invoked in | ||
# ordinary usage. | ||
# | ||
# This is a workaround for our current (comrpomise) approach of re-executing DB CLI commands | ||
# in test mode. | ||
# | ||
# @see Hanami::CLI::Commands::App::DB::Command#re_run_development_command_in_test | ||
def as_hanami_cli_with_args(args) | ||
original_0 = $0.dup | ||
original_argv = ARGV.dup | ||
|
||
$0 = "hanami" | ||
ARGV.replace(args) | ||
|
||
yield | ||
|
||
$0 = original_0 | ||
ARGV.replace(original_argv) | ||
end | ||
end | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include RSpec::Support::HanamiCLIEnvironment | ||
end |
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
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
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
Oops, something went wrong.