Class: GeoserverMigrations::Generators::StatusGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/geoserver_migrations/status/status_generator.rb

Instance Method Summary collapse

Instance Method Details

#check_statusObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/generators/geoserver_migrations/status/status_generator.rb', line 6

def check_status
  puts "Checking configuration ... "
  errors = []
  errors << "geoserver_base is not set" unless GeoserverMigrations.config[:geoserver_base].present?
  errors << "api-user is not set" unless       GeoserverMigrations.config[:api][:user].present?
  errors << "api-password is not set" unless GeoserverMigrations.config[:api][:password].present?

  errors << "Geoserver workspace is not set" unless GeoserverMigrations.config[:workspace].present?
  errors << "Geoserver datastore is not set" unless GeoserverMigrations.config[:datastore].present?

  unless errors.count > 0
    puts " --> Configuration ok"
  else
    puts "Problems with the configuration-file:\n #{errors.join("\n")}"
    puts "Check the documentation how to fix them"
    puts "Did you forget to edit the default config-file or to run rails g geoserver_migrations:install ?"
  end

  puts "Checking API reachability"
  begin
    layers = GeoserverMigrations::Base.connection.test
    puts " --> Connected to API correctly and retrieved #{layers.count} layers"
  rescue => e
    puts "    FAILED to reach Geoserver REST API."
    puts "    Error: #{e.message}"
  end

  puts "Checking database setup"
  begin
    count = GeoserverMigration.all_versions.count
    puts " --> Database is correctly setup"
  rescue => e
    puts "    Database is not setup correctly. Did you run rake db:migrate ?"
    puts "    The returned error is #{e.message}"
  end

  migrator = GeoserverMigrations::Migrator.new
  if migrator.needs_migration?
    puts "There are pending migrations."
  else
    puts "There are no pending migrations. Geoserver is up to date."
  end

end