]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-2726 Do not allow upgrade with Derby embedded database
authorSimon Brandhof <simon.brandhof@gmail.com>
Tue, 27 Sep 2011 15:29:13 +0000 (17:29 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Tue, 27 Sep 2011 15:29:13 +0000 (17:29 +0200)
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/setup/not_upgradable.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb

index 4a5a52c1310de2a831eb50f861b58822fef5161d..c777559cfc05723986b85a595185e10c85ba83e1 100644 (file)
@@ -66,7 +66,11 @@ class Api::ServerController < Api::ApiController
 
   def setup
     begin
-      DatabaseVersion.migrate_and_start unless DatabaseVersion.uptodate?
+      if !DatabaseVersion.upgradable?
+        raise "Upgrade is not supported. Please use a production-ready database."
+      end
+
+      DatabaseVersion.upgrade_and_start unless DatabaseVersion.uptodate?
       hash={:status => 'ok'}
       respond_to do |format|
         format.json{ render :json => jsonp(hash) }
index ddb4e0b3baa39bfc695933828583bfff4f59a104..5917f3b2f4d18b7e33c19462ba70e9edbf86e171 100644 (file)
@@ -27,21 +27,25 @@ class SetupController < ApplicationController
     
   def index
     if DatabaseVersion.uptodate?
-      render :template => "setup/index" 
+      render :template => 'setup/index'
     elsif ActiveRecord::Base.connected?
-      render :template => "setup/form", :layout => 'nonav'
+      render :template => (DatabaseVersion.upgradable? ? 'setup/form' : 'setup/not_upgradable'), :layout => 'nonav'
     else 
-      render :template => "setup/dbdown", :layout => 'nonav'
+      render :template => 'setup/dbdown', :layout => 'nonav'
     end
   end
 
   def maintenance
-    render :template => "setup/maintenance", :layout => 'nonav'
+    render :template => 'setup/maintenance', :layout => 'nonav'
   end
 
   def setup_database
-    # do not forget that this code is also in /api/server/setup (see api/server_controller.rb)
-    DatabaseVersion.migrate_and_start unless DatabaseVersion.uptodate?
-    redirect_to home_path
+    if !DatabaseVersion.upgradable?
+      render :text => 'Upgrade is not supported. Please use a production-ready database.', :status => 500
+    else
+      # do not forget that this code is also in /api/server/setup (see api/server_controller.rb)
+      DatabaseVersion.upgrade_and_start unless DatabaseVersion.uptodate?
+      redirect_to home_path
+    end
   end
 end
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/setup/not_upgradable.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/setup/not_upgradable.html.erb
new file mode 100644 (file)
index 0000000..bd3c0f1
--- /dev/null
@@ -0,0 +1,5 @@
+<h1>Not supported</h1>
+
+<div class="error">
+  Upgrade is not supported. Please use a <a href="http://docs.codehaus.org/display/SONAR/Requirements">production-ready database</a>.
+</div>
\ No newline at end of file
index 9dd1eed5611dad1480efdce20cacdd5dcf1c7ee9..e40d012dda04acd7e47a19aa0468f01a46156304 100644 (file)
@@ -59,7 +59,7 @@ class DatabaseVersion
     $uptodate
   end
 
-  def self.migrate_and_start
+  def self.upgrade_and_start
     ActiveRecord::Migrator.migrate(migrations_path)
     Java::OrgSonarServerPlatform::Platform.getInstance().start()
     load_plugin_webservices()
@@ -72,10 +72,12 @@ class DatabaseVersion
   def self.automatic_setup
     if current_version<=0
       try_restore_structure_dump() if use_structure_dump?
-      migrate_and_start()
+      upgrade_and_start()
     end
     if uptodate?
       load_plugin_webservices()
+    else
+      puts "Server must be upgraded. Please browse /setup"
     end
     uptodate?
   end
@@ -117,4 +119,8 @@ class DatabaseVersion
     # default value is true
     ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.useStructureDump')!='false'
   end
+
+  def self.upgradable?
+    dialect()!='derby'
+  end
 end
\ No newline at end of file