class GeoserverMigrations::Migrator

Constants

MigrationFilenameRegexp

Public Instance Methods

any_migrations?() click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 56
def any_migrations?
  migrations(migrations_paths).any?
end
current_version() click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 48
def current_version
  get_all_versions.max || 0
end
get_all_versions() click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 40
def get_all_versions
  begin
    GeoserverMigration.all_versions.map(&:to_i)
  rescue
    []
  end
end
migrate() click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 7
def migrate
  if !any_migrations?
    puts "No migration files found!"
  else
    if !needs_migration?
      puts "There are no pending migrations."
    else
      pending_migrations.each do |migration|
        migration.assets_path = GeoserverMigrations.assets_path
        migration.migrate
        
        GeoserverMigration.set_migrated(migration)
      end
    end
  end
end
migration_files(paths) click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 103
def migration_files(paths)
  Dir[*paths.flat_map { |path| "#{path}/**/[0-9]*_*.rb" }]
end
migrations(paths) click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 88
def migrations(paths)
  paths = Array(paths)

  migrations = migration_files(paths).map do |file|
    version, name, scope = parse_migration_filename(file)
    raise GeoserverMigrations::IllegalMigrationNameError.new(file) unless version
    version = version.to_i
    name = name.camelize

    MigrationProxy.new(name, version, file, scope)
  end

  migrations.sort_by(&:version)
end
migrations_paths() click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 78
def migrations_paths
  @migrations_paths ||= ["geoserver/migrate"]
  # just to not break things if someone uses: migrations_path = some_string
  Array(@migrations_paths)
end
migrations_paths=(paths) click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 74
def migrations_paths=(paths)
  @migrations_paths = paths
end
needs_migration?() click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 52
def needs_migration?
  (migrations(migrations_paths).collect(&:version) - get_all_versions).size > 0
end
pending_migrations() click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 67
def pending_migrations
  already_migrated = get_all_versions
  migrations = migrations(migrations_paths)
  migrations.reject { |m| already_migrated.include?(m.version) }
end
rollback(steps=1) click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 25
def rollback(steps=1)
  if steps < 1
    puts "The nr of steps to rollback has to be at least 1"
  else
    rollback_migrations(steps).each do |migration|
      migration.assets_path = GeoserverMigrations.assets_path
      migration.migrate(:down)

      GeoserverMigration.set_reverted(migration)
    end
  end
end
rollback_migrations(steps=1) click to toggle source
# File lib/geoserver_migrations/migrator.rb, line 61
def rollback_migrations(steps=1)
  to_rollback = get_all_versions[0 - steps .. -1]
  migrations = migrations(migrations_paths)
  migrations.select { |m| to_rollback.include?(m.version) }
end