Sha256: 76381adbb54ac8adda64259554b5c35b1f16328c3d0d60bfa3f48f5f58c4c515

Contents?: true

Size: 905 Bytes

Versions: 1

Compression:

Stored size: 905 Bytes

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legion-data-0.1.1 lib/legion/data/migration.rb