Sha256: 178a8221f479f2ba1e7894068c0793706edab6da56a9279ecd973ab587c10abb

Contents?: true

Size: 819 Bytes

Versions: 124

Compression:

Stored size: 819 Bytes

Contents

# frozen_string_literal: true

class ReeMigrator::ApplyMigration
  include Ree::FnDSL

  fn :apply_migration do
    link :now, from: :ree_datetime
    link :logger, from: :ree_logger
  end

  contract(
    Sequel::Database,
    String,
    Or[:schema, :data] => nil
  ).throws(ArgumentError)
  def call(connection, migration_path, type)
    if !File.exist?(migration_path)
      raise ArgumentError.new("file not found: #{migration_path}")
    end

    logger.info("Applying migration: #{migration_path}")
    load(migration_path)

    migration = Sequel::Migration.descendants.last
    migration_name = File.basename(migration_path)

    connection.instance_eval(&migration.up)

    connection[:migrations].insert({
      filename: migration_name,
      type: type.to_s,
      created_at: now
    })

    nil
  end
end

Version data entries

124 entries across 124 versions & 1 rubygems

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb