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" 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 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 # 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