--- /dev/null
+#
+# 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 6.0
+# SONAR-7794
+#
+class AddUserUpdatedAtToRulesProfiles < ActiveRecord::Migration
+ def self.up
+ execute_java_migration('org.sonar.db.version.v60.AddUserUpdatedAtToRulesProfiles')
+ end
+end
private String parentKee;
private String rulesUpdatedAt;
private Long lastUsed;
+ private Long userUpdatedAt;
private boolean isDefault;
/**
return this;
}
+ @CheckForNull
+ public Long getUserUpdatedAt() {
+ return userUpdatedAt;
+ }
+
+ public QualityProfileDto setUserUpdatedAt(@Nullable Long userUpdatedAt) {
+ this.userUpdatedAt = userUpdatedAt;
+ return this;
+ }
+
public boolean isDefault() {
return isDefault;
}
public class DatabaseVersion {
- public static final int LAST_VERSION = 1_261;
+ public static final int LAST_VERSION = 1_262;
/**
* The minimum supported version which can be upgraded. Lower
import org.sonar.db.version.v60.AddComponentUuidColumnsToSnapshots;
import org.sonar.db.version.v60.AddLastUsedColumnToRulesProfiles;
import org.sonar.db.version.v60.AddProfileKeyToActivities;
+import org.sonar.db.version.v60.AddUserUpdatedAtToRulesProfiles;
import org.sonar.db.version.v60.AddUuidColumnToSnapshots;
import org.sonar.db.version.v60.AddUuidColumnsToProjects;
import org.sonar.db.version.v60.AddUuidColumnsToResourceIndex;
AddProfileKeyToActivities.class,
PopulateProfileKeyOfActivities.class,
MakeProfileKeyNotNullOnActivities.class,
+ AddUserUpdatedAtToRulesProfiles.class,
// SNAPSHOTS.UUID
AddUuidColumnToSnapshots.class,
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.db.version.v60;
+
+import java.sql.SQLException;
+import org.sonar.db.Database;
+import org.sonar.db.version.AddColumnsBuilder;
+import org.sonar.db.version.DdlChange;
+
+import static org.sonar.db.version.BigDecimalColumnDef.newBigDecimalColumnDefBuilder;
+
+public class AddUserUpdatedAtToRulesProfiles extends DdlChange {
+
+ private static final String TABLE_QUALITY_PROFILES = "rules_profiles";
+
+ public AddUserUpdatedAtToRulesProfiles(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ context.execute(new AddColumnsBuilder(getDatabase().getDialect(), TABLE_QUALITY_PROFILES)
+ .addColumn(newBigDecimalColumnDefBuilder().setColumnName("user_updated_at").setIsNullable(true).build())
+ .build());
+ }
+
+}
p.created_at as createdAt,
p.updated_at as updatedAt,
p.rules_updated_at as rulesUpdatedAt,
- p.last_used as lastUsed
+ p.last_used as lastUsed,
+ p.user_updated_at as userUpdatedAt
</sql>
<insert id="insert" parameterType="QualityProfile" keyColumn="id" useGeneratedKeys="true" keyProperty="id">
- INSERT INTO rules_profiles (kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at, last_used)
- VALUES (#{kee, jdbcType=VARCHAR}, #{parentKee,jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR}, #{language, jdbcType=VARCHAR}, #{isDefault, jdbcType=BOOLEAN},
- #{createdAt, jdbcType=TIMESTAMP}, #{updatedAt, jdbcType=TIMESTAMP}, #{rulesUpdatedAt, jdbcType=VARCHAR}, #{lastUsed, jdbcType=BIGINT})
+ INSERT INTO rules_profiles (kee, parent_kee, name, language, is_default, created_at, updated_at, rules_updated_at, last_used, user_updated_at)
+ VALUES (
+ #{kee, jdbcType=VARCHAR},
+ #{parentKee, jdbcType=VARCHAR},
+ #{name, jdbcType=VARCHAR},
+ #{language, jdbcType=VARCHAR},
+ #{isDefault, jdbcType=BOOLEAN},
+ #{createdAt, jdbcType=TIMESTAMP},
+ #{updatedAt, jdbcType=TIMESTAMP},
+ #{rulesUpdatedAt, jdbcType=VARCHAR},
+ #{lastUsed, jdbcType=BIGINT},
+ #{userUpdatedAt, jdbcType=BIGINT})
</insert>
<update id="update" parameterType="QualityProfile">
parent_kee=#{parentKee, jdbcType=VARCHAR},
updated_at=#{updatedAt, jdbcType=TIMESTAMP},
rules_updated_at=#{rulesUpdatedAt, jdbcType=VARCHAR},
- last_used=#{lastUsed, jdbcType=BIGINT}
+ last_used=#{lastUsed, jdbcType=BIGINT},
+ user_updated_at=#{userUpdatedAt, jdbcType=BIGINT}
WHERE id=#{id}
</update>
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1258');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1259');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1260');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('1261');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, EXTERNAL_IDENTITY, EXTERNAL_IDENTITY_PROVIDER, USER_LOCAL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT) VALUES (1, 'admin', 'Administrator', '', 'admin', 'sonarqube', true, 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482');
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
"IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
"CREATED_AT" TIMESTAMP,
"UPDATED_AT" TIMESTAMP,
- "LAST_USED" BIGINT
+ "LAST_USED" BIGINT,
+ "USER_UPDATED_AT" BIGINT
);
CREATE TABLE "PROJECT_QPROFILES" (
public void verify_count_of_added_MigrationStep_types() {
ComponentContainer container = new ComponentContainer();
new MigrationStepModule().configure(container);
- assertThat(container.size()).isEqualTo(117);
+ assertThat(container.size()).isEqualTo(118);
}
}
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program 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.
+ *
+ * This program 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.db.version.v60;
+
+import java.sql.SQLException;
+import java.sql.Types;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.sonar.api.utils.System2;
+import org.sonar.db.DbTester;
+
+public class AddUserUpdatedAtToRulesProfilesTest {
+
+ @Rule
+ public DbTester db = DbTester.createForSchema(System2.INSTANCE, AddUserUpdatedAtToRulesProfilesTest.class, "rules_profiles.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ AddUserUpdatedAtToRulesProfiles underTest = new AddUserUpdatedAtToRulesProfiles(db.database());
+
+ @Test
+ public void migration_adds_column_to_empty_table() throws SQLException {
+ underTest.execute();
+
+ verifyAddedColumn();
+ }
+
+ @Test
+ public void migration_adds_column_to_populated_table() throws SQLException {
+ for (int i = 0; i < 9; i++) {
+ db.executeInsert(
+ "rules_profiles",
+ "name", "NAME_" + i,
+ "language", "java",
+ "kee", "" + i,
+ "rules_updated_at", "2016-06-21",
+ "last_used", "123456789");
+ }
+ db.commit();
+
+ underTest.execute();
+
+ verifyAddedColumn();
+ }
+
+ @Test
+ public void migration_is_not_reentrant() throws SQLException {
+ underTest.execute();
+
+ expectedException.expect(IllegalStateException.class);
+ expectedException.expectMessage("Fail to execute ");
+ underTest.execute();
+ }
+
+ private void verifyAddedColumn() {
+ db.assertColumnDefinition("rules_profiles", "user_updated_at", Types.BIGINT, null, true);
+ }
+}
<dataset>
<rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
</dataset>
<dataset>
<rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
<rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
<rules_profiles id="3" name="ABCDE" language="xoo" parent_kee="[null]" kee="abcde" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
</dataset>
<dataset>
<rules_profiles id="1" name="Sonar Way" language="java" parent_kee="[null]" kee="java_sonar_way" is_default="[true]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
<rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
</dataset>
<dataset>
<rules_profiles id="1" name="New Name" language="js" parent_kee="fghij" kee="java_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]"/>
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="[null]" user_updated_at="[null]"/>
<rules_profiles id="2" name="Sonar Way" language="js" parent_kee="[null]" kee="js_sonar_way" is_default="[false]"
- rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789"/>
-
-
+ rules_updated_at="[null]" created_at="[null]" updated_at="[null]" last_used="123456789" user_updated_at="987654321"/>
</dataset>
--- /dev/null
+CREATE TABLE "RULES_PROFILES" (
+ "ID" INTEGER NOT NULL GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1),
+ "NAME" VARCHAR(100) NOT NULL,
+ "LANGUAGE" VARCHAR(20),
+ "KEE" VARCHAR(255) NOT NULL,
+ "PARENT_KEE" VARCHAR(255),
+ "RULES_UPDATED_AT" VARCHAR(100),
+ "IS_DEFAULT" BOOLEAN NOT NULL DEFAULT FALSE,
+ "CREATED_AT" TIMESTAMP,
+ "UPDATED_AT" TIMESTAMP,
+ "LAST_USED" BIGINT
+);