class CreateTableQprofileChanges < ActiveRecord::Migration
def self.up
- create_table 'qprofile_changes', :id => false do |t|
- t.column 'kee', :string, :limit => 40, :null => false
- t.column 'qprofile_key', :string, :limit => 255, :null => false
- t.column 'change_type', :string, :limit => 20, :null => false
- t.column 'created_at', :big_integer, :null => false
- t.column 'user_login', :string, :limit => 255, :null => true
- t.column 'data', :text, :null => true
- end
- add_primary_key 'qprofile_changes', 'kee'
+ execute_java_migration('org.sonar.db.version.v61.CreateTableQprofileChanges')
end
end
import org.sonar.db.version.v61.CreateTableCeTaskInput;
import org.sonar.db.version.v61.CreateTableInternalProperties;
import org.sonar.db.version.v61.CreateTableProperties2;
+import org.sonar.db.version.v61.CreateTableQprofileChanges;
import org.sonar.db.version.v61.CreateTableScannerContext;
import org.sonar.db.version.v61.DeleteProjectDashboards;
import org.sonar.db.version.v61.DeleteReportsFromCeQueue;
CreateTableProperties2.class,
PopulateTableProperties2.class,
RemoveViewsDefinitionFromProperties.class,
+ CreateTableQprofileChanges.class,
CopyActivitiesToQprofileChanges.class);
}
}
"and qc.kee is null")
.setString(1, "QPROFILE");
- massUpdate.update("insert into qprofile_changes (kee, qprofile_key, created_at, user_login, change_type, data) values (?,?,?,?,?,?)");
+ massUpdate.update("insert into qprofile_changes (kee, qprofile_key, created_at, user_login, change_type, change_data) values (?,?,?,?,?,?)");
massUpdate.execute((row, update) -> {
String key = row.getString(1);
String profileKey = row.getString(2);
--- /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.v61;
+
+import java.sql.SQLException;
+import java.util.List;
+import org.sonar.db.Database;
+import org.sonar.db.version.CreateTableBuilder;
+import org.sonar.db.version.DdlChange;
+
+import static org.sonar.db.version.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
+import static org.sonar.db.version.ClobColumnDef.newClobColumnDefBuilder;
+import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateTableQprofileChanges extends DdlChange {
+ public CreateTableQprofileChanges(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ List<String> stmts = new CreateTableBuilder(getDialect(), "qprofile_changes")
+ .addPkColumn(newVarcharColumnDefBuilder().setColumnName("kee").setLimit(40).setIsNullable(false).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("qprofile_key").setLimit(255).setIsNullable(false).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("change_type").setLimit(20).setIsNullable(false).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("user_login").setLimit(255).setIsNullable(true).build())
+ .addColumn(newClobColumnDefBuilder().setColumnName("change_data").setIsNullable(true).build())
+ .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
+ .build();
+ context.execute(stmts);
+ }
+}
created_at,
user_login,
change_type,
- data
+ change_data
) values (
#{key,jdbcType=VARCHAR},
#{profileKey,jdbcType=VARCHAR},
created_at as createdAt,
user_login as login,
change_type as changeType,
- data
+ change_data as data
</sql>
<sql id="sqlSelectByQuery">
"CHANGE_TYPE" VARCHAR(20) NOT NULL,
"CREATED_AT" BIGINT NOT NULL,
"USER_LOGIN" VARCHAR(255),
- "DATA" CLOB
+ "CHANGE_DATA" CLOB
);
CREATE TABLE "FILE_SOURCES" (
assertThat(row.get("createdAt")).isEqualTo(A_DATE);
assertThat(row.get("login")).isEqualTo(login);
assertThat(row.get("changeType")).isEqualTo(type);
- assertThat(row.get("data")).isEqualTo(data);
+ assertThat(row.get("changeData")).isEqualTo(data);
}
/**
assertThat(row.get("createdAt")).isEqualTo(A_DATE);
assertThat(row.get("changeType")).isEqualTo("ACTIVATED");
assertThat(row.get("login")).isNull();
- assertThat(row.get("data")).isNull();
+ assertThat(row.get("changeData")).isNull();
}
@Test
private Map<String, Object> selectChangeByKey(String key) {
return dbTester.selectFirst(dbSession,
- "select qprofile_key as \"qprofileKey\", created_at as \"createdAt\", user_login as \"login\", change_type as \"changeType\", data as \"data\" from qprofile_changes where kee='"
+ "select qprofile_key as \"qprofileKey\", created_at as \"createdAt\", user_login as \"login\", change_type as \"changeType\", change_data as \"changeData\" from qprofile_changes where kee='"
+ key + "'");
}
}
public void verify_count_of_added_MigrationStep_types() {
ComponentContainer container = new ComponentContainer();
new MigrationStepModule().configure(container);
- assertThat(container.size()).isEqualTo(139);
+ assertThat(container.size()).isEqualTo(140);
}
}
assertThat(change.get("createdAt")).isEqualTo(A_DATE);
assertThat(change.get("login")).isEqualTo(login);
assertThat(change.get("changeType")).isEqualTo(type);
- assertThat(change.get("data")).isEqualTo(data);
+ assertThat(change.get("changeData")).isEqualTo(data);
}
/**
}
private Map<String, Object> selectChangeByKey(String key) {
- return db.selectFirst("select qprofile_key as \"qprofileKey\", created_at as \"createdAt\", user_login as \"login\", change_type as \"changeType\", data as \"data\" from qprofile_changes where kee='" + key + "'");
+ return db.selectFirst("select qprofile_key as \"qprofileKey\", created_at as \"createdAt\", user_login as \"login\", change_type as \"changeType\", change_data as \"changeData\" from qprofile_changes where kee='" + key + "'");
}
}
--- /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.v61;
+
+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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class CreateTableQprofileChangesTest {
+ private static final String TABLE_QPROFILE_CHANGES = "qprofile_changes";
+
+ @Rule
+ public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableQprofileChangesTest.class, "empty.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private CreateTableQprofileChanges underTest = new CreateTableQprofileChanges(dbTester.database());
+
+ @Test
+ public void creates_table_on_empty_db() throws SQLException {
+ underTest.execute();
+
+ assertThat(dbTester.countRowsOfTable(TABLE_QPROFILE_CHANGES)).isEqualTo(0);
+
+ dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "kee", Types.VARCHAR, 40, false);
+ dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "qprofile_key", Types.VARCHAR, 255, false);
+ dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "change_type", Types.VARCHAR, 20, false);
+ dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "user_login", Types.VARCHAR, 255, true);
+ dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "change_data", Types.CLOB, null, true);
+ dbTester.assertColumnDefinition(TABLE_QPROFILE_CHANGES, "created_at", Types.BIGINT, null, false);
+ dbTester.assertPrimaryKey(TABLE_QPROFILE_CHANGES, "pk_" + TABLE_QPROFILE_CHANGES, "kee");
+ }
+
+ @Test
+ public void migration_is_not_reentrant() throws SQLException {
+ underTest.execute();
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+}
"CHANGE_TYPE" VARCHAR(20) NOT NULL,
"CREATED_AT" BIGINT NOT NULL,
"USER_LOGIN" VARCHAR(255),
- "DATA" CLOB
+ "CHANGE_DATA" CLOB
);
CREATE INDEX "QPROFILE_CHANGES_QPROFILE_KEY" ON "QPROFILE_CHANGES" ("QPROFILE_KEY");