3 * Copyright (C) 2009-2019 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.version.v70;
22 import java.sql.SQLException;
23 import org.sonar.db.Database;
24 import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
25 import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
26 import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
27 import org.sonar.server.platform.db.migration.step.DdlChange;
29 import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
30 import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder;
31 import static org.sonar.server.platform.db.migration.def.DecimalColumnDef.newDecimalColumnDefBuilder;
32 import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;
33 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
34 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
36 public class CreateTableLiveMeasures extends DdlChange {
38 private static final String TABLE_NAME = "live_measures";
40 public CreateTableLiveMeasures(Database db) {
45 public void execute(Context context) throws SQLException {
46 context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
47 .addPkColumn(newVarcharColumnDefBuilder()
48 .setColumnName("uuid")
50 .setLimit(VarcharColumnDef.UUID_SIZE)
52 .addColumn(newVarcharColumnDefBuilder()
53 .setColumnName("project_uuid")
55 .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
57 .addColumn(newVarcharColumnDefBuilder()
58 .setColumnName("component_uuid")
60 .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
62 .addColumn(newIntegerColumnDefBuilder()
63 .setColumnName("metric_id")
66 .addColumn(newDecimalColumnDefBuilder()
67 .setColumnName("value")
71 .addColumn(newVarcharColumnDefBuilder()
72 .setColumnName("text_value")
76 .addColumn(newDecimalColumnDefBuilder()
77 .setColumnName("variation")
81 .addColumn(newBlobColumnDefBuilder()
82 .setColumnName("measure_data")
84 .addColumn(newVarcharColumnDefBuilder()
85 .setColumnName("update_marker")
89 .addColumn(newBigIntegerColumnDefBuilder()
90 .setColumnName("created_at")
93 .addColumn(newBigIntegerColumnDefBuilder()
94 .setColumnName("updated_at")
99 context.execute(new CreateIndexBuilder(getDialect())
100 .addColumn(newVarcharColumnDefBuilder()
101 .setColumnName("project_uuid")
102 .setIsNullable(false)
103 .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
106 .setTable(TABLE_NAME)
107 .setName("live_measures_project")
110 context.execute(new CreateIndexBuilder(getDialect())
111 .addColumn(newVarcharColumnDefBuilder()
112 .setColumnName("component_uuid")
113 .setIsNullable(false)
114 .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
116 .addColumn(newIntegerColumnDefBuilder()
117 .setColumnName("metric_id")
118 .setIsNullable(false)
121 .setTable(TABLE_NAME)
122 .setName("live_measures_component")