-
-
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.
Add a `db prepare` command for the new db layer. This command will invoke `db create` and `db structure load` (if the database did not already exist), and then `db migrate` and `db seed`. Getting this to work and be well tested required some internal changes: - Update the `db` commands that it calls to otherwise exit themselves using an injected `command_exit` proc, which defaults to `method(:exit)`. This then allows the `db prepare` command to inject an alternative proc that prevents those subcommands from exiting the whole process, allow it to catch the failures and handle them on its own. - Allow `DB::Command#databases` to receive a real `slice:` object as part of its args, so that `db prepare` can pass this along directly to all its subcommands.
- Loading branch information
Showing
15 changed files
with
461 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# frozen_string_literal: true | ||
|
||
module Hanami | ||
module CLI | ||
module Commands | ||
module App | ||
module DB | ||
# @api private | ||
class Prepare < DB::Command | ||
desc "Prepare databases" | ||
|
||
def call(app: false, slice: nil, **) | ||
exit_codes = [] | ||
|
||
databases(app: app, slice: slice).each do |database| | ||
command_exit = -> code { throw :command_exited, code } | ||
command_args = {slice: database.slice, command_exit: command_exit} | ||
|
||
exit_code = catch :command_exited do | ||
unless database.exists? | ||
run_command(DB::Create, **command_args) | ||
run_command(DB::Structure::Load, **command_args) | ||
end | ||
|
||
run_command(DB::Migrate, **command_args) | ||
run_command(DB::Seed, **command_args) | ||
nil | ||
end | ||
|
||
exit_codes << exit_code if exit_code | ||
end | ||
|
||
exit_codes.each do |code| | ||
break exit code if code > 0 | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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,17 @@ | ||
module RSpec | ||
module Support | ||
module Matchers | ||
def include_in_order(*strings) | ||
re = Regexp.new( | ||
strings.map { Regexp.escape(_1) }.join(".+"), | ||
Regexp::MULTILINE | Regexp::EXTENDED | ||
) | ||
match(re) | ||
end | ||
end | ||
end | ||
end | ||
|
||
RSpec.configure do |config| | ||
config.include RSpec::Support::Matchers | ||
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
Oops, something went wrong.