require 'sequel/extensions/migration' module Legion module Data class Migration def initialize(connection, options = {}) options.merge!(default_options) { |_key, v1, _v2| v1 } migrate(options[:migration_path], connection) if options[:auto_migrate] end def default_options { auto_migrate: true, migration_path: __dir__ + '/migrations' } end def migrate(path, connection) Legion::Logging.debug("Running Legion::Data.migrate with path: #{path}") Sequel::Migrator.run(connection, path) Legion::Logging.info('Legion::Data finished migrations') rescue Sequel::Migrator::Error => e Legion::Logging.error(e.message) raise e rescue StandardError => e Legion::Logging.error(e.message) raise e unless Legion::Settings[:data][:migrations][:continue_on_fail] end end end end