aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2011-09-27 14:18:46 +0200
committerSimon Brandhof <simon.brandhof@gmail.com>2011-09-27 14:18:57 +0200
commitbfccff9675815ad796d1b73c330a95acd2b96c13 (patch)
treee7ff80203c3af714f29355a4c26ccdea549814b5
parent24b35ccec51c57c47b301893e46c96c92cfdfe6d (diff)
downloadsonarqube-bfccff9675815ad796d1b73c330a95acd2b96c13.tar.gz
sonarqube-bfccff9675815ad796d1b73c330a95acd2b96c13.zip
SONAR-2839 Speed up server startup when using Derby
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/migrate/README.txt2
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/structure/derby.ddl257
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/db/structure/derby.sql179
-rw-r--r--sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb41
6 files changed, 477 insertions, 6 deletions
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
index fe5697b7f76..4a5a52c1310 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/server_controller.rb
@@ -66,7 +66,7 @@ class Api::ServerController < Api::ApiController
def setup
begin
- DatabaseVersion.setup unless DatabaseVersion.uptodate?
+ DatabaseVersion.migrate_and_start unless DatabaseVersion.uptodate?
hash={:status => 'ok'}
respond_to do |format|
format.json{ render :json => jsonp(hash) }
diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb
index e3564346ad2..ddb4e0b3baa 100644
--- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/setup_controller.rb
@@ -41,7 +41,7 @@ class SetupController < ApplicationController
def setup_database
# do not forget that this code is also in /api/server/setup (see api/server_controller.rb)
- DatabaseVersion.setup unless DatabaseVersion.uptodate?
+ DatabaseVersion.migrate_and_start unless DatabaseVersion.uptodate?
redirect_to home_path
end
end
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/migrate/README.txt b/sonar-server/src/main/webapp/WEB-INF/db/migrate/README.txt
index 52ae0b9f36b..752c79ebff3 100644
--- a/sonar-server/src/main/webapp/WEB-INF/db/migrate/README.txt
+++ b/sonar-server/src/main/webapp/WEB-INF/db/migrate/README.txt
@@ -2,4 +2,4 @@ Don't forget that index name limited to 30 characters in Oracle DB.
Prefer to add nullable columns to avoid problems during migration.
-After adding migration script - don't forget to update sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java
+After adding migration script - don't forget to update sonar-core/src/main/java/org/sonar/jpa/entity/SchemaMigration.java and ../structure/derby.*
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/structure/derby.ddl b/sonar-server/src/main/webapp/WEB-INF/db/structure/derby.ddl
new file mode 100644
index 00000000000..2594c90feea
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/structure/derby.ddl
@@ -0,0 +1,257 @@
+-- Structure of version 2.11
+
+-- This file has been generated manually :
+-- 1. start sonar with property sonar.useStructureDump=false
+-- 2. execute $DERBY_HOME/bin/dblook -d 'jdbc:derby://localhost:1527/sonar;user=sonar;password=sonar' -o /derby.ddl
+-- 3. copy the generated derby.ddl into this file
+
+CREATE TABLE "SONAR"."QUALITY_MODELS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(100));
+
+CREATE TABLE "SONAR"."GROUPS_USERS" ("USER_ID" INTEGER, "GROUP_ID" INTEGER);
+
+CREATE TABLE "SONAR"."CHARACTERISTIC_EDGES" ("CHILD_ID" INTEGER, "PARENT_ID" INTEGER);
+
+CREATE TABLE "SONAR"."CRITERIA" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "FILTER_ID" INTEGER, "FAMILY" VARCHAR(100), "KEE" VARCHAR(100), "OPERATOR" VARCHAR(20), "VALUE" DECIMAL(30,20), "TEXT_VALUE" VARCHAR(256), "VARIATION" SMALLINT);
+
+CREATE TABLE "SONAR"."DEPENDENCIES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "FROM_SNAPSHOT_ID" INTEGER, "FROM_RESOURCE_ID" INTEGER, "TO_SNAPSHOT_ID" INTEGER, "TO_RESOURCE_ID" INTEGER, "DEP_USAGE" VARCHAR(30), "DEP_WEIGHT" INTEGER, "PROJECT_SNAPSHOT_ID" INTEGER, "PARENT_DEPENDENCY_ID" BIGINT, "FROM_SCOPE" VARCHAR(3), "TO_SCOPE" VARCHAR(3));
+
+CREATE TABLE "SONAR"."CHARACTERISTICS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "QUALITY_MODEL_ID" INTEGER, "KEE" VARCHAR(100), "NAME" VARCHAR(100), "RULE_ID" INTEGER, "DEPTH" INTEGER, "CHARACTERISTIC_ORDER" INTEGER, "DESCRIPTION" VARCHAR(4000), "ENABLED" SMALLINT);
+
+CREATE TABLE "SONAR"."RULES_PARAMETERS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "RULE_ID" INTEGER NOT NULL, "NAME" VARCHAR(128) NOT NULL, "PARAM_TYPE" VARCHAR(512) NOT NULL, "DEFAULT_VALUE" VARCHAR(4000), "DESCRIPTION" VARCHAR(4000));
+
+CREATE TABLE "SONAR"."RULES_PROFILES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(100) NOT NULL, "DEFAULT_PROFILE" SMALLINT DEFAULT 0, "PROVIDED" SMALLINT NOT NULL DEFAULT 0, "LANGUAGE" VARCHAR(16), "PARENT_NAME" VARCHAR(100), "ENABLED" SMALLINT NOT NULL DEFAULT 1, "VERSION" INTEGER DEFAULT 1, "USED_PROFILE" SMALLINT DEFAULT 0);
+
+CREATE TABLE "SONAR"."WIDGETS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "DASHBOARD_ID" INTEGER NOT NULL, "WIDGET_KEY" VARCHAR(256) NOT NULL, "NAME" VARCHAR(256), "DESCRIPTION" VARCHAR(1000), "COLUMN_INDEX" INTEGER, "ROW_INDEX" INTEGER, "CONFIGURED" SMALLINT, "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP);
+
+CREATE TABLE "SONAR"."FILTER_COLUMNS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "FILTER_ID" INTEGER, "FAMILY" VARCHAR(100), "KEE" VARCHAR(100), "SORT_DIRECTION" VARCHAR(5), "ORDER_INDEX" INTEGER, "VARIATION" SMALLINT);
+
+CREATE TABLE "SONAR"."MEASURE_DATA" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "MEASURE_ID" INTEGER, "SNAPSHOT_ID" INTEGER, "DATA" BLOB(2147483647));
+
+CREATE TABLE "SONAR"."GROUPS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(40), "DESCRIPTION" VARCHAR(200), "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP);
+
+CREATE TABLE "SONAR"."ACTIVE_RULE_PARAM_CHANGES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "ACTIVE_RULE_CHANGE_ID" INTEGER NOT NULL, "RULES_PARAMETER_ID" INTEGER NOT NULL, "OLD_VALUE" VARCHAR(4000), "NEW_VALUE" VARCHAR(4000));
+
+CREATE TABLE "SONAR"."SNAPSHOTS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "CREATED_AT" TIMESTAMP, "PROJECT_ID" INTEGER NOT NULL, "PARENT_SNAPSHOT_ID" INTEGER, "STATUS" VARCHAR(4) NOT NULL DEFAULT 'U', "ISLAST" SMALLINT NOT NULL DEFAULT 0, "SCOPE" VARCHAR(3), "QUALIFIER" VARCHAR(3), "ROOT_SNAPSHOT_ID" INTEGER, "VERSION" VARCHAR(60), "PATH" VARCHAR(96), "DEPTH" INTEGER, "ROOT_PROJECT_ID" INTEGER, "PERIOD1_MODE" VARCHAR(100), "PERIOD1_PARAM" VARCHAR(100), "PERIOD1_DATE" TIMESTAMP, "PERIOD2_MODE" VARCHAR(100), "PERIOD2_PARAM" VARCHAR(100), "PERIOD2_DATE" TIMESTAMP, "PERIOD3_MODE" VARCHAR(100), "PERIOD3_PARAM" VARCHAR(100), "PERIOD3_DATE" TIMESTAMP, "PERIOD4_MODE" VARCHAR(100), "PERIOD4_PARAM" VARCHAR(100), "PERIOD4_DATE" TIMESTAMP, "PERIOD5_MODE" VARCHAR(100), "PERIOD5_PARAM" VARCHAR(100), "PERIOD5_DATE" TIMESTAMP);
+
+CREATE TABLE "SONAR"."SCHEMA_MIGRATIONS" ("VERSION" VARCHAR(256) NOT NULL);
+
+CREATE TABLE "SONAR"."GROUP_ROLES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "GROUP_ID" INTEGER, "RESOURCE_ID" INTEGER, "ROLE" VARCHAR(64) NOT NULL);
+
+CREATE TABLE "SONAR"."RULES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "PLUGIN_RULE_KEY" VARCHAR(200) NOT NULL, "PLUGIN_NAME" VARCHAR(255) NOT NULL, "DESCRIPTION" CLOB(2147483647), "PRIORITY" INTEGER, "ENABLED" SMALLINT, "CARDINALITY" VARCHAR(10), "PARENT_ID" INTEGER, "PLUGIN_CONFIG_KEY" VARCHAR(500), "NAME" VARCHAR(200));
+
+CREATE TABLE "SONAR"."WIDGET_PROPERTIES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "WIDGET_ID" INTEGER NOT NULL, "KEE" VARCHAR(100), "TEXT_VALUE" VARCHAR(4000), "VALUE_TYPE" VARCHAR(20));
+
+CREATE TABLE "SONAR"."EVENTS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(50), "RESOURCE_ID" INTEGER, "SNAPSHOT_ID" INTEGER, "CATEGORY" VARCHAR(50), "EVENT_DATE" TIMESTAMP, "CREATED_AT" TIMESTAMP, "DESCRIPTION" VARCHAR(3072), "DATA" VARCHAR(4000));
+
+CREATE TABLE "SONAR"."ALERTS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "PROFILE_ID" INTEGER, "METRIC_ID" INTEGER, "OPERATOR" VARCHAR(3), "VALUE_ERROR" VARCHAR(64), "VALUE_WARNING" VARCHAR(64));
+
+CREATE TABLE "SONAR"."PROPERTIES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "PROP_KEY" VARCHAR(512), "RESOURCE_ID" INTEGER, "TEXT_VALUE" CLOB(2147483647), "USER_ID" INTEGER);
+
+CREATE TABLE "SONAR"."PROJECT_LINKS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "PROJECT_ID" INTEGER NOT NULL, "LINK_TYPE" VARCHAR(20), "NAME" VARCHAR(128), "HREF" VARCHAR(2048) NOT NULL);
+
+CREATE TABLE "SONAR"."DUPLICATIONS_INDEX" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "PROJECT_SNAPSHOT_ID" INTEGER NOT NULL, "SNAPSHOT_ID" INTEGER NOT NULL, "HASH" VARCHAR(50) NOT NULL, "INDEX_IN_FILE" INTEGER NOT NULL, "START_LINE" INTEGER NOT NULL, "END_LINE" INTEGER NOT NULL);
+
+CREATE TABLE "SONAR"."REVIEW_COMMENTS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP, "REVIEW_ID" INTEGER, "USER_ID" INTEGER, "REVIEW_TEXT" CLOB(2147483647));
+
+CREATE TABLE "SONAR"."ACTIVE_RULE_CHANGES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "USER_NAME" VARCHAR(200) NOT NULL, "PROFILE_ID" INTEGER NOT NULL, "PROFILE_VERSION" INTEGER NOT NULL, "RULE_ID" INTEGER NOT NULL, "CHANGE_DATE" TIMESTAMP NOT NULL, "ENABLED" SMALLINT, "OLD_SEVERITY" INTEGER, "NEW_SEVERITY" INTEGER);
+
+CREATE TABLE "SONAR"."PROJECT_MEASURES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "VALUE" DECIMAL(30,20), "METRIC_ID" INTEGER NOT NULL, "SNAPSHOT_ID" INTEGER, "RULE_ID" INTEGER, "RULES_CATEGORY_ID" INTEGER, "TEXT_VALUE" VARCHAR(96), "TENDENCY" INTEGER, "MEASURE_DATE" TIMESTAMP, "PROJECT_ID" INTEGER, "ALERT_STATUS" VARCHAR(5), "ALERT_TEXT" VARCHAR(4000), "URL" VARCHAR(2000), "DESCRIPTION" VARCHAR(4000), "RULE_PRIORITY" INTEGER, "CHARACTERISTIC_ID" INTEGER, "VARIATION_VALUE_1" DECIMAL(30,20), "VARIATION_VALUE_2" DECIMAL(30,20), "VARIATION_VALUE_3" DECIMAL(30,20), "VARIATION_VALUE_4" DECIMAL(30,20), "VARIATION_VALUE_5" DECIMAL(30,20));
+
+CREATE TABLE "SONAR"."SNAPSHOT_SOURCES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "SNAPSHOT_ID" INTEGER NOT NULL, "DATA" CLOB(2147483647));
+
+CREATE TABLE "SONAR"."PROJECTS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(256), "DESCRIPTION" VARCHAR(2000), "ENABLED" SMALLINT NOT NULL DEFAULT 1, "SCOPE" VARCHAR(3), "QUALIFIER" VARCHAR(3), "KEE" VARCHAR(400), "ROOT_ID" INTEGER, "PROFILE_ID" INTEGER, "LANGUAGE" VARCHAR(5), "COPY_RESOURCE_ID" INTEGER, "LONG_NAME" VARCHAR(256));
+
+CREATE TABLE "SONAR"."REVIEWS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP, "USER_ID" INTEGER, "ASSIGNEE_ID" INTEGER, "TITLE" VARCHAR(500), "STATUS" VARCHAR(10), "SEVERITY" VARCHAR(10), "RULE_FAILURE_PERMANENT_ID" INTEGER, "PROJECT_ID" INTEGER, "RESOURCE_ID" INTEGER, "RESOURCE_LINE" INTEGER, "RESOLUTION" VARCHAR(200));
+
+CREATE TABLE "SONAR"."RULES_CATEGORIES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(255) NOT NULL, "DESCRIPTION" VARCHAR(1000) NOT NULL);
+
+CREATE TABLE "SONAR"."ACTIVE_FILTERS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "FILTER_ID" INTEGER, "USER_ID" INTEGER, "ORDER_INDEX" INTEGER);
+
+CREATE TABLE "SONAR"."MANUAL_MEASURES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "METRIC_ID" INTEGER NOT NULL, "RESOURCE_ID" INTEGER, "VALUE" DECIMAL(30,20), "TEXT_VALUE" VARCHAR(4000), "USER_LOGIN" VARCHAR(40), "DESCRIPTION" VARCHAR(4000), "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP);
+
+CREATE TABLE "SONAR"."ACTIVE_RULES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "PROFILE_ID" INTEGER NOT NULL, "RULE_ID" INTEGER NOT NULL, "FAILURE_LEVEL" INTEGER NOT NULL, "INHERITANCE" VARCHAR(10));
+
+CREATE TABLE "SONAR"."NOTIFICATIONS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "CREATED_AT" TIMESTAMP, "DATA" BLOB(2147483647));
+
+CREATE TABLE "SONAR"."USER_ROLES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "USER_ID" INTEGER, "RESOURCE_ID" INTEGER, "ROLE" VARCHAR(64) NOT NULL);
+
+CREATE TABLE "SONAR"."ACTIVE_DASHBOARDS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "DASHBOARD_ID" INTEGER NOT NULL, "USER_ID" INTEGER, "ORDER_INDEX" INTEGER);
+
+CREATE TABLE "SONAR"."ACTIVE_RULE_PARAMETERS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "ACTIVE_RULE_ID" INTEGER NOT NULL, "RULES_PARAMETER_ID" INTEGER NOT NULL, "VALUE" VARCHAR(4000));
+
+CREATE TABLE "SONAR"."CHARACTERISTIC_PROPERTIES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "CHARACTERISTIC_ID" INTEGER, "KEE" VARCHAR(100), "VALUE" DECIMAL(30,20), "TEXT_VALUE" VARCHAR(4000));
+
+CREATE TABLE "SONAR"."USERS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "LOGIN" VARCHAR(40), "NAME" VARCHAR(200), "EMAIL" VARCHAR(100), "CRYPTED_PASSWORD" VARCHAR(40), "SALT" VARCHAR(40), "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP, "REMEMBER_TOKEN" VARCHAR(500), "REMEMBER_TOKEN_EXPIRES_AT" TIMESTAMP);
+
+CREATE TABLE "SONAR"."FILTERS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(100), "USER_ID" INTEGER, "SHARED" SMALLINT, "FAVOURITES" SMALLINT, "RESOURCE_ID" INTEGER, "DEFAULT_VIEW" VARCHAR(20), "PAGE_SIZE" INTEGER, "PERIOD_INDEX" INTEGER);
+
+CREATE TABLE "SONAR"."DASHBOARDS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "USER_ID" INTEGER, "NAME" VARCHAR(256), "DESCRIPTION" VARCHAR(1000), "COLUMN_LAYOUT" VARCHAR(20), "SHARED" SMALLINT, "CREATED_AT" TIMESTAMP, "UPDATED_AT" TIMESTAMP);
+
+CREATE TABLE "SONAR"."RULE_FAILURES" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "SNAPSHOT_ID" INTEGER NOT NULL, "RULE_ID" INTEGER NOT NULL, "FAILURE_LEVEL" INTEGER NOT NULL, "MESSAGE" VARCHAR(4000), "LINE" INTEGER, "COST" DECIMAL(30,20), "CREATED_AT" TIMESTAMP, "CHECKSUM" VARCHAR(1000), "PERMANENT_ID" INTEGER, "SWITCHED_OFF" SMALLINT);
+
+CREATE TABLE "SONAR"."METRICS" ("ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), "NAME" VARCHAR(64) NOT NULL, "DESCRIPTION" VARCHAR(255), "DIRECTION" INTEGER NOT NULL DEFAULT 0, "DOMAIN" VARCHAR(64), "SHORT_NAME" VARCHAR(64), "QUALITATIVE" SMALLINT NOT NULL DEFAULT 0, "VAL_TYPE" VARCHAR(8), "USER_MANAGED" SMALLINT DEFAULT 0, "ENABLED" SMALLINT DEFAULT 1, "ORIGIN" VARCHAR(3), "WORST_VALUE" DECIMAL(30,20), "BEST_VALUE" DECIMAL(30,20), "OPTIMIZED_BEST_VALUE" SMALLINT, "HIDDEN" SMALLINT);
+
+-- ----------------------------------------------
+-- DDL Statements for indexes
+-- ----------------------------------------------
+
+CREATE INDEX "SONAR"."GROUP_ROLES_RESOURCE" ON "SONAR"."GROUP_ROLES" ("RESOURCE_ID");
+
+CREATE INDEX "SONAR"."GROUP_ROLES_GROUP" ON "SONAR"."GROUP_ROLES" ("GROUP_ID");
+
+CREATE INDEX "SONAR"."USER_ROLES_RESOURCE" ON "SONAR"."USER_ROLES" ("RESOURCE_ID");
+
+CREATE INDEX "SONAR"."USER_ROLES_USER" ON "SONAR"."USER_ROLES" ("USER_ID");
+
+CREATE INDEX "SONAR"."DUPLICATIONS_INDEX_HASH" ON "SONAR"."DUPLICATIONS_INDEX" ("HASH");
+
+CREATE INDEX "SONAR"."DUPLICATIONS_INDEX_SID" ON "SONAR"."DUPLICATIONS_INDEX" ("SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."DUPLICATIONS_INDEX_PSID" ON "SONAR"."DUPLICATIONS_INDEX" ("PROJECT_SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."SNAP_SOURCES_SNAPSHOT_ID" ON "SONAR"."SNAPSHOT_SOURCES" ("SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."INDEX_GROUPS_USERS_ON_GROUP_ID" ON "SONAR"."GROUPS_USERS" ("GROUP_ID");
+
+CREATE INDEX "SONAR"."INDEX_GROUPS_USERS_ON_USER_ID" ON "SONAR"."GROUPS_USERS" ("USER_ID");
+
+CREATE INDEX "SONAR"."DEPS_TO_SID" ON "SONAR"."DEPENDENCIES" ("TO_SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."DEPS_FROM_SID" ON "SONAR"."DEPENDENCIES" ("FROM_SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."MEASURES_SID_METRIC" ON "SONAR"."PROJECT_MEASURES" ("SNAPSHOT_ID", "METRIC_ID");
+
+CREATE INDEX "SONAR"."ACTIVE_RULE_CHANGES_PID" ON "SONAR"."ACTIVE_RULE_CHANGES" ("PROFILE_ID");
+
+CREATE INDEX "SONAR"."CHARACTERISTIC_PROPERTIES_CID" ON "SONAR"."CHARACTERISTIC_PROPERTIES" ("CHARACTERISTIC_ID");
+
+CREATE UNIQUE INDEX "SONAR"."METRICS_UNIQUE_NAME" ON "SONAR"."METRICS" ("NAME");
+
+CREATE INDEX "SONAR"."ACTIVE_RULE_PARAM_CHANGES_CID" ON "SONAR"."ACTIVE_RULE_PARAM_CHANGES" ("ACTIVE_RULE_CHANGE_ID");
+
+CREATE INDEX "SONAR"."M_DATA_SID" ON "SONAR"."MEASURE_DATA" ("SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."MEASURE_DATA_MEASURE_ID" ON "SONAR"."MEASURE_DATA" ("MEASURE_ID");
+
+CREATE INDEX "SONAR"."RF_PERMANENT_ID" ON "SONAR"."RULE_FAILURES" ("PERMANENT_ID");
+
+CREATE INDEX "SONAR"."RULE_FAILURE_RULE_ID" ON "SONAR"."RULE_FAILURES" ("RULE_ID");
+
+CREATE INDEX "SONAR"."RULE_FAILURE_SNAPSHOT_ID" ON "SONAR"."RULE_FAILURES" ("SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."EVENTS_SNAPSHOT_ID" ON "SONAR"."EVENTS" ("SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."EVENTS_RESOURCE_ID" ON "SONAR"."EVENTS" ("RESOURCE_ID");
+
+CREATE INDEX "SONAR"."WIDGETS_WIDGETKEY" ON "SONAR"."WIDGETS" ("WIDGET_KEY");
+
+CREATE INDEX "SONAR"."WIDGETS_DASHBOARDS" ON "SONAR"."WIDGETS" ("DASHBOARD_ID");
+
+CREATE INDEX "SONAR"."SNAPSHOTS_QUALIFIER" ON "SONAR"."SNAPSHOTS" ("QUALIFIER");
+
+CREATE INDEX "SONAR"."SNAPSHOTS_ROOT" ON "SONAR"."SNAPSHOTS" ("ROOT_SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."SNAPSHOTS_PARENT" ON "SONAR"."SNAPSHOTS" ("PARENT_SNAPSHOT_ID");
+
+CREATE INDEX "SONAR"."SNAPSHOT_PROJECT_ID" ON "SONAR"."SNAPSHOTS" ("PROJECT_ID");
+
+CREATE INDEX "SONAR"."RULES_PARAMETERS_RULE_ID" ON "SONAR"."RULES_PARAMETERS" ("RULE_ID");
+
+CREATE INDEX "SONAR"."ACTIVE_DASHBOARDS_DASHBOARDID" ON "SONAR"."ACTIVE_DASHBOARDS" ("DASHBOARD_ID");
+
+CREATE INDEX "SONAR"."ACTIVE_DASHBOARDS_USERID" ON "SONAR"."ACTIVE_DASHBOARDS" ("USER_ID");
+
+CREATE UNIQUE INDEX "SONAR"."UNIQUE_SCHEMA_MIGRATIONS" ON "SONAR"."SCHEMA_MIGRATIONS" ("VERSION");
+
+CREATE INDEX "SONAR"."WIDGET_PROPERTIES_WIDGETS" ON "SONAR"."WIDGET_PROPERTIES" ("WIDGET_ID");
+
+CREATE INDEX "SONAR"."PROPERTIES_KEY" ON "SONAR"."PROPERTIES" ("PROP_KEY");
+
+CREATE INDEX "SONAR"."MANUAL_MEASURES_RESOURCE_ID" ON "SONAR"."MANUAL_MEASURES" ("RESOURCE_ID");
+
+CREATE INDEX "SONAR"."PROJECTS_KEE" ON "SONAR"."PROJECTS" ("KEE");
+
+-- ----------------------------------------------
+-- DDL Statements for keys
+-- ----------------------------------------------
+
+-- primary/unique
+ALTER TABLE "SONAR"."GROUP_ROLES" ADD CONSTRAINT "SQL110927104437910" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."REVIEWS" ADD CONSTRAINT "SQL110927104440700" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."RULES" ADD CONSTRAINT "SQL110927104437080" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."USER_ROLES" ADD CONSTRAINT "SQL110927104437940" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."DUPLICATIONS_INDEX" ADD CONSTRAINT "SQL110927104441080" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."SNAPSHOT_SOURCES" ADD CONSTRAINT "SQL110927104437590" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."NOTIFICATIONS" ADD CONSTRAINT "SQL110927104441030" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."RULES_CATEGORIES" ADD CONSTRAINT "SQL110927104437060" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."DEPENDENCIES" ADD CONSTRAINT "SQL110927104438330" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."PROJECT_MEASURES" ADD CONSTRAINT "SQL110927104437040" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."ACTIVE_RULE_CHANGES" ADD CONSTRAINT "SQL110927104440770" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."CHARACTERISTIC_PROPERTIES" ADD CONSTRAINT "SQL110927104439660" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."QUALITY_MODELS" ADD CONSTRAINT "SQL110927104439440" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."USERS" ADD CONSTRAINT "SQL110927104437310" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."CRITERIA" ADD CONSTRAINT "SQL110927104438720" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."METRICS" ADD CONSTRAINT "SQL110927104436990" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."ACTIVE_RULE_PARAM_CHANGES" ADD CONSTRAINT "SQL110927104440790" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."MEASURE_DATA" ADD CONSTRAINT "SQL110927104437810" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."RULE_FAILURES" ADD CONSTRAINT "SQL110927104437100" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."EVENTS" ADD CONSTRAINT "SQL110927104437690" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."WIDGETS" ADD CONSTRAINT "SQL110927104439750" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."SNAPSHOTS" ADD CONSTRAINT "SQL110927104436960" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."ACTIVE_RULES" ADD CONSTRAINT "SQL110927104437550" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."CHARACTERISTICS" ADD CONSTRAINT "SQL110927104439450" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."RULES_PARAMETERS" ADD CONSTRAINT "SQL110927104437130" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."ACTIVE_FILTERS" ADD CONSTRAINT "SQL110927104438740" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."ACTIVE_DASHBOARDS" ADD CONSTRAINT "SQL110927104439710" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."FILTER_COLUMNS" ADD CONSTRAINT "SQL110927104438710" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."REVIEW_COMMENTS" ADD CONSTRAINT "SQL110927104440710" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."WIDGET_PROPERTIES" ADD CONSTRAINT "SQL110927104439770" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."PROPERTIES" ADD CONSTRAINT "SQL110927104437750" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."DASHBOARDS" ADD CONSTRAINT "SQL110927104439740" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."GROUPS" ADD CONSTRAINT "SQL110927104437850" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."PROJECT_LINKS" ADD CONSTRAINT "SQL110927104437150" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."FILTERS" ADD CONSTRAINT "SQL110927104438690" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."MANUAL_MEASURES" ADD CONSTRAINT "SQL110927104440930" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."ALERTS" ADD CONSTRAINT "SQL110927104437730" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."PROJECTS" ADD CONSTRAINT "SQL110927104436930" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."RULES_PROFILES" ADD CONSTRAINT "SQL110927104437540" PRIMARY KEY ("ID");
+
+ALTER TABLE "SONAR"."ACTIVE_RULE_PARAMETERS" ADD CONSTRAINT "SQL110927104437560" PRIMARY KEY ("ID"); \ No newline at end of file
diff --git a/sonar-server/src/main/webapp/WEB-INF/db/structure/derby.sql b/sonar-server/src/main/webapp/WEB-INF/db/structure/derby.sql
new file mode 100644
index 00000000000..b939fe86d44
--- /dev/null
+++ b/sonar-server/src/main/webapp/WEB-INF/db/structure/derby.sql
@@ -0,0 +1,179 @@
+-- Version 2.11
+
+-- All the rows inserted during Rails migrations. Rows inserted during server startup tasks (Java) are excluded : rules, profiles, metrics, ...
+-- Note: do not split a request on multiple lines.
+INSERT INTO SONAR.ACTIVE_DASHBOARDS(ID, DASHBOARD_ID, USER_ID, ORDER_INDEX) VALUES (1, 1, null, 1);
+ALTER TABLE SONAR.ACTIVE_DASHBOARDS ALTER COLUMN ID RESTART WITH 2;
+
+INSERT INTO SONAR.ACTIVE_FILTERS(ID, FILTER_ID, USER_ID, ORDER_INDEX) VALUES (1, 1, null, 1);
+INSERT INTO SONAR.ACTIVE_FILTERS(ID, FILTER_ID, USER_ID, ORDER_INDEX) VALUES (2, 2, null, 2);
+INSERT INTO SONAR.ACTIVE_FILTERS(ID, FILTER_ID, USER_ID, ORDER_INDEX) VALUES (3, 3, null, 3);
+ALTER TABLE SONAR.ACTIVE_FILTERS ALTER COLUMN ID RESTART WITH 4;
+
+INSERT INTO SONAR.CRITERIA(ID, FILTER_ID, FAMILY, KEE, OPERATOR, VALUE, TEXT_VALUE, VARIATION) VALUES (1, 1, 'qualifier', null, '=', null, 'TRK', null);
+INSERT INTO SONAR.CRITERIA(ID, FILTER_ID, FAMILY, KEE, OPERATOR, VALUE, TEXT_VALUE, VARIATION) VALUES (2, 2, 'qualifier', null, '=', null, 'TRK', null);
+INSERT INTO SONAR.CRITERIA(ID, FILTER_ID, FAMILY, KEE, OPERATOR, VALUE, TEXT_VALUE, VARIATION) VALUES (3, 3, 'qualifier', null, '=', null, 'VW,SVW,TRK,BRC,DIR,PAC,FIL,CLA,UTS,LIB', null);
+ALTER TABLE SONAR.CRITERIA ALTER COLUMN ID RESTART WITH 4;
+
+INSERT INTO SONAR.DASHBOARDS(ID, USER_ID, NAME, DESCRIPTION, COLUMN_LAYOUT, SHARED, CREATED_AT, UPDATED_AT) VALUES (1, null, 'Dashboard', 'Default dashboard', '50%-50%', 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
+ALTER TABLE SONAR.DASHBOARDS ALTER COLUMN ID RESTART WITH 2;
+
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (1, 1, 'metric', 'alert_status', null, 1, null);
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (2, 1, 'name', null, 'ASC', 2, null);
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (3, 1, 'version', null, null, 3, null);
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (4, 1, 'metric', 'ncloc', null, 4, null);
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (5, 1, 'metric', 'violations_density', null, 5, null);
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (6, 1, 'date', null, null, 6, null)
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (7, 1, 'links', null, null, 7, null)
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (8, 2, 'name', null, 'ASC', 1, null)
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (9, 2, 'metric', 'ncloc', null, 2, null)
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (10, 2, 'metric', 'violations_density', null, 3, null)
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (11, 3, 'metric', 'alert_status', null, 1, null)
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (12, 3, 'name', null, 'ASC', 2, null)
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (13, 3, 'metric', 'ncloc', null, 3, null)
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (14, 3, 'metric', 'violations_density', null, 4, null)
+INSERT INTO SONAR.FILTER_COLUMNS(ID, FILTER_ID, FAMILY, KEE, SORT_DIRECTION, ORDER_INDEX, VARIATION) VALUES (15, 3, 'date', null, null, 5, null)
+ALTER TABLE SONAR.FILTER_COLUMNS ALTER COLUMN ID RESTART WITH 16;
+
+INSERT INTO SONAR.FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (1, 'Projects', null, 1, 0, null, 'list', null, null)
+INSERT INTO SONAR.FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (2, 'Treemap', null, 1, 0, null, 'treemap', null, null)
+INSERT INTO SONAR.FILTERS(ID, NAME, USER_ID, SHARED, FAVOURITES, RESOURCE_ID, DEFAULT_VIEW, PAGE_SIZE, PERIOD_INDEX) VALUES (3, 'My favourites', null, 1, 1, null, 'list', null, null)
+ALTER TABLE SONAR.FILTERS ALTER COLUMN ID RESTART WITH 4;
+
+INSERT INTO SONAR.GROUP_ROLES(ID, GROUP_ID, RESOURCE_ID, ROLE) VALUES (1, 1, null, 'admin')
+INSERT INTO SONAR.GROUP_ROLES(ID, GROUP_ID, RESOURCE_ID, ROLE) VALUES (2, 1, null, 'default-admin')
+INSERT INTO SONAR.GROUP_ROLES(ID, GROUP_ID, RESOURCE_ID, ROLE) VALUES (3, 2, null, 'default-user')
+INSERT INTO SONAR.GROUP_ROLES(ID, GROUP_ID, RESOURCE_ID, ROLE) VALUES (4, null, null, 'default-user')
+INSERT INTO SONAR.GROUP_ROLES(ID, GROUP_ID, RESOURCE_ID, ROLE) VALUES (5, 2, null, 'default-codeviewer')
+INSERT INTO SONAR.GROUP_ROLES(ID, GROUP_ID, RESOURCE_ID, ROLE) VALUES (6, null, null, 'default-codeviewer')
+ALTER TABLE SONAR.GROUP_ROLES ALTER COLUMN ID RESTART WITH 7;
+
+INSERT INTO SONAR.GROUPS(ID, NAME, DESCRIPTION, CREATED_AT, UPDATED_AT) VALUES (1, 'sonar-administrators', 'System administrators', '2011-09-26 22:27:51.0', '2011-09-26 22:27:51.0')
+INSERT INTO SONAR.GROUPS(ID, NAME, DESCRIPTION, CREATED_AT, UPDATED_AT) VALUES (2, 'sonar-users', 'Any new users created will automatically join this group', '2011-09-26 22:27:51.0', '2011-09-26 22:27:51.0')
+ALTER TABLE SONAR.GROUPS ALTER COLUMN ID RESTART WITH 3;
+
+INSERT INTO SONAR.GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 1)
+INSERT INTO SONAR.GROUPS_USERS(USER_ID, GROUP_ID) VALUES (1, 2)
+
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('1')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('2')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('10')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('11')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('13')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('14')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('16')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('35')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('36')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('39')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('41')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('46')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('48')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('49')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('51')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('52')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('53')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('54')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('55')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('57')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('58')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('59')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('60')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('61')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('62')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('66')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('68')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('69')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('72')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('73')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('75')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('76')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('77')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('78')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('79')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('80')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('81')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('82')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('84')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('85')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('86')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('87')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('88')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('89')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('90')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('91')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('92')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('93')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('94')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('95')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('96')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('97')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('98')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('99')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('100')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('101')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('110')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('111')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('112')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('113')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('114')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('115')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('116')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('117')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('118')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('119')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('120')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('131')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('132')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('133')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('134')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('135')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('136')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('137')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('138')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('139')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('140')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('141')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('142')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('150')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('151')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('160')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('162')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('163')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('165')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('166')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('167')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('168')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('169')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('170')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('180')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('181')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('190')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('191')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('200')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('201')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('202')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('203')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('210')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('211')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('212')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('213')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('214')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('215')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('216')
+INSERT INTO SONAR.SCHEMA_MIGRATIONS(VERSION) VALUES ('217')
+
+INSERT INTO SONAR.USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '2011-09-26 22:27:48.0', '2011-09-26 22:27:48.0', null, null)
+ALTER TABLE SONAR.USERS ALTER COLUMN ID RESTART WITH 2;
+
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (1, 1, 'size', 'Size metrics', null, 1, 1, 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0')
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (2, 1, 'comments_duplications', 'Comments duplications', null, 1, 2, 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0')
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (3, 1, 'complexity', 'Complexity', null, 1, 3, 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0')
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (4, 1, 'code_coverage', 'Code coverage', null, 1, 4, 1, '2011-09-26 22:27:55.0', '2011-09-26 22:27:55.0');
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (5, 1, 'events', 'Events', null, 1, 5, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (6, 1, 'description', 'Description', null, 1, 6, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (7, 1, 'rules', 'Rules', null, 2, 1, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (8, 1, 'alerts', 'Alerts', null, 2, 2, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (9, 1, 'file_design', 'File design', null, 2, 3, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (10, 1, 'package_design', 'Package design', null, 2, 4, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+INSERT INTO SONAR.WIDGETS(ID, DASHBOARD_ID, WIDGET_KEY, NAME, DESCRIPTION, COLUMN_INDEX, ROW_INDEX, CONFIGURED, CREATED_AT, UPDATED_AT) VALUES (11, 1, 'ckjm', 'CKJM', null, 2, 5, 1, '2011-09-26 22:27:56.0', '2011-09-26 22:27:56.0');
+ALTER TABLE SONAR.WIDGETS ALTER COLUMN ID RESTART WITH 12;
diff --git a/sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb b/sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb
index af5cbb497c7..9dd1eed5611 100644
--- a/sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb
+++ b/sonar-server/src/main/webapp/WEB-INF/lib/database_version.rb
@@ -26,10 +26,10 @@ class DatabaseVersion
end
def self.current_version
- result=0
begin
result=ActiveRecord::Migrator.current_version
rescue
+ result=0
end
if result==0
@@ -59,7 +59,7 @@ class DatabaseVersion
$uptodate
end
- def self.setup
+ def self.migrate_and_start
ActiveRecord::Migrator.migrate(migrations_path)
Java::OrgSonarServerPlatform::Platform.getInstance().start()
load_plugin_webservices()
@@ -71,7 +71,8 @@ class DatabaseVersion
def self.automatic_setup
if current_version<=0
- setup
+ try_restore_structure_dump() if use_structure_dump?
+ migrate_and_start()
end
if uptodate?
load_plugin_webservices()
@@ -82,4 +83,38 @@ class DatabaseVersion
def self.connected?
ActiveRecord::Base.connected?
end
+
+ def self.try_restore_structure_dump()
+ begin
+ ddl=IO.readlines("#{RAILS_ROOT}/db/structure/#{dialect}.ddl")
+ sql=IO.readlines("#{RAILS_ROOT}/db/structure/#{dialect}.sql")
+
+ puts "Restore database structure & data"
+ execute_sql_requests(ddl)
+ execute_sql_requests(sql)
+ puts "Database created"
+ rescue
+ # file not found
+ nil
+ end
+ end
+
+ def self.execute_sql_requests(requests)
+ requests.each do |request|
+ unless request.blank? || request.start_with?('--')
+ request.chomp!
+ request.chop! if request.end_with?(';')
+ ActiveRecord::Base.connection.execute(request)
+ end
+ end
+ end
+
+ def self.dialect
+ ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getDialect().getActiveRecordDialectCode()
+ end
+
+ def self.use_structure_dump?
+ # default value is true
+ ::Java::OrgSonarServerUi::JRubyFacade.getInstance().getConfigurationValue('sonar.useStructureDump')!='false'
+ end
end \ No newline at end of file