]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/dev/templates/default/rails.setup.rb.erb
nominatim: add automatic migration on updates
[chef.git] / cookbooks / dev / templates / default / rails.setup.rb.erb
index 269ac4355e7a85c452fcffbc8160ed5552541a12..ad42b68f723ed186eed5de0a80a436020c8f8d04 100644 (file)
@@ -1,41 +1,54 @@
-unless Object.const_defined?(:Rake) or Object.const_defined?(:POTLATCH2_KEY)
-  OpenStreetMap::Application.config.after_initialize do
+OpenStreetMap::Application.config.after_initialize do
+  if ActiveRecord::Base.connection.table_exists?(:client_applications)
     unless webmaster = User.find_by_email("webmaster@openstreetmap.org")
     unless webmaster = User.find_by_email("webmaster@openstreetmap.org")
-      webmaster = User.create({
-        :display_name => "OpenStreetMap Webmaster",
-        :email => "webmaster@openstreetmap.org",
-        :pass_crypt => SecureRandom.hex,
-        :status => "active"
-      }, :without_protection => true)
+      webmaster = User.new
+      webmaster.display_name = "OpenStreetMap Webmaster"
+      webmaster.email = "webmaster@openstreetmap.org"
+      webmaster.pass_crypt = SecureRandom.hex
+      webmaster.status = "active"
+      webmaster.save!
     end
 
     end
 
-    permissions = Hash[ClientApplication.all_permissions.map { |p| [ p, true ] }]
-
     unless id = webmaster.client_applications.find_by_name("iD")
     unless id = webmaster.client_applications.find_by_name("iD")
-      id = ClientApplication.create(permissions.merge({
-        :name => "iD",
-        :url => "http://<%= @site %>/",
-      }), :without_protection => true)
+      id = webmaster.client_applications.new
+      id.name = "iD"
+      id.url = "https://<%= @site %>/"
+      ClientApplication.all_permissions.each { |p| id[p] = true }
+      id.save!
     end
 
     end
 
-    ID_KEY = id.key
+    if Kernel.const_defined?("Settings")
+      Settings.id_key = id.key
+    else
+      ID_KEY = id.key
+    end
 
     unless potlatch = webmaster.client_applications.find_by_name("Potlatch 2")
 
     unless potlatch = webmaster.client_applications.find_by_name("Potlatch 2")
-      potlatch = ClientApplication.create(permissions.merge({
-        :name => "Potlatch 2",
-        :url => "http://<%= @site %>/",
-      }), :without_protection => true)
+      potlatch = webmaster.client_applications.new
+      potlatch.name = "Potlatch 2"
+      potlatch.url = "https://<%= @site %>/"
+      ClientApplication.all_permissions.each { |p| potlatch[p] = true }
+      potlatch.save!
     end
 
     end
 
-    POTLATCH2_KEY = potlatch.key
+    if Kernel.const_defined?("Settings")
+      Settings.potlatch2_key = potlatch.key
+    else
+      POTLATCH2_KEY = potlatch.key
+    end
 
     unless website = webmaster.client_applications.find_by_name("Web Site")
 
     unless website = webmaster.client_applications.find_by_name("Web Site")
-      website = ClientApplication.create(permissions.merge({
-        :name => "Web Site",
-        :url => "http://<%= @site %>/",
-      }), :without_protection => true)
+      website = webmaster.client_applications.new
+      website.name = "Web Site"
+      website.url = "https://<%= @site %>/"
+      ClientApplication.all_permissions.each { |p| website[p] = true }
+      website.save!
     end
 
     end
 
-    OAUTH_KEY = website.key
+    if Kernel.const_defined?("Settings")
+      Settings.oauth_key = website.key
+    else
+      OAUTH_KEY = website.key
+    end
   end
 end
   end
 end