From 8b4970287bc5df535a08f6cd70992681cf6418af Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Sat, 25 Feb 2023 17:22:42 +0900 Subject: [PATCH 1/4] fix: fix typo --- lib/mihari/cli/main.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mihari/cli/main.rb b/lib/mihari/cli/main.rb index 6b21c99e..bbff22c9 100644 --- a/lib/mihari/cli/main.rb +++ b/lib/mihari/cli/main.rb @@ -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" From 862eacffd84de3eacb8bc37b368e38889edc3fd0 Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Sat, 25 Feb 2023 17:22:57 +0900 Subject: [PATCH 2/4] refactor: set param type --- lib/mihari/commands/database.rb | 4 ++++ lib/mihari/commands/searcher.rb | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/mihari/commands/database.rb b/lib/mihari/commands/database.rb index bacba298..d70e1a91 100644 --- a/lib/mihari/commands/database.rb +++ b/lib/mihari/commands/database.rb @@ -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 diff --git a/lib/mihari/commands/searcher.rb b/lib/mihari/commands/searcher.rb index c617dd3c..93c3e0ce 100644 --- a/lib/mihari/commands/searcher.rb +++ b/lib/mihari/commands/searcher.rb @@ -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 From 0d81c1575df4e2bb057892d77c53f72169ca5091 Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Sat, 25 Feb 2023 17:23:14 +0900 Subject: [PATCH 3/4] refactor: set schemas --- lib/mihari/database.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/mihari/database.rb b/lib/mihari/database.rb index 4ca06d97..f219af05 100644 --- a/lib/mihari/database.rb +++ b/lib/mihari/database.rb @@ -117,18 +117,23 @@ def adapter "sqlite3" end +# +# @return [Array] 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 # From 94914ac5b8a23e31378626be2d82a7cc353d9f17 Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Sat, 25 Feb 2023 17:23:40 +0900 Subject: [PATCH 4/4] refactor: set error message for ActiveRecord::StatementInvalid --- lib/mihari/mixins/database.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/mihari/mixins/database.rb b/lib/mihari/mixins/database.rb index 4683d303..e7c02e3b 100644 --- a/lib/mihari/mixins/database.rb +++ b/lib/mihari/mixins/database.rb @@ -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