3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.db.migration.adhoc;
22 import java.sql.SQLException;
23 import org.sonar.db.Database;
24 import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
25 import org.sonar.server.platform.db.migration.step.CreateTableChange;
26 import org.sonar.server.platform.db.migration.step.DdlChange;
28 import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
29 import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder;
30 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
31 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
33 public class CreateMeasuresTable extends CreateTableChange {
34 static final String MEASURES_TABLE_NAME = "measures";
35 static final String COLUMN_COMPONENT_UUID = "component_uuid";
36 static final String COLUMN_BRANCH_UUID = "branch_uuid";
37 static final String COLUMN_JSON_VALUE = "json_value";
38 static final String COLUMN_JSON_VALUE_HASH = "json_value_hash";
39 static final String COLUMN_CREATED_AT = "created_at";
40 static final String COLUMN_UPDATED_AT = "updated_at";
42 public CreateMeasuresTable(Database db) {
43 super(db, MEASURES_TABLE_NAME);
47 public void execute(DdlChange.Context context, String tableName) throws SQLException {
48 context.execute(new CreateTableBuilder(getDialect(), tableName)
49 .addColumn(newVarcharColumnDefBuilder().setColumnName(COLUMN_COMPONENT_UUID).setIsNullable(false).setLimit(UUID_SIZE).build())
50 .addColumn(newVarcharColumnDefBuilder().setColumnName(COLUMN_BRANCH_UUID).setIsNullable(false).setLimit(UUID_SIZE).build())
51 .addColumn(newClobColumnDefBuilder().setColumnName(COLUMN_JSON_VALUE).setIsNullable(false).build())
52 .addColumn(newBigIntegerColumnDefBuilder().setColumnName(COLUMN_JSON_VALUE_HASH).setIsNullable(false).build())
53 .addColumn(newBigIntegerColumnDefBuilder().setColumnName(COLUMN_CREATED_AT).setIsNullable(false).build())
54 .addColumn(newBigIntegerColumnDefBuilder().setColumnName(COLUMN_UPDATED_AT).setIsNullable(false).build())