Sha256: 6cf8bf400c72ef5420365f89645f6ec8af4fa3cd8c8723ec2ec0e44564df820d

Contents?: true

Size: 1.58 KB

Versions: 41

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

module DataMigrate
  ##
  # Provides the definition method for data_schema.rb
  class Data < ActiveRecord::Schema
    # This method is based on the following two methods
    #   ActiveRecord::Schema#define
    #   ActiveRecord::ConnectionAdapters::SchemaStatements
    #     #assume_migrated_upto_version
    def define(info)
      DataMigrate::DataMigrator.assure_data_schema_table

      return if info[:version].blank?

      version = info[:version].to_i

      unless migrated.include?(version)
        execute "INSERT INTO #{sm_table} (version) VALUES ('#{version}')"
      end

      insert(version)
    end

    private

    def migrated
      @migrated ||= select_values("SELECT version FROM #{sm_table}").map(&:to_i)
    end

    def versions
      @versions ||= begin
        versions = []
        Dir.foreach(DataMigrate::DataMigrator.full_migrations_path) do |file|
          match_data = DataMigrate::DataMigrator.match(file)
          versions << match_data[1].to_i if match_data
        end
        versions
      end
    end

    def insert(version)
      inserted = Set.new
      (versions - migrated).each do |v|
        if inserted.include?(v)
          raise "Duplicate data migration #{v}. Please renumber your data " \
            "migrations to resolve the conflict."
        elsif v < version
          execute "INSERT INTO #{sm_table} (version) VALUES ('#{v}')"
          inserted << v
        end
      end
    end

    def sm_table
      quote_table_name(table_name)
    end

    def table_name
      DataMigrate::DataSchemaMigration.table_name
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
data_migrate-10.0.3.rc lib/data_migrate/data_schema.rb
data_migrate-10.0.0.rc1 lib/data_migrate/data_schema.rb
data_migrate-9.0.0 lib/data_migrate/data_schema.rb
data_migrate-8.5.0 lib/data_migrate/data_schema.rb
data_migrate-8.4.2 lib/data_migrate/data_schema.rb
data_migrate-8.4.1 lib/data_migrate/data_schema.rb
data_migrate-8.4.0 lib/data_migrate/data_schema.rb
data_migrate-8.3.0 lib/data_migrate/data_schema.rb
data_migrate-8.2.0 lib/data_migrate/data_schema.rb
data_migrate-8.1.1 lib/data_migrate/data_schema.rb
data_migrate-8.1.0 lib/data_migrate/data_schema.rb
data_migrate-8.0.0 lib/data_migrate/data_schema.rb
data_migrate-8.0.0.rc2 lib/data_migrate/data_schema.rb
data_migrate-8.0.0.rc1 lib/data_migrate/data_schema.rb
data_migrate-7.0.2 lib/data_migrate/data_schema.rb
data_migrate-7.0.1 lib/data_migrate/data_schema.rb
data_migrate-7.0.0 lib/data_migrate/data_schema.rb
data_migrate-6.8.0 lib/data_migrate/data_schema.rb
data_migrate-6.7.0 lib/data_migrate/data_schema.rb
data_migrate-6.6.2 lib/data_migrate/data_schema.rb