diff options
author | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-12-04 14:48:00 +0100 |
---|---|---|
committer | Jean-Baptiste Lievremont <jean-baptiste.lievremont@sonarsource.com> | 2014-12-04 16:32:05 +0100 |
commit | c44215ac4df1098dbe9aa4f1c0ec0a3653e44eeb (patch) | |
tree | 0afea375b00f43890eac949f1e97e28fd2965a2d /server | |
parent | d8b058490fd1e9b68271959e7f1653abd63fc77b (diff) | |
download | sonarqube-c44215ac4df1098dbe9aa4f1c0ec0a3653e44eeb.tar.gz sonarqube-c44215ac4df1098dbe9aa4f1c0ec0a3653e44eeb.zip |
SONAR-5826 Fix reentrance of migration, add unique constraint on file_sources to prevent dups
Diffstat (limited to 'server')
6 files changed, 48 insertions, 6 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java index 9ceecdd1730..12bf122af39 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v50/FeedFileSources.java @@ -107,6 +107,8 @@ public class FeedFileSources extends BaseDataChange { "ON s.root_project_id = p.id " + "JOIN projects f " + "ON s.project_id = f.id " + + "LEFT JOIN file_sources fs " + + "ON fs.file_uuid = f.uuid " + "LEFT JOIN project_measures m1 " + "ON m1.snapshot_id = s.id AND m1.metric_id = ? " + "LEFT JOIN project_measures m2 " + @@ -136,7 +138,8 @@ public class FeedFileSources extends BaseDataChange { "WHERE " + "f.enabled = ? " + "AND f.scope = 'FIL' " + - "AND p.scope = 'PRJ' AND p.qualifier = 'TRK' "; + "AND p.scope = 'PRJ' AND p.qualifier = 'TRK' " + + "AND fs.file_uuid IS NULL"; private static final class FileSourceBuilder implements MassUpdate.Handler { private final Date now; diff --git a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java index 82d45e5b814..52766eec228 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/db/migrations/v50/FeedFileSourcesTest.java @@ -74,6 +74,11 @@ public class FeedFileSourcesTest { "values " + "(6, 'class Foo {\r\n // Empty\r\n}\r\n', '2014-10-31 16:44:02.000')"); + db.executeUpdateSql("insert into snapshot_sources " + + "(snapshot_id, data, updated_at) " + + "values " + + "(7, '', '2014-10-31 16:44:02.000')"); + migration.execute(); db.assertDbUnit(getClass(), "after.xml", "file_sources"); @@ -102,6 +107,11 @@ public class FeedFileSourcesTest { "(6, 'class Foo {\r\n // Empty\r\n}\r\n', '2014-10-31 16:44:02.000')") .executeUpdate(); + db.executeUpdateSql("insert into snapshot_sources " + + "(snapshot_id, data, updated_at) " + + "values " + + "(7, '', '2014-10-31 16:44:02.000')"); + PreparedStatement revisionStmt = connection.prepareStatement("insert into project_measures " + "(metric_id, snapshot_id, " + columnName + ") " + "values " + diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/after-with-scm.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/after-with-scm.xml index 954a51fa83d..e44511b3d6f 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/after-with-scm.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/after-with-scm.xml @@ -1,6 +1,11 @@ <dataset> - <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="1416238020000" updated_at="1414770242000" + <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-Migrated.xoo" created_at="1416238020000" updated_at="1414770242000" + data="" + line_hashes="" + data_hash="" /> + + <file_sources id="2" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="1416238020000" updated_at="1414770242000" data="aef12a,alice,2014-04-25T12:34:56+0100,1,4,2,2,5,3,3,6,4,,,1,class Foo { abe465,bob,2014-07-25T12:34:56+0100,,,,,,,,,,,,2, // Empty afb789,carol,2014-03-23T12:34:56+0100,0,,,0,,,0,,,,,,} afb789,carol,2014-03-23T12:34:56+0100,,,,,,,,,,,,, " line_hashes="6a19ce786467960a3a9b0d26383a464a aab2dbc5fdeaa80b050b1d049ede357c cbb184dd8e05c9709e5dcaedaa0495cf " data_hash="" /> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/after.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/after.xml index 266e06d8a53..7762dcd311d 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/after.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/after.xml @@ -1,6 +1,11 @@ <dataset> - <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="1416238020000" updated_at="1414770242000" + <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-Migrated.xoo" created_at="1416238020000" updated_at="1414770242000" + data="" + line_hashes="" + data_hash="" /> + + <file_sources id="2" project_uuid="uuid-MyProject" file_uuid="uuid-MyFile.xoo" created_at="1416238020000" updated_at="1414770242000" data=",,,,,,,,,,,,,,,class Foo { ,,,,,,,,,,,,,,, // Empty ,,,,,,,,,,,,,,,} ,,,,,,,,,,,,,,, " line_hashes="6a19ce786467960a3a9b0d26383a464a aab2dbc5fdeaa80b050b1d049ede357c cbb184dd8e05c9709e5dcaedaa0495cf " data_hash="" /> diff --git a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/before.xml b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/before.xml index f977bd54963..3dced7c48ee 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/before.xml +++ b/server/sonar-server/src/test/resources/org/sonar/server/db/migrations/v50/FeedFileSourcesTest/before.xml @@ -30,6 +30,7 @@ <projects id="1" uuid="uuid-MyProject" kee="MyProject" scope="PRJ" qualifier="TRK" /> <projects id="2" uuid="uuid-prj" kee="MyProject:src/main/xoo/prj" scope="DIR" qualifier="DIR" /> <projects id="3" uuid="uuid-MyFile.xoo" kee="MyProject:src/main/xoo/prj/MyFile.xoo" scope="FIL" qualifier="FIL" /> + <projects id="4" uuid="uuid-Migrated.xoo" kee="MyProject:src/main/xoo/prj/Migrated.xoo" scope="FIL" qualifier="FIL" /> <snapshots id="1" project_id="1" parent_snapshot_id="1" root_project_id="1" root_snapshot_id="1" status="P" islast="[false]" purge_status="1" @@ -65,8 +66,8 @@ period2_mode="days2" period2_param="31" period2_date="2011-09-25" period3_mode="days3" period3_param="32" period3_date="2011-09-26" period4_mode="days4" period4_param="33" period4_date="2011-09-27" - period5_mode="days5" period5_param="34" period5_date="2011-09-28" depth="1" scope="DIR" qualifier="DIR" created_at="2008-12-02" build_date="2011-09-29" + period5_mode="days5" period5_param="34" period5_date="2011-09-28" version="2.1-SNAPSHOT" path="1.2."/> <snapshots id="5" project_id="3" parent_snapshot_id="3" root_project_id="1" root_snapshot_id="1" @@ -87,4 +88,20 @@ period5_mode="days5" period5_param="34" period5_date="2011-09-28" depth="1" scope="FIL" qualifier="FIL" created_at="2008-12-02" build_date="2011-09-29" version="2.1-SNAPSHOT" path="1.2."/> + + <snapshots id="7" project_id="4" parent_snapshot_id="5" root_project_id="1" root_snapshot_id="2" + status="P" islast="[true]" purge_status="1" + period1_mode="days1" period1_param="30" period1_date="2011-09-24" + period2_mode="days2" period2_param="31" period2_date="2011-09-25" + period3_mode="days3" period3_param="32" period3_date="2011-09-26" + period4_mode="days4" period4_param="33" period4_date="2011-09-27" + period5_mode="days5" period5_param="34" period5_date="2011-09-28" + depth="1" scope="FIL" qualifier="FIL" created_at="2008-12-02" build_date="2011-09-29" + version="2.1-SNAPSHOT" path="1.2."/> + + <file_sources id="1" project_uuid="uuid-MyProject" file_uuid="uuid-Migrated.xoo" created_at="1416238020000" updated_at="1414770242000" + data="" + line_hashes="" + data_hash="" /> + </dataset> diff --git a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/713_create_file_sources.rb b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/713_create_file_sources.rb index 635df588822..ae7e45aecf9 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/713_create_file_sources.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/db/migrate/713_create_file_sources.rb @@ -30,7 +30,7 @@ class CreateFileSources < ActiveRecord::Migration t.column :data, :text, :null => true t.column :line_hashes, :text, :null => true t.column :data_hash, :string, :limit => 50, :null => true - t.column :created_at, :big_integer, :null => false + t.column :created_at, :big_integer, :null => false t.column :updated_at, :big_integer, :null => false end @@ -38,7 +38,9 @@ class CreateFileSources < ActiveRecord::Migration ActiveRecord::Base.connection.execute("alter table file_sources modify data longtext") end - ["project_uuid", "file_uuid", "updated_at"].each do |column| + add_index "file_sources", "file_uuid", :unique => true, :name => "file_sources_file_uuid_uniq" + + ["project_uuid", "updated_at"].each do |column| begin add_index "file_sources", column, :name => "file_sources_" + column rescue |