]> source.dussan.org Git - sonarqube.git/blob
ad4a5ed97d48b48745628b36bbd620797c503d24
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2019 SonarSource SA
4  * mailto:info AT sonarsource DOT com
5  *
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.
10  *
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.
15  *
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.
19  */
20 package org.sonar.server.platform.db.migration.version.v70;
21
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;
28
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;
35
36 public class CreateTableLiveMeasures extends DdlChange {
37
38   private static final String TABLE_NAME = "live_measures";
39
40   public CreateTableLiveMeasures(Database db) {
41     super(db);
42   }
43
44   @Override
45   public void execute(Context context) throws SQLException {
46     context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
47       .addPkColumn(newVarcharColumnDefBuilder()
48         .setColumnName("uuid")
49         .setIsNullable(false)
50         .setLimit(VarcharColumnDef.UUID_SIZE)
51         .build())
52       .addColumn(newVarcharColumnDefBuilder()
53         .setColumnName("project_uuid")
54         .setIsNullable(false)
55         .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
56         .build())
57       .addColumn(newVarcharColumnDefBuilder()
58         .setColumnName("component_uuid")
59         .setIsNullable(false)
60         .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
61         .build())
62       .addColumn(newIntegerColumnDefBuilder()
63         .setColumnName("metric_id")
64         .setIsNullable(false)
65         .build())
66       .addColumn(newDecimalColumnDefBuilder()
67         .setColumnName("value")
68         .setPrecision(38)
69         .setScale(20)
70         .build())
71       .addColumn(newVarcharColumnDefBuilder()
72         .setColumnName("text_value")
73         .setIsNullable(true)
74         .setLimit(4_000)
75         .build())
76       .addColumn(newDecimalColumnDefBuilder()
77         .setColumnName("variation")
78         .setPrecision(38)
79         .setScale(20)
80         .build())
81       .addColumn(newBlobColumnDefBuilder()
82         .setColumnName("measure_data")
83         .build())
84       .addColumn(newVarcharColumnDefBuilder()
85         .setColumnName("update_marker")
86         .setIsNullable(true)
87         .setLimit(UUID_SIZE)
88         .build())
89       .addColumn(newBigIntegerColumnDefBuilder()
90         .setColumnName("created_at")
91         .setIsNullable(false)
92         .build())
93       .addColumn(newBigIntegerColumnDefBuilder()
94         .setColumnName("updated_at")
95         .setIsNullable(false)
96         .build())
97       .build());
98
99     context.execute(new CreateIndexBuilder(getDialect())
100       .addColumn(newVarcharColumnDefBuilder()
101         .setColumnName("project_uuid")
102         .setIsNullable(false)
103         .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
104         .build())
105       .setUnique(false)
106       .setTable(TABLE_NAME)
107       .setName("live_measures_project")
108       .build());
109
110     context.execute(new CreateIndexBuilder(getDialect())
111       .addColumn(newVarcharColumnDefBuilder()
112         .setColumnName("component_uuid")
113         .setIsNullable(false)
114         .setLimit(VarcharColumnDef.UUID_VARCHAR_SIZE)
115         .build())
116       .addColumn(newIntegerColumnDefBuilder()
117         .setColumnName("metric_id")
118         .setIsNullable(false)
119         .build())
120       .setUnique(true)
121       .setTable(TABLE_NAME)
122       .setName("live_measures_component")
123       .build());
124   }
125 }