Skip to content

Commit

Permalink
Merge pull request #555 from ninoseki/update
Browse files Browse the repository at this point in the history
Update
  • Loading branch information
ninoseki authored Feb 25, 2023
2 parents fd1c337 + 94914ac commit baf93af
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/mihari/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Main < Base
include Mihari::Commands::Version
include Mihari::Commands::Web

desc "database", "Sub commands for database"
desc "db", "Sub commands for DB"
subcommand "db", Database

desc "rule", "Sub commands for rule"
Expand Down
4 changes: 4 additions & 0 deletions lib/mihari/commands/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def self.included(thor)
thor.class_eval do
desc "migrate", "Migrate DB schemas"
method_option :verbose, type: :boolean, default: true
#
# @param [String] direction
#
#
def migrate(direction = "up")
verbose = options["verbose"]
ActiveRecord::Migration.verbose = verbose
Expand Down
5 changes: 5 additions & 0 deletions lib/mihari/commands/searcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ def self.included(thor)
thor.class_eval do
desc "search [PATH]", "Search by a rule"
method_option :force_overwrite, type: :boolean, aliases: "-f", desc: "Force an overwrite the rule"
#
# Search by a rule
#
# @param [String] path_or_id
#
def search(path_or_id)
with_db_connection do
rule = Structs::Rule.from_path_or_id path_or_id
Expand Down
11 changes: 8 additions & 3 deletions lib/mihari/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,23 @@ def adapter
"sqlite3"
end

#
# @return [Array<ActiveRecord::Migration>] schemas
#
def schemas
[V5Schema]
end

module Mihari
class Database
class << self
include Memist::Memoizable

#
# DB migraration
#
# @param [Symbol] direction
#
def migrate(direction)
[V5Schema].each { |schema| schema.migrate direction }
schemas.each { |schema| schema.migrate direction }
end

#
Expand Down
2 changes: 2 additions & 0 deletions lib/mihari/mixins/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ module Database
def with_db_connection
Mihari::Database.connect
yield
rescue ActiveRecord::StatementInvalid
Mihari.logger.error("You haven't finished the DB migration! Please run 'mihari db migrate'.")
ensure
Mihari::Database.close
end
Expand Down

0 comments on commit baf93af

Please sign in to comment.