forked from SonarSource/sonarqube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change issue_changes timestamp columns to bigint/long
- Loading branch information
Showing
28 changed files
with
458 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...ar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* SonarQube, open source software quality management tool. | ||
* Copyright (C) 2008-2014 SonarSource | ||
* mailto:contact AT sonarsource DOT com | ||
* | ||
* SonarQube is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* SonarQube is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package org.sonar.server.db.migrations.v51; | ||
|
||
import org.sonar.api.utils.System2; | ||
import org.sonar.core.persistence.Database; | ||
import org.sonar.server.db.migrations.BaseDataChange; | ||
import org.sonar.server.db.migrations.MassUpdate; | ||
import org.sonar.server.db.migrations.Select; | ||
import org.sonar.server.db.migrations.SqlStatement; | ||
|
||
import java.sql.SQLException; | ||
import java.util.Date; | ||
|
||
public class FeedIssueChangesLongDates extends BaseDataChange { | ||
|
||
private final System2 system; | ||
|
||
public FeedIssueChangesLongDates(Database db, System2 system) { | ||
super(db); | ||
this.system = system; | ||
} | ||
|
||
@Override | ||
public void execute(Context context) throws SQLException { | ||
final long now = system.now(); | ||
|
||
MassUpdate massUpdate = context.prepareMassUpdate(); | ||
massUpdate.select("SELECT i.created_at, i.updated_at, i.issue_change_creation_date_ms, i.id FROM issue_changes i WHERE created_at_ms IS NULL"); | ||
massUpdate.update("UPDATE issue_changes SET created_at_ms=?, updated_at_ms=?, issue_change_creation_date_ms=? WHERE id=?"); | ||
massUpdate.rowPluralName("issue_changes"); | ||
massUpdate.execute(new MassUpdate.Handler() { | ||
@Override | ||
public boolean handle(Select.Row row, SqlStatement update) throws SQLException { | ||
Date createdAt = row.getDate(1); | ||
Date updatedAt = row.getDate(2); | ||
Date functionalCreatedAt = row.getDate(3); | ||
Long id = row.getLong(4); | ||
|
||
updateColumn(update, 1, createdAt); | ||
updateColumn(update, 2, updatedAt); | ||
if (functionalCreatedAt == null) { | ||
update.setLong(3, null); | ||
} else { | ||
update.setLong(3, functionalCreatedAt.getTime()); | ||
} | ||
update.setLong(4, id); | ||
return true; | ||
} | ||
|
||
private void updateColumn(SqlStatement update, int position, Date time) throws SQLException { | ||
if (time == null) { | ||
update.setLong(position, now); | ||
} else { | ||
update.setLong(position, Math.min(now, time.getTime())); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...erver/src/test/java/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SonarQube, open source software quality management tool. | ||
* Copyright (C) 2008-2014 SonarSource | ||
* mailto:contact AT sonarsource DOT com | ||
* | ||
* SonarQube is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* SonarQube is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
package org.sonar.server.db.migrations.v51; | ||
|
||
import org.junit.ClassRule; | ||
import org.junit.Test; | ||
import org.sonar.api.utils.System2; | ||
import org.sonar.core.persistence.DbTester; | ||
import org.sonar.server.db.migrations.DatabaseMigration; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class FeedIssueChangesLongDatesTest { | ||
@ClassRule | ||
public static DbTester db = new DbTester().schema(FeedIssueChangesLongDatesTest.class, "schema.sql"); | ||
|
||
@Test | ||
public void execute() throws Exception { | ||
db.prepareDbUnit(getClass(), "before.xml"); | ||
|
||
System2 system = mock(System2.class); | ||
when(system.now()).thenReturn(1500000000000L); | ||
DatabaseMigration migration = new FeedIssueChangesLongDates(db.database(), system); | ||
migration.execute(); | ||
|
||
int count = db.countSql("select count(*) from issue_changes where created_at_ms is not null and updated_at_ms is not null"); | ||
assertThat(count).isEqualTo(3); | ||
|
||
int countWithAllDateFieldsNull = db | ||
.countSql("select count(*) from issue_changes where created_at_ms is not null and updated_at_ms is not null and issue_change_creation_date_ms is not null"); | ||
assertThat(countWithAllDateFieldsNull).isEqualTo(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...est/resources/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest/before.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<dataset> | ||
|
||
<!-- new migration --> | ||
<issue_changes id="1" kee="ABC-DEF" issue_key="ABC" user_login="[null]" change_type="[null]" change_data="[null]" | ||
created_at="2013-05-18" | ||
updated_at="2013-05-18" | ||
issue_change_creation_date="2013-05-18" | ||
created_at_ms="[null]" | ||
updated_at_ms="[null]" | ||
issue_change_creation_date_ms="[null]"/> | ||
/> | ||
|
||
<!-- re-entrant migration - ignore the issues that are already fed with new dates --> | ||
<issue_changes id="2" kee="FGH-DEF" issue_key="FGH" user_login="[null]" change_type="[null]" change_data="[null]" | ||
created_at="2013-05-18" | ||
updated_at="2013-05-18" | ||
issue_change_creation_date="2013-05-18" | ||
created_at_ms="1500000000000" | ||
updated_at_ms="1500000000000" | ||
issue_change_creation_date_ms="1500000000000"/> | ||
|
||
<!-- NULL dates --> | ||
<issue_changes id="3" kee="MISSING-DEF" issue_key="MISSING" user_login="[null]" change_type="[null]" | ||
change_data="[null]" | ||
created_at="[null]" | ||
updated_at="[null]" | ||
issue_change_creation_date="[null]" | ||
created_at_ms="[null]" | ||
updated_at_ms="[null]" | ||
issue_change_creation_date_ms="[null]"/> | ||
</dataset> |
14 changes: 14 additions & 0 deletions
14
...est/resources/org/sonar/server/db/migrations/v51/FeedIssueChangesLongDatesTest/schema.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
CREATE TABLE "ISSUE_CHANGES" ( | ||
"ID" BIGINT NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1), | ||
"KEE" VARCHAR(50), | ||
"ISSUE_KEY" VARCHAR(50) NOT NULL, | ||
"USER_LOGIN" VARCHAR(255), | ||
"CHANGE_TYPE" VARCHAR(40), | ||
"CHANGE_DATA" VARCHAR(16777215), | ||
"CREATED_AT" TIMESTAMP, | ||
"UPDATED_AT" TIMESTAMP, | ||
"ISSUE_CHANGE_CREATION_DATE" TIMESTAMP, | ||
"CREATED_AT_MS" BIGINT, | ||
"UPDATED_AT_MS" BIGINT, | ||
"ISSUE_CHANGE_CREATION_DATE_MS" BIGINT | ||
); |
32 changes: 32 additions & 0 deletions
32
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/760_add_issue_changes_long_dates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# | ||
# SonarQube, open source software quality management tool. | ||
# Copyright (C) 2008-2014 SonarSource | ||
# mailto:contact AT sonarsource DOT com | ||
# | ||
# SonarQube is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 3 of the License, or (at your option) any later version. | ||
# | ||
# SonarQube is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program; if not, write to the Free Software Foundation, | ||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
|
||
# | ||
# SonarQube 5.1 | ||
# | ||
class AddIssueChangesLongDates < ActiveRecord::Migration | ||
|
||
def self.up | ||
add_column 'issue_changes', :created_at_ms, :big_integer, :null => true | ||
add_column 'issue_changes', :updated_at_ms, :big_integer, :null => true | ||
add_column 'issue_changes', :issue_change_creation_date_ms, :big_integer, :null => true | ||
end | ||
end | ||
|
31 changes: 31 additions & 0 deletions
31
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/761_feed_issue_changes_long_dates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# | ||
# SonarQube, open source software quality management tool. | ||
# Copyright (C) 2008-2014 SonarSource | ||
# mailto:contact AT sonarsource DOT com | ||
# | ||
# SonarQube is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 3 of the License, or (at your option) any later version. | ||
# | ||
# SonarQube is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program; if not, write to the Free Software Foundation, | ||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
|
||
# | ||
# SonarQube 5.1 | ||
# | ||
class FeedIssueChangesLongDates < ActiveRecord::Migration | ||
|
||
def self.up | ||
execute_java_migration('org.sonar.server.db.migrations.v51.FeedIssueChangesLongDates') | ||
end | ||
|
||
end | ||
|
35 changes: 35 additions & 0 deletions
35
server/sonar-web/src/main/webapp/WEB-INF/db/migrate/762_rename_issue_changes_long_dates.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# | ||
# SonarQube, open source software quality management tool. | ||
# Copyright (C) 2008-2014 SonarSource | ||
# mailto:contact AT sonarsource DOT com | ||
# | ||
# SonarQube is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License as published by the Free Software Foundation; either | ||
# version 3 of the License, or (at your option) any later version. | ||
# | ||
# SonarQube is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program; if not, write to the Free Software Foundation, | ||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
|
||
# | ||
# SonarQube 5.1 | ||
# | ||
class RenameIssueChangesLongDates < ActiveRecord::Migration | ||
|
||
def self.up | ||
remove_column 'issue_changes', 'created_at' | ||
remove_column 'issue_changes', 'updated_at' | ||
remove_column 'issue_changes', 'issue_change_creation_date' | ||
rename_column 'issue_changes', 'created_at_ms', 'created_at' | ||
rename_column 'issue_changes', 'updated_at_ms', 'updated_at' | ||
rename_column 'issue_changes', 'issue_change_creation_date_ms', 'issue_change_creation_date' | ||
end | ||
end | ||
|
Oops, something went wrong.