class CreateTableProperties2 < ActiveRecord::Migration
def self.up
- create_table 'properties2' do |t|
- t.column 'prop_key', :string, :limit => 512, :null => false
- t.column :resource_id, :integer, :null => true
- t.column :user_id, :integer, :null => true
- t.column 'is_empty', :boolean, :null => false
- t.column :text_value, :string, :limit => 4000, :null => true
- t.column :clob_value, :text, :null => true
- t.column 'created_at', :big_integer, :null => false
- end
+ execute_java_migration('org.sonar.db.version.v61.CreateTableProperties2')
add_varchar_index :properties2, :prop_key, :name => 'properties2_key'
end
end
import org.sonar.db.version.v61.CopyActivitiesToQprofileChanges;
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.CreateTableScannerContext;
import org.sonar.db.version.v61.DeleteProjectDashboards;
import org.sonar.db.version.v61.DeleteReportsFromCeQueue;
AddErrorColumnsToCeActivity.class,
CreateTableScannerContext.class,
CreateTableInternalProperties.class,
+ CreateTableProperties2.class,
PopulateTableProperties2.class,
RemoveViewsDefinitionFromProperties.class,
CopyActivitiesToQprofileChanges.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.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.BooleanColumnDef.newBooleanColumnDefBuilder;
+import static org.sonar.db.version.ClobColumnDef.newClobColumnDefBuilder;
+import static org.sonar.db.version.CreateTableBuilder.ColumnFlag.AUTO_INCREMENT;
+import static org.sonar.db.version.IntegerColumnDef.newIntegerColumnDefBuilder;
+import static org.sonar.db.version.VarcharColumnDef.MAX_SIZE;
+import static org.sonar.db.version.VarcharColumnDef.newVarcharColumnDefBuilder;
+
+public class CreateTableProperties2 extends DdlChange {
+ public CreateTableProperties2(Database db) {
+ super(db);
+ }
+
+ @Override
+ public void execute(Context context) throws SQLException {
+ List<String> stmts = new CreateTableBuilder(getDialect(), "properties2")
+ .addPkColumn(newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("prop_key").setLimit(512).setIsNullable(false).build())
+ .addColumn(newBigIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build())
+ .addColumn(newBigIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(true).build())
+ .addColumn(newBooleanColumnDefBuilder().setColumnName("is_empty").setIsNullable(false).build())
+ .addColumn(newVarcharColumnDefBuilder().setColumnName("text_value").setLimit(MAX_SIZE).setIsNullable(true).build())
+ .addColumn(newClobColumnDefBuilder().setColumnName("clob_value").setIsNullable(true).build())
+ .addColumn(newBigIntegerColumnDefBuilder().setColumnName("created_at").setIsNullable(false).build())
+ // table with be renamed to properties in following migration, use final constraint name right away
+ .withPkConstraintName("pk_properties")
+ .build();
+ context.execute(stmts);
+ }
+}
public void verify_count_of_added_MigrationStep_types() {
ComponentContainer container = new ComponentContainer();
new MigrationStepModule().configure(container);
- assertThat(container.size()).isEqualTo(138);
+ assertThat(container.size()).isEqualTo(139);
}
}
--- /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 CreateTableProperties2Test {
+ private static final String TABLE_PROPERTIES_2 = "properties2";
+
+ @Rule
+ public final DbTester dbTester = DbTester.createForSchema(System2.INSTANCE, CreateTableProperties2Test.class, "empty.sql");
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private CreateTableProperties2 underTest = new CreateTableProperties2(dbTester.database());
+
+ @Test
+ public void creates_table_on_empty_db() throws SQLException {
+ underTest.execute();
+
+ assertThat(dbTester.countRowsOfTable(TABLE_PROPERTIES_2)).isEqualTo(0);
+
+ dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "id", Types.INTEGER, null, false);
+ dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "prop_key", Types.VARCHAR, 512, false);
+ dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "resource_id", Types.BIGINT, null, true);
+ dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "user_id", Types.BIGINT, null, true);
+ dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "is_empty", Types.BOOLEAN, null, false);
+ dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "text_value", Types.VARCHAR, 4000, true);
+ dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "clob_value", Types.CLOB, null, true);
+ dbTester.assertColumnDefinition(TABLE_PROPERTIES_2, "created_at", Types.BIGINT, null, false);
+ dbTester.assertPrimaryKey(TABLE_PROPERTIES_2, "pk_properties", "id");
+ }
+
+ @Test
+ public void migration_is_not_reentrant() throws SQLException {
+ underTest.execute();
+
+ expectedException.expect(IllegalStateException.class);
+
+ underTest.execute();
+ }
+
+}