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.44 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.43 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.42 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.41 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.40 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.39 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.38 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.37 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.36 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.35 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.34 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.33 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.32 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.31 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.30 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.29 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.28 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.27 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.26 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb
ree_lib-1.0.24 lib/ree_lib/packages/ree_migrator/package/ree_migrator/functions/apply_migration.rb