Sha256: a3eaa6a25a985d4fdf8f95f8224a50019c1e5c09d141daed82bac5cdd3f0c1a5

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module DataMigrate
  module Tasks
    module DataMigrateTasks
      extend self
      def migrations_paths
        @migrations_paths ||= DataMigrate.config.data_migrations_path
      end

      def dump
        if dump_schema_after_migration?
          filename = DataMigrate::DatabaseTasks.schema_file
          ActiveRecord::Base.establish_connection(DataMigrate.config.db_configuration) if DataMigrate.config.db_configuration
          File.open(filename, "w:utf-8") do |file|
            DataMigrate::SchemaDumper.dump(ActiveRecord::Base.connection, file)
          end
        end
      end

      def migrate
        target_version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil

        DataMigrate::DataMigrator.assure_data_schema_table
        DataMigrate::MigrationContext.new(migrations_paths).migrate(target_version)
      end

      def abort_if_pending_migrations(migrations, message)
        if migrations.any?
          puts "You have #{migrations.size} pending #{migrations.size > 1 ? 'migrations:' : 'migration:'}"
          migrations.each do |pending_migration|
            puts "  %4d %s" % [pending_migration[:version], pending_migration[:name]]
          end
          abort message
        end
      end

      def dump_schema_after_migration?
        if ActiveRecord.respond_to?(:dump_schema_after_migration)
          ActiveRecord.dump_schema_after_migration
        else
          ActiveRecord::Base.dump_schema_after_migration
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
data_migrate-8.0.0.rc1 lib/data_migrate/tasks/data_migrate_tasks.rb