3 * Copyright (C) 2009-2020 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.v00;
22 import java.sql.SQLException;
23 import org.sonar.db.Database;
24 import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
25 import org.sonar.server.platform.db.migration.def.BooleanColumnDef;
26 import org.sonar.server.platform.db.migration.def.ColumnDef;
27 import org.sonar.server.platform.db.migration.def.IntegerColumnDef;
28 import org.sonar.server.platform.db.migration.def.TimestampColumnDef;
29 import org.sonar.server.platform.db.migration.def.TinyIntColumnDef;
30 import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
31 import org.sonar.server.platform.db.migration.sql.CreateIndexBuilder;
32 import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
33 import org.sonar.server.platform.db.migration.step.DdlChange;
35 import static java.util.Arrays.stream;
36 import static java.util.stream.Stream.concat;
37 import static java.util.stream.Stream.of;
38 import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
39 import static org.sonar.server.platform.db.migration.def.BlobColumnDef.newBlobColumnDefBuilder;
40 import static org.sonar.server.platform.db.migration.def.BooleanColumnDef.newBooleanColumnDefBuilder;
41 import static org.sonar.server.platform.db.migration.def.ClobColumnDef.newClobColumnDefBuilder;
42 import static org.sonar.server.platform.db.migration.def.DecimalColumnDef.newDecimalColumnDefBuilder;
43 import static org.sonar.server.platform.db.migration.def.IntegerColumnDef.newIntegerColumnDefBuilder;
44 import static org.sonar.server.platform.db.migration.def.TimestampColumnDef.newTimestampColumnDefBuilder;
45 import static org.sonar.server.platform.db.migration.def.TinyIntColumnDef.newTinyIntColumnDefBuilder;
46 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.MAX_SIZE;
47 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
48 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
49 import static org.sonar.server.platform.db.migration.sql.CreateTableBuilder.ColumnFlag.AUTO_INCREMENT;
51 public class CreateInitialSchema extends DdlChange {
54 * Initially, UUID columns were created with size 50 when only 40 is needed. {@link VarcharColumnDef#UUID_SIZE}
55 * should be used instead of this constant whenever reducing the column size is possible.
57 private static final int OLD_UUID_VARCHAR_SIZE = 50;
59 // keep column name constants in alphabetic order
60 private static final String ANALYSIS_UUID_COL_NAME = "analysis_uuid";
61 private static final String COMPONENT_UUID_COL_NAME = "component_uuid";
62 private static final String CREATED_AT_COL_NAME = "created_at";
63 private static final String DESCRIPTION_COL_NAME = "description";
64 private static final String METRIC_ID_COL_NAME = "metric_id";
65 private static final String ORGANIZATION_UUID_COL_NAME = "organization_uuid";
66 private static final String PROJECT_UUID_COL_NAME = "project_uuid";
67 private static final String TASK_UUID_COL_NAME = "task_uuid";
68 private static final String UPDATED_AT_COL_NAME = "updated_at";
69 private static final String USER_UUID_COL_NAME = "user_uuid";
71 // usual technical columns
72 private static final IntegerColumnDef ID_COL = newIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build();
73 private static final BigIntegerColumnDef TECHNICAL_CREATED_AT_COL = newBigIntegerColumnDefBuilder().setColumnName(CREATED_AT_COL_NAME).setIsNullable(false).build();
74 private static final BigIntegerColumnDef NULLABLE_TECHNICAL_CREATED_AT_COL = newBigIntegerColumnDefBuilder().setColumnName(CREATED_AT_COL_NAME).setIsNullable(true).build();
75 private static final BigIntegerColumnDef TECHNICAL_UPDATED_AT_COL = newBigIntegerColumnDefBuilder().setColumnName(UPDATED_AT_COL_NAME).setIsNullable(false).build();
76 private static final BigIntegerColumnDef NULLABLE_TECHNICAL_UPDATED_AT_COL = newBigIntegerColumnDefBuilder().setColumnName(UPDATED_AT_COL_NAME).setIsNullable(true).build();
77 private static final TimestampColumnDef DEPRECATED_TECHNICAL_CREATED_AT_COL = newTimestampColumnDefBuilder().setColumnName(CREATED_AT_COL_NAME).setIsNullable(true).build();
78 private static final TimestampColumnDef DEPRECATED_TECHNICAL_UPDATED_AT_COL = newTimestampColumnDefBuilder().setColumnName(UPDATED_AT_COL_NAME).setIsNullable(true).build();
80 public CreateInitialSchema(Database db) {
85 public void execute(Context context) throws SQLException {
86 createActiveRuleParameters(context);
87 createActiveRules(context);
88 createAlmAppInstalls(context);
89 createAnalysisProperties(context);
90 createCeActivity(context);
91 createCeQueue(context);
92 createCeScannerContext(context);
93 createCeTaskCharacteristics(context);
94 createCeTaskInput(context);
95 createCeTaskMessage(context);
96 createDefaultQProfiles(context);
97 createDeprecatedRuleKeys(context);
98 createDuplicationsIndex(context);
99 createEsQueue(context);
100 createEventComponentChanges(context);
101 createEvents(context);
102 createFileSources(context);
103 createGroupRoles(context);
104 createGroups(context);
105 createGroupsUsers(context);
106 createInternalComponentProps(context);
107 createInternalProperties(context);
108 createIssueChanges(context);
109 createIssues(context);
110 createLiveMeasures(context);
111 createManualMeasures(context);
112 createMetrics(context);
113 createNotifications(context);
114 createOrgQProfiles(context);
115 createOrgQualityGates(context);
116 createOrganizationAlmBindings(context);
117 createOrganizationMembers(context);
118 createOrganizations(context);
119 createPermTemplatesGroups(context);
120 createPermTemplatesUsers(context);
121 createPermTemplatesCharacteristics(context);
122 createPermissionTemplates(context);
123 createPlugins(context);
124 createProjectAlmBindings(context);
125 createProjectBranches(context);
126 createProjectLinks(context);
127 createProjectMappings(context);
128 createProjectMeasures(context);
129 createProjectQprofiles(context);
130 createProjects(context);
131 createProperties(context);
132 createQProfileChanges(context);
133 createQProfileEditGroups(context);
134 createQProfileEditUsers(context);
135 createQualityGateConditions(context);
136 createQualityGates(context);
137 createRulesRepository(context);
138 createRules(context);
139 createRulesMetadata(context);
140 createRulesParameters(context);
141 createRulesProfiles(context);
142 createSnapshots(context);
143 createUserProperties(context);
144 createUserRoles(context);
145 createUserTokens(context);
146 createUsers(context);
147 createWebhookDeliveries(context);
148 createWebhooks(context);
151 private void createActiveRuleParameters(Context context) {
152 String tableName = "active_rule_parameters";
153 IntegerColumnDef activeRuleIdColumnDef = newIntegerColumnDefBuilder().setColumnName("active_rule_id").setIsNullable(false).build();
155 newTableBuilder(tableName)
156 .addPkColumn(ID_COL, AUTO_INCREMENT)
157 .addColumn(activeRuleIdColumnDef)
158 .addColumn(newIntegerColumnDefBuilder().setColumnName("rules_parameter_id").setIsNullable(false).build())
159 .addColumn(newLenientVarcharBuilder("value").setLimit(MAX_SIZE).build())
160 .addColumn(newLenientVarcharBuilder("rules_parameter_key").setLimit(128).build())
162 addIndex(context, tableName, "ix_arp_on_active_rule_id", false, activeRuleIdColumnDef);
165 private void createActiveRules(Context context) {
166 IntegerColumnDef profileIdCol = newIntegerColumnDefBuilder().setColumnName("profile_id").setIsNullable(false).build();
167 IntegerColumnDef ruleIdCol = newIntegerColumnDefBuilder().setColumnName("rule_id").setIsNullable(false).build();
169 newTableBuilder("active_rules")
170 .addPkColumn(ID_COL, AUTO_INCREMENT)
171 .addColumn(profileIdCol)
172 .addColumn(ruleIdCol)
173 .addColumn(newIntegerColumnDefBuilder().setColumnName("failure_level").setIsNullable(false).build())
174 .addColumn(newLenientVarcharBuilder("inheritance").setLimit(10).build())
175 .addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
176 .addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
178 addIndex(context, "active_rules", "uniq_profile_rule_ids", true, profileIdCol, ruleIdCol);
181 private void createAlmAppInstalls(Context context) {
182 String tableName = "alm_app_installs";
183 VarcharColumnDef almIdCol = newVarcharColumnBuilder("alm_id").setIsNullable(false).setLimit(UUID_SIZE).build();
184 VarcharColumnDef ownerCol = newVarcharColumnBuilder("owner_id").setIsNullable(false).setLimit(MAX_SIZE).build();
185 VarcharColumnDef installCol = newVarcharColumnBuilder("install_id").setIsNullable(false).setLimit(MAX_SIZE).build();
186 VarcharColumnDef userExternalIdCol = newVarcharColumnBuilder("user_external_id").setLimit(255).setIsNullable(true).build();
187 context.execute(newTableBuilder(tableName)
188 .addPkColumn(newVarcharColumnBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
191 .addColumn(installCol)
192 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_owner_user").setIsNullable(false).build())
193 .addColumn(userExternalIdCol)
194 .addColumn(TECHNICAL_CREATED_AT_COL)
195 .addColumn(TECHNICAL_UPDATED_AT_COL)
197 addIndex(context, tableName, "alm_app_installs_owner", true, almIdCol, ownerCol);
198 addIndex(context, tableName, "alm_app_installs_install", true, almIdCol, installCol);
199 addIndex(context, tableName, "alm_app_installs_external_id", false, userExternalIdCol);
202 private void createAnalysisProperties(Context context) {
203 String tableName = "analysis_properties";
204 VarcharColumnDef snapshotUuidColumn = newVarcharColumnBuilder("snapshot_uuid")
205 .setIsNullable(false)
209 newTableBuilder(tableName)
210 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
211 .addColumn(snapshotUuidColumn)
212 .addColumn(newVarcharColumnBuilder("kee").setIsNullable(false).setLimit(512).build())
213 .addColumn(newVarcharColumnBuilder("text_value").setIsNullable(true).setLimit(MAX_SIZE).build())
214 .addColumn(newClobColumnDefBuilder().setColumnName("clob_value").setIsNullable(true).build())
215 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_empty").setIsNullable(false).build())
216 .addColumn(TECHNICAL_CREATED_AT_COL)
218 addIndex(context, tableName, "ix_snapshot_uuid", false, snapshotUuidColumn);
221 private void createCeActivity(Context context) {
222 String tableName = "ce_activity";
223 VarcharColumnDef uuidCol = newLenientVarcharBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build();
224 VarcharColumnDef mainComponentUuidCol = newVarcharColumnBuilder("main_component_uuid").setLimit(UUID_SIZE).setIsNullable(true).build();
225 VarcharColumnDef componentUuidCol = newVarcharColumnBuilder(COMPONENT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
226 VarcharColumnDef statusCol = newLenientVarcharBuilder("status").setLimit(15).setIsNullable(false).build();
227 BooleanColumnDef isLastCol = newBooleanColumnDefBuilder().setColumnName("is_last").setIsNullable(false).build();
228 VarcharColumnDef isLastKeyCol = newLenientVarcharBuilder("is_last_key").setLimit(55).setIsNullable(false).build();
229 BooleanColumnDef mainIsLastCol = newBooleanColumnDefBuilder().setColumnName("main_is_last").setIsNullable(false).build();
230 VarcharColumnDef mainIsLastKeyCol = newLenientVarcharBuilder("main_is_last_key").setLimit(55).setIsNullable(false).build();
232 newTableBuilder(tableName)
233 .addPkColumn(ID_COL, AUTO_INCREMENT)
235 .addColumn(newLenientVarcharBuilder("task_type").setLimit(15).setIsNullable(false).build())
236 .addColumn(mainComponentUuidCol)
237 .addColumn(componentUuidCol)
238 .addColumn(statusCol)
239 .addColumn(mainIsLastCol)
240 .addColumn(mainIsLastKeyCol)
241 .addColumn(isLastCol)
242 .addColumn(isLastKeyCol)
243 .addColumn(newLenientVarcharBuilder("submitter_uuid").setLimit(255).setIsNullable(true).build())
244 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("submitted_at").setIsNullable(false).build())
245 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("started_at").setIsNullable(true).build())
246 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("executed_at").setIsNullable(true).build())
247 .addColumn(newIntegerColumnDefBuilder().setColumnName("execution_count").setIsNullable(false).build())
248 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("execution_time_ms").setIsNullable(true).build())
249 .addColumn(newLenientVarcharBuilder(ANALYSIS_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(true).build())
250 .addColumn(newLenientVarcharBuilder("error_message").setLimit(1_000).setIsNullable(true).build())
251 .addColumn(newClobColumnDefBuilder().setColumnName("error_stacktrace").setIsNullable(true).build())
252 .addColumn(newVarcharColumnBuilder("error_type").setLimit(20).setIsNullable(true).build())
253 .addColumn(newVarcharColumnBuilder("worker_uuid").setLimit(UUID_SIZE).setIsNullable(true).build())
254 .addColumn(TECHNICAL_CREATED_AT_COL)
255 .addColumn(TECHNICAL_UPDATED_AT_COL)
257 addIndex(context, tableName, "ce_activity_component", false, componentUuidCol);
258 addIndex(context, tableName, "ce_activity_islast", false, isLastCol, statusCol);
259 addIndex(context, tableName, "ce_activity_islast_key", false, isLastKeyCol);
260 addIndex(context, tableName, "ce_activity_main_component", false, mainComponentUuidCol);
261 addIndex(context, tableName, "ce_activity_main_islast", false, mainIsLastCol, statusCol);
262 addIndex(context, tableName, "ce_activity_main_islast_key", false, mainIsLastKeyCol);
263 addIndex(context, tableName, "ce_activity_uuid", true, uuidCol);
266 private void createCeQueue(Context context) {
267 String tableName = "ce_queue";
268 VarcharColumnDef uuidCol = newLenientVarcharBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build();
269 VarcharColumnDef mainComponentUuidCol = newLenientVarcharBuilder("main_component_uuid").setLimit(UUID_SIZE).setIsNullable(true).build();
270 VarcharColumnDef componentUuidCol = newLenientVarcharBuilder(COMPONENT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
272 newTableBuilder(tableName)
273 .addPkColumn(ID_COL, AUTO_INCREMENT)
275 .addColumn(newLenientVarcharBuilder("task_type").setLimit(15).setIsNullable(false).build())
276 .addColumn(mainComponentUuidCol)
277 .addColumn(componentUuidCol)
278 .addColumn(newLenientVarcharBuilder("status").setLimit(15).setIsNullable(true).build())
279 .addColumn(newLenientVarcharBuilder("submitter_uuid").setLimit(255).setIsNullable(true).build())
280 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("started_at").setIsNullable(true).build())
281 .addColumn(newVarcharColumnBuilder("worker_uuid").setLimit(UUID_SIZE).setIsNullable(true).build())
282 .addColumn(newIntegerColumnDefBuilder().setColumnName("execution_count").setIsNullable(false).build())
283 .addColumn(TECHNICAL_CREATED_AT_COL)
284 .addColumn(TECHNICAL_UPDATED_AT_COL)
286 addIndex(context, tableName, "ce_queue_main_component", false, mainComponentUuidCol);
287 addIndex(context, tableName, "ce_queue_component", false, componentUuidCol);
288 addIndex(context, tableName, "ce_queue_uuid", true, uuidCol);
291 private void createCeScannerContext(Context context) {
293 newTableBuilder("ce_scanner_context")
294 .addPkColumn(newLenientVarcharBuilder(TASK_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
295 .addColumn(newBlobColumnDefBuilder().setColumnName("context_data").setIsNullable(false).build())
296 .addColumn(TECHNICAL_CREATED_AT_COL)
297 .addColumn(TECHNICAL_UPDATED_AT_COL)
301 private void createCeTaskCharacteristics(Context context) {
302 String tableName = "ce_task_characteristics";
303 VarcharColumnDef ceTaskUuidColumn = newLenientVarcharBuilder(TASK_UUID_COL_NAME)
305 .setIsNullable(false)
309 newTableBuilder(tableName)
310 .addPkColumn(newLenientVarcharBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
311 .addColumn(ceTaskUuidColumn)
312 .addColumn(newLenientVarcharBuilder("kee").setLimit(512).setIsNullable(false).build())
313 .addColumn(newLenientVarcharBuilder("text_value").setLimit(512).setIsNullable(true).build())
315 addIndex(context, tableName, "ce_characteristics_" + ceTaskUuidColumn.getName(), false, ceTaskUuidColumn);
318 private void createCeTaskInput(Context context) {
320 newTableBuilder("ce_task_input")
321 .addPkColumn(newLenientVarcharBuilder(TASK_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
322 .addColumn(newBlobColumnDefBuilder().setColumnName("input_data").setIsNullable(true).build())
323 .addColumn(TECHNICAL_CREATED_AT_COL)
324 .addColumn(TECHNICAL_UPDATED_AT_COL)
328 private void createCeTaskMessage(Context context) {
329 String tableName = "ce_task_message";
330 VarcharColumnDef taskUuidCol = newVarcharColumnBuilder(TASK_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
331 context.execute(newTableBuilder(tableName)
332 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
333 .addColumn(taskUuidCol)
334 .addColumn(newVarcharColumnBuilder("message").setIsNullable(false).setLimit(MAX_SIZE).build())
335 .addColumn(TECHNICAL_CREATED_AT_COL)
337 addIndex(context, tableName, tableName + "_task", false, taskUuidCol);
340 private void createDefaultQProfiles(Context context) {
341 String tableName = "default_qprofiles";
342 VarcharColumnDef profileUuidColumn = newLenientVarcharBuilder("qprofile_uuid")
344 .setIsNullable(false)
348 newTableBuilder(tableName)
349 .addPkColumn(newLenientVarcharBuilder(ORGANIZATION_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
350 .addPkColumn(newLenientVarcharBuilder("language").setLimit(20).setIsNullable(false).build())
351 .addColumn(profileUuidColumn)
352 .addColumn(TECHNICAL_CREATED_AT_COL)
353 .addColumn(TECHNICAL_UPDATED_AT_COL)
355 addIndex(context, tableName, "uniq_default_qprofiles_uuid", true, profileUuidColumn);
358 private void createDeprecatedRuleKeys(Context context) {
359 String tableName = "deprecated_rule_keys";
360 IntegerColumnDef ruleIdCol = newIntegerColumnDefBuilder().setColumnName("rule_id").setIsNullable(false).build();
361 VarcharColumnDef oldRepositoryKeyCol = newVarcharColumnBuilder("old_repository_key").setIsNullable(false).setLimit(255).build();
362 VarcharColumnDef oldRuleKeyCol = newVarcharColumnBuilder("old_rule_key").setIsNullable(false).setLimit(200).build();
363 context.execute(newTableBuilder(tableName)
364 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
365 .addColumn(ruleIdCol)
366 .addColumn(oldRepositoryKeyCol)
367 .addColumn(oldRuleKeyCol)
368 .addColumn(TECHNICAL_CREATED_AT_COL)
370 addIndex(context, tableName, "uniq_deprecated_rule_keys", true, oldRepositoryKeyCol, oldRuleKeyCol);
371 addIndex(context, tableName, "rule_id_deprecated_rule_keys", true, ruleIdCol);
374 private void createDuplicationsIndex(Context context) {
375 String tableName = "duplications_index";
376 VarcharColumnDef hashCol = newLenientVarcharBuilder("hash").setLimit(50).setIsNullable(false).build();
377 VarcharColumnDef analysisUuidCol = newLenientVarcharBuilder(ANALYSIS_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
378 VarcharColumnDef componentUuidCol = newLenientVarcharBuilder(COMPONENT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
380 newTableBuilder(tableName)
381 .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
382 .addColumn(analysisUuidCol)
383 .addColumn(componentUuidCol)
385 .addColumn(newIntegerColumnDefBuilder().setColumnName("index_in_file").setIsNullable(false).build())
386 .addColumn(newIntegerColumnDefBuilder().setColumnName("start_line").setIsNullable(false).build())
387 .addColumn(newIntegerColumnDefBuilder().setColumnName("end_line").setIsNullable(false).build())
390 addIndex(context, tableName, "duplications_index_hash", false, hashCol);
391 addIndex(context, tableName, "duplication_analysis_component", false, analysisUuidCol, componentUuidCol);
394 private void createEsQueue(Context context) {
395 String tableName = "es_queue";
396 BigIntegerColumnDef createdAtCol = TECHNICAL_CREATED_AT_COL;
398 newTableBuilder(tableName)
399 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
400 .addColumn(newVarcharColumnBuilder("doc_type").setIsNullable(false).setLimit(40).build())
401 .addColumn(newVarcharColumnBuilder("doc_id").setIsNullable(false).setLimit(MAX_SIZE).build())
402 .addColumn(newVarcharColumnBuilder("doc_id_type").setIsNullable(true).setLimit(20).build())
403 .addColumn(newVarcharColumnBuilder("doc_routing").setIsNullable(true).setLimit(MAX_SIZE).build())
404 .addColumn(createdAtCol)
406 addIndex(context, tableName, "es_queue_created_at", false, createdAtCol);
409 private void createEventComponentChanges(Context context) {
410 String tableName = "event_component_changes";
411 VarcharColumnDef eventUuidCol = newVarcharColumnBuilder("event_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
412 VarcharColumnDef eventComponentUuidCol = newVarcharColumnBuilder("event_component_uuid").setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
413 VarcharColumnDef eventAnalysisUuidCol = newVarcharColumnBuilder("event_analysis_uuid").setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
414 VarcharColumnDef changeCategoryCol = newVarcharColumnBuilder("change_category").setIsNullable(false).setLimit(12).build();
415 VarcharColumnDef componentUuidCol = newVarcharColumnBuilder(COMPONENT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
416 context.execute(newTableBuilder(tableName)
417 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
418 .addColumn(eventUuidCol)
419 .addColumn(eventComponentUuidCol)
420 .addColumn(eventAnalysisUuidCol)
421 .addColumn(changeCategoryCol)
422 .addColumn(componentUuidCol)
423 .addColumn(newVarcharColumnBuilder("component_key").setIsNullable(false).setLimit(400).build())
424 .addColumn(newVarcharColumnBuilder("component_name").setIsNullable(false).setLimit(2000).build())
425 .addColumn(newVarcharColumnBuilder("component_branch_key").setIsNullable(true).setLimit(255).build())
426 .addColumn(TECHNICAL_CREATED_AT_COL)
428 addIndex(context, tableName, tableName + "_unique", true, eventUuidCol, changeCategoryCol, componentUuidCol);
429 addIndex(context, tableName, "event_cpnt_changes_cpnt", false, eventComponentUuidCol);
430 addIndex(context, tableName, "event_cpnt_changes_analysis", false, eventAnalysisUuidCol);
433 private void createEvents(Context context) {
434 String tableName = "events";
435 VarcharColumnDef uuidCol = newVarcharColumnBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build();
436 VarcharColumnDef analysisUuidCol = newLenientVarcharBuilder(ANALYSIS_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
437 VarcharColumnDef componentUuid = newLenientVarcharBuilder(COMPONENT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
439 newTableBuilder(tableName)
440 .addPkColumn(ID_COL, AUTO_INCREMENT)
442 .addColumn(analysisUuidCol)
443 .addColumn(newLenientVarcharBuilder("name").setLimit(400).setIsNullable(true).build())
444 .addColumn(newLenientVarcharBuilder("category").setLimit(50).build())
445 .addColumn(newLenientVarcharBuilder(DESCRIPTION_COL_NAME).setLimit(MAX_SIZE).build())
446 .addColumn(newLenientVarcharBuilder("event_data").setLimit(MAX_SIZE).build())
447 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("event_date").setIsNullable(false).build())
448 .addColumn(TECHNICAL_CREATED_AT_COL)
449 .addColumn(componentUuid)
451 addIndex(context, tableName, "events_uuid", true, uuidCol);
452 addIndex(context, tableName, "events_analysis", false, analysisUuidCol);
453 addIndex(context, tableName, "events_component_uuid", false, componentUuid);
456 private void createFileSources(Context context) {
457 String tableName = "file_sources";
458 VarcharColumnDef projectUuidCol = newLenientVarcharBuilder(PROJECT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
459 BigIntegerColumnDef updatedAtCol = TECHNICAL_UPDATED_AT_COL;
460 VarcharColumnDef fileUuidCol = newLenientVarcharBuilder("file_uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
462 newTableBuilder(tableName)
463 .addPkColumn(ID_COL, AUTO_INCREMENT)
464 .addColumn(projectUuidCol)
465 .addColumn(fileUuidCol)
466 .addColumn(newClobColumnDefBuilder().setColumnName("line_hashes").setIsNullable(true).build())
467 .addColumn(newIntegerColumnDefBuilder().setColumnName("line_hashes_version").setIsNullable(true).build())
468 .addColumn(newLenientVarcharBuilder("data_hash").setLimit(50).setIsNullable(true).build())
469 .addColumn(newLenientVarcharBuilder("src_hash").setLimit(50).setIsNullable(true).build())
470 .addColumn(newLenientVarcharBuilder("revision").setLimit(100).setIsNullable(true).build())
471 .addColumn(newIntegerColumnDefBuilder().setColumnName("line_count").setIsNullable(false).build())
472 .addColumn(newBlobColumnDefBuilder().setColumnName("binary_data").setIsNullable(true).build())
473 .addColumn(TECHNICAL_CREATED_AT_COL)
474 .addColumn(updatedAtCol)
476 addIndex(context, tableName, "file_sources_file_uuid", true, fileUuidCol);
477 addIndex(context, tableName, "file_sources_project_uuid", false, projectUuidCol);
478 addIndex(context, tableName, "file_sources_updated_at", false, updatedAtCol);
481 private void createGroupRoles(Context context) {
482 String tableName = "group_roles";
483 IntegerColumnDef groupIdCol = newIntegerColumnDefBuilder().setColumnName("group_id").setIsNullable(true).build();
484 IntegerColumnDef resourceIdCol = newIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build();
485 VarcharColumnDef roleCol = newLenientVarcharBuilder("role").setLimit(64).setIsNullable(false).build();
486 VarcharColumnDef organizationUuidCol = newLenientVarcharBuilder(ORGANIZATION_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
488 newTableBuilder(tableName)
489 .addPkColumn(ID_COL, AUTO_INCREMENT)
490 .addColumn(organizationUuidCol)
491 .addColumn(groupIdCol)
492 .addColumn(resourceIdCol)
495 addIndex(context, tableName, "uniq_group_roles", true, organizationUuidCol, groupIdCol, resourceIdCol, roleCol);
496 addIndex(context, tableName, "group_roles_resource", false, resourceIdCol);
499 private void createGroups(Context context) {
501 newTableBuilder("groups")
502 .addPkColumn(ID_COL, AUTO_INCREMENT)
503 .addColumn(newLenientVarcharBuilder(ORGANIZATION_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build())
504 .addColumn(newLenientVarcharBuilder("name").setLimit(500).setIsNullable(true).build())
505 .addColumn(newLenientVarcharBuilder(DESCRIPTION_COL_NAME).setLimit(200).setIsNullable(true).build())
506 .addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
507 .addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
511 private void createGroupsUsers(Context context) {
512 String tableName = "groups_users";
513 BigIntegerColumnDef userIdCol = newBigIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(true).build();
514 BigIntegerColumnDef groupIdCol = newBigIntegerColumnDefBuilder().setColumnName("group_id").setIsNullable(true).build();
516 newTableBuilder(tableName)
517 .addColumn(userIdCol)
518 .addColumn(groupIdCol)
520 addIndex(context, tableName, "index_groups_users_on_user_id", false, userIdCol);
521 addIndex(context, tableName, "index_groups_users_on_group_id", false, groupIdCol);
522 addIndex(context, tableName, "groups_users_unique", true, groupIdCol, userIdCol);
525 private void createInternalComponentProps(Context context) {
526 String tableName = "internal_component_props";
527 VarcharColumnDef componentUuidCol = newVarcharColumnBuilder(COMPONENT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
528 VarcharColumnDef keeCol = newVarcharColumnBuilder("kee").setIsNullable(false).setLimit(512).build();
529 context.execute(newTableBuilder(tableName)
530 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
531 .addColumn(componentUuidCol)
533 .addColumn(newVarcharColumnBuilder("value").setIsNullable(true).setLimit(MAX_SIZE).build())
534 .addColumn(TECHNICAL_UPDATED_AT_COL)
535 .addColumn(TECHNICAL_CREATED_AT_COL)
537 addIndex(context, tableName, "unique_component_uuid_kee", true, componentUuidCol, keeCol);
540 private void createInternalProperties(Context context) {
542 newTableBuilder("internal_properties")
543 .addPkColumn(newLenientVarcharBuilder("kee").setLimit(20).setIsNullable(false).build())
544 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_empty").setIsNullable(false).build())
545 .addColumn(newVarcharColumnDefBuilder().setColumnName("text_value").setLimit(MAX_SIZE).setIgnoreOracleUnit(true).build())
546 .addColumn(newClobColumnDefBuilder().setColumnName("clob_value").setIsNullable(true).build())
547 .addColumn(TECHNICAL_CREATED_AT_COL)
551 private void createIssueChanges(Context context) {
552 String tableName = "issue_changes";
553 VarcharColumnDef issueKeyCol = newLenientVarcharBuilder("issue_key").setLimit(50).setIsNullable(false).build();
554 VarcharColumnDef keeCol = newLenientVarcharBuilder("kee").setLimit(50).build();
556 newTableBuilder(tableName)
557 .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
559 .addColumn(issueKeyCol)
560 .addColumn(newLenientVarcharBuilder("user_login").setLimit(255).build())
561 .addColumn(newLenientVarcharBuilder("change_type").setLimit(20).build())
562 .addColumn(newClobColumnDefBuilder().setColumnName("change_data").build())
563 .addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
564 .addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
565 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_change_creation_date").build())
567 addIndex(context, tableName, "issue_changes_issue_key", false, issueKeyCol);
568 addIndex(context, tableName, "issue_changes_kee", false, keeCol);
571 private void createIssues(Context context) {
572 VarcharColumnDef assigneeCol = newLenientVarcharBuilder("assignee").setLimit(255).build();
573 VarcharColumnDef componentUuidCol = newLenientVarcharBuilder(COMPONENT_UUID_COL_NAME).setLimit(50).build();
574 BigIntegerColumnDef issueCreationDateCol = newBigIntegerColumnDefBuilder().setColumnName("issue_creation_date").build();
575 VarcharColumnDef keeCol = newLenientVarcharBuilder("kee").setLimit(50).setIsNullable(false).build();
576 VarcharColumnDef projectUuidCol = newLenientVarcharBuilder(PROJECT_UUID_COL_NAME).setLimit(50).build();
577 VarcharColumnDef resolutionCol = newLenientVarcharBuilder("resolution").setLimit(20).build();
578 IntegerColumnDef ruleIdCol = newIntegerColumnDefBuilder().setColumnName("rule_id").build();
579 BigIntegerColumnDef updatedAtCol = NULLABLE_TECHNICAL_UPDATED_AT_COL;
581 newTableBuilder("issues")
582 .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
584 .addColumn(ruleIdCol)
585 .addColumn(newLenientVarcharBuilder("severity").setLimit(10).build())
586 .addColumn(newBooleanColumnDefBuilder().setColumnName("manual_severity").setIsNullable(false).build())
587 // unit has been fixed in SonarQube 5.6 (see migration 1151, SONAR-7493)
588 .addColumn(newVarcharColumnBuilder("message").setLimit(MAX_SIZE).build())
589 .addColumn(newIntegerColumnDefBuilder().setColumnName("line").build())
590 .addColumn(newDecimalColumnDefBuilder().setColumnName("gap").setPrecision(30).setScale(20).build())
591 .addColumn(newLenientVarcharBuilder("status").setLimit(20).build())
592 .addColumn(resolutionCol)
593 .addColumn(newLenientVarcharBuilder("checksum").setLimit(1000).build())
594 .addColumn(newLenientVarcharBuilder("reporter").setLimit(255).build())
595 .addColumn(assigneeCol)
596 .addColumn(newLenientVarcharBuilder("author_login").setLimit(255).build())
597 .addColumn(newLenientVarcharBuilder("action_plan_key").setLimit(50).build())
598 .addColumn(newLenientVarcharBuilder("issue_attributes").setLimit(MAX_SIZE).build())
599 .addColumn(newIntegerColumnDefBuilder().setColumnName("effort").build())
600 .addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
601 .addColumn(updatedAtCol)
602 .addColumn(issueCreationDateCol)
603 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_update_date").build())
604 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("issue_close_date").build())
605 .addColumn(newLenientVarcharBuilder("tags").setLimit(MAX_SIZE).build())
606 .addColumn(componentUuidCol)
607 .addColumn(projectUuidCol)
608 .addColumn(newBlobColumnDefBuilder().setColumnName("locations").build())
609 .addColumn(new TinyIntColumnDef.Builder().setColumnName("issue_type").build())
610 .addColumn(newBooleanColumnDefBuilder().setColumnName("from_hotspot").setIsNullable(true).build())
612 addIndex(context, "issues", "issues_assignee", false, assigneeCol);
613 addIndex(context, "issues", "issues_component_uuid", false, componentUuidCol);
614 addIndex(context, "issues", "issues_creation_date", false, issueCreationDateCol);
615 addIndex(context, "issues", "issues_kee", true, keeCol);
616 addIndex(context, "issues", "issues_project_uuid", false, projectUuidCol);
617 addIndex(context, "issues", "issues_resolution", false, resolutionCol);
618 addIndex(context, "issues", "issues_rule_id", false, ruleIdCol);
619 addIndex(context, "issues", "issues_updated_at", false, updatedAtCol);
622 private void createLiveMeasures(Context context) {
623 String tableName = "live_measures";
624 VarcharColumnDef projectUuidCol = newVarcharColumnBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
625 VarcharColumnDef componentUuidCol = newVarcharColumnBuilder(COMPONENT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
626 IntegerColumnDef metricIdCol = newIntegerColumnDefBuilder().setColumnName(METRIC_ID_COL_NAME).setIsNullable(false).build();
627 context.execute(newTableBuilder(tableName)
628 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
629 .addColumn(projectUuidCol)
630 .addColumn(componentUuidCol)
631 .addColumn(metricIdCol)
632 .addColumn(newDecimalColumnDefBuilder().setColumnName("value").setPrecision(38).setScale(20).build())
633 .addColumn(newVarcharColumnBuilder("text_value").setIsNullable(true).setLimit(MAX_SIZE).build())
634 .addColumn(newDecimalColumnDefBuilder().setColumnName("variation").setPrecision(38).setScale(20).build())
635 .addColumn(newBlobColumnDefBuilder().setColumnName("measure_data").setIsNullable(true).build())
636 .addColumn(newVarcharColumnBuilder("update_marker").setIsNullable(true).setLimit(UUID_SIZE).build())
637 .addColumn(TECHNICAL_CREATED_AT_COL)
638 .addColumn(TECHNICAL_UPDATED_AT_COL)
640 addIndex(context, tableName, "live_measures_project", false, projectUuidCol);
641 addIndex(context, tableName, "live_measures_component", true, componentUuidCol, metricIdCol);
644 private void createManualMeasures(Context context) {
645 String tableName = "manual_measures";
646 VarcharColumnDef componentUuidCol = newLenientVarcharBuilder(COMPONENT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
648 newTableBuilder(tableName)
649 .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
650 .addColumn(newIntegerColumnDefBuilder().setColumnName(METRIC_ID_COL_NAME).setIsNullable(false).build())
651 .addColumn(newDecimalColumnDefBuilder().setColumnName("value").setPrecision(38).setScale(20).build())
652 .addColumn(newLenientVarcharBuilder("text_value").setLimit(MAX_SIZE).build())
653 .addColumn(newLenientVarcharBuilder(USER_UUID_COL_NAME).setLimit(255).build())
654 .addColumn(newLenientVarcharBuilder(DESCRIPTION_COL_NAME).setLimit(MAX_SIZE).build())
655 .addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
656 .addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
657 .addColumn(componentUuidCol)
659 addIndex(context, tableName, "manual_measures_component_uuid", false, componentUuidCol);
662 private void createMetrics(Context context) {
663 String tableName = "metrics";
664 VarcharColumnDef nameCol = newLenientVarcharBuilder("name").setLimit(64).setIsNullable(false).build();
666 newTableBuilder(tableName)
667 .addPkColumn(ID_COL, AUTO_INCREMENT)
669 .addColumn(newLenientVarcharBuilder(DESCRIPTION_COL_NAME).setLimit(255).build())
670 .addColumn(newIntegerColumnDefBuilder().setColumnName("direction").setIsNullable(false).setDefaultValue(0).build())
671 .addColumn(newLenientVarcharBuilder("domain").setLimit(64).build())
672 .addColumn(newLenientVarcharBuilder("short_name").setLimit(64).build())
673 .addColumn(newBooleanColumnDefBuilder().setColumnName("qualitative").setDefaultValue(false).setIsNullable(false).build())
674 .addColumn(newLenientVarcharBuilder("val_type").setLimit(8).build())
675 .addColumn(newBooleanColumnDefBuilder().setColumnName("user_managed").setDefaultValue(false).build())
676 .addColumn(newBooleanColumnDefBuilder().setColumnName("enabled").setDefaultValue(true).build())
677 .addColumn(newDecimalColumnDefBuilder().setColumnName("worst_value").setPrecision(38).setScale(20).build())
678 .addColumn(newDecimalColumnDefBuilder().setColumnName("best_value").setPrecision(38).setScale(20).build())
679 .addColumn(newBooleanColumnDefBuilder().setColumnName("optimized_best_value").build())
680 .addColumn(newBooleanColumnDefBuilder().setColumnName("hidden").build())
681 .addColumn(newBooleanColumnDefBuilder().setColumnName("delete_historical_data").build())
682 .addColumn(newIntegerColumnDefBuilder().setColumnName("decimal_scale").build())
684 addIndex(context, tableName, "metrics_unique_name", true, nameCol);
687 private void createNotifications(Context context) {
689 newTableBuilder("notifications")
690 .addPkColumn(ID_COL, AUTO_INCREMENT)
691 .addColumn(newBlobColumnDefBuilder().setColumnName("data").build())
695 private void createOrgQProfiles(Context context) {
696 String tableName = "org_qprofiles";
697 int profileUuidSize = 255;
698 VarcharColumnDef organizationCol = newLenientVarcharBuilder(ORGANIZATION_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
699 VarcharColumnDef rulesProfileUuidCol = newLenientVarcharBuilder("rules_profile_uuid").setLimit(profileUuidSize).setIsNullable(false).build();
700 VarcharColumnDef parentUuidCol = newLenientVarcharBuilder("parent_uuid").setLimit(profileUuidSize).setIsNullable(true).build();
702 newTableBuilder(tableName)
703 .addPkColumn(newVarcharColumnBuilder("uuid").setLimit(profileUuidSize).setIsNullable(false).build())
704 .addColumn(organizationCol)
705 .addColumn(rulesProfileUuidCol)
706 .addColumn(parentUuidCol)
707 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_used").setIsNullable(true).build())
708 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("user_updated_at").setIsNullable(true).build())
709 .addColumn(TECHNICAL_CREATED_AT_COL)
710 .addColumn(TECHNICAL_UPDATED_AT_COL)
712 addIndex(context, tableName, "qprofiles_org_uuid", false, organizationCol);
713 addIndex(context, tableName, "qprofiles_rp_uuid", false, rulesProfileUuidCol);
714 addIndex(context, tableName, "org_qprofiles_parent_uuid", false, parentUuidCol);
717 private void createOrgQualityGates(Context context) {
718 String tableName = "org_quality_gates";
719 VarcharColumnDef organizationUuidCol = newVarcharColumnBuilder(ORGANIZATION_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
720 VarcharColumnDef qualityGateUuidCol = newVarcharColumnBuilder("quality_gate_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
721 context.execute(newTableBuilder(tableName)
722 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
723 .addColumn(organizationUuidCol)
724 .addColumn(qualityGateUuidCol)
726 addIndex(context, tableName, "uniq_org_quality_gates", true, organizationUuidCol, qualityGateUuidCol);
729 private void createOrganizationAlmBindings(Context context) {
730 String tableName = "organization_alm_bindings";
731 VarcharColumnDef organizationUuidCol = newVarcharColumnBuilder(ORGANIZATION_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
732 VarcharColumnDef almAppInstallUuidCol = newVarcharColumnBuilder("alm_app_install_uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
733 context.execute(newTableBuilder(tableName)
734 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
735 .addColumn(organizationUuidCol)
736 .addColumn(almAppInstallUuidCol)
737 .addColumn(newVarcharColumnBuilder("alm_id").setIsNullable(false).setLimit(UUID_SIZE).build())
738 .addColumn(newVarcharColumnBuilder("url").setIsNullable(false).setLimit(2000).build())
739 .addColumn(newVarcharColumnBuilder(USER_UUID_COL_NAME).setIsNullable(false).setLimit(255).build())
740 .addColumn(newBooleanColumnDefBuilder().setColumnName("members_sync_enabled").setIsNullable(true).build())
741 .addColumn(TECHNICAL_CREATED_AT_COL)
743 addIndex(context, tableName, "org_alm_bindings_org", true, organizationUuidCol);
744 addIndex(context, tableName, "org_alm_bindings_install", true, almAppInstallUuidCol);
747 private void createOrganizationMembers(Context context) {
748 String tableName = "organization_members";
749 IntegerColumnDef userIdCol = newIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(false).build();
751 newTableBuilder(tableName)
752 .addPkColumn(newVarcharColumnBuilder(ORGANIZATION_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
753 .addPkColumn(userIdCol)
755 addIndex(context, tableName, "ix_org_members_on_user_id", false, userIdCol);
758 private void createOrganizations(Context context) {
759 String tableName = "organizations";
760 VarcharColumnDef keeColumn = newLenientVarcharBuilder("kee").setLimit(255).setIsNullable(false).build();
762 newTableBuilder(tableName)
763 .addPkColumn(newLenientVarcharBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
764 .addColumn(keeColumn)
765 .addColumn(newLenientVarcharBuilder("name").setLimit(255).setIsNullable(false).build())
766 .addColumn(newLenientVarcharBuilder(DESCRIPTION_COL_NAME).setLimit(256).setIsNullable(true).build())
767 .addColumn(newLenientVarcharBuilder("url").setLimit(256).setIsNullable(true).build())
768 .addColumn(newLenientVarcharBuilder("avatar_url").setLimit(256).setIsNullable(true).build())
769 .addColumn(newBooleanColumnDefBuilder().setColumnName("guarded").setIsNullable(false).build())
770 .addColumn(newIntegerColumnDefBuilder().setColumnName("default_group_id").setIsNullable(true).build())
771 .addColumn(newVarcharColumnBuilder("default_quality_gate_uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
772 .addColumn(newVarcharColumnBuilder("default_perm_template_project").setLimit(UUID_SIZE).setIsNullable(true).build())
773 .addColumn(newVarcharColumnBuilder("default_perm_template_app").setLimit(UUID_SIZE).setIsNullable(true).build())
774 .addColumn(newVarcharColumnBuilder("default_perm_template_port").setLimit(UUID_SIZE).setIsNullable(true).build())
775 .addColumn(newBooleanColumnDefBuilder().setColumnName("new_project_private").setIsNullable(false).build())
776 .addColumn(newVarcharColumnBuilder("subscription").setLimit(UUID_SIZE).setIsNullable(false).build())
777 .addColumn(TECHNICAL_CREATED_AT_COL)
778 .addColumn(TECHNICAL_UPDATED_AT_COL)
780 addIndex(context, tableName, "organization_key", true, keeColumn);
783 private void createPermTemplatesGroups(Context context) {
785 newTableBuilder("perm_templates_groups")
786 .addPkColumn(ID_COL, AUTO_INCREMENT)
787 .addColumn(newIntegerColumnDefBuilder().setColumnName("group_id").build())
788 .addColumn(newIntegerColumnDefBuilder().setColumnName("template_id").setIsNullable(false).build())
789 .addColumn(newLenientVarcharBuilder("permission_reference").setLimit(64).setIsNullable(false).build())
790 .addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
791 .addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
795 private void createPermTemplatesUsers(Context context) {
797 newTableBuilder("perm_templates_users")
798 .addPkColumn(ID_COL, AUTO_INCREMENT)
799 .addColumn(newIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(false).build())
800 .addColumn(newIntegerColumnDefBuilder().setColumnName("template_id").setIsNullable(false).build())
801 .addColumn(newLenientVarcharBuilder("permission_reference").setLimit(64).setIsNullable(false).build())
802 .addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
803 .addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
807 private void createPermTemplatesCharacteristics(Context context) {
808 String tableName = "perm_tpl_characteristics";
809 IntegerColumnDef templateIdColumn = newIntegerColumnDefBuilder().setColumnName("template_id").setIsNullable(false).build();
810 VarcharColumnDef permissionKeyColumn = newLenientVarcharBuilder("permission_key").setLimit(64).setIsNullable(false).build();
812 newTableBuilder(tableName)
813 .addPkColumn(ID_COL, AUTO_INCREMENT)
814 .addColumn(templateIdColumn)
815 .addColumn(permissionKeyColumn)
816 .addColumn(newBooleanColumnDefBuilder().setColumnName("with_project_creator").setIsNullable(false).setDefaultValue(false).build())
817 .addColumn(TECHNICAL_CREATED_AT_COL)
818 .addColumn(TECHNICAL_UPDATED_AT_COL)
821 addIndex(context, tableName, "uniq_perm_tpl_charac", true, templateIdColumn, permissionKeyColumn);
824 private void createPermissionTemplates(Context context) {
826 newTableBuilder("permission_templates")
827 .addPkColumn(ID_COL, AUTO_INCREMENT)
828 .addColumn(newLenientVarcharBuilder(ORGANIZATION_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build())
829 .addColumn(newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build())
830 .addColumn(newLenientVarcharBuilder("kee").setLimit(100).setIsNullable(false).build())
831 .addColumn(newLenientVarcharBuilder(DESCRIPTION_COL_NAME).setLimit(MAX_SIZE).build())
832 .addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
833 .addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
834 .addColumn(newLenientVarcharBuilder("key_pattern").setLimit(500).build())
838 private void createPlugins(Context context) {
839 int pluginKeyMaxSize = 200;
840 String tableName = "plugins";
841 VarcharColumnDef keyColumn = newVarcharColumnBuilder("kee").setLimit(pluginKeyMaxSize).setIsNullable(false).build();
843 newTableBuilder(tableName)
844 .addPkColumn(newLenientVarcharBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
845 .addColumn(keyColumn)
846 .addColumn(newVarcharColumnBuilder("base_plugin_key").setLimit(pluginKeyMaxSize).setIsNullable(true).build())
847 .addColumn(newVarcharColumnBuilder("file_hash").setLimit(200).setIsNullable(false).build())
848 .addColumn(TECHNICAL_CREATED_AT_COL)
849 .addColumn(TECHNICAL_UPDATED_AT_COL)
851 addIndex(context, tableName, "plugins_key", true, keyColumn);
854 private void createProjectAlmBindings(Context context) {
855 String tableName = "project_alm_bindings";
856 VarcharColumnDef almIdCol = newVarcharColumnDefBuilder().setColumnName("alm_id").setIsNullable(false).setLimit(40).build();
857 VarcharColumnDef repoIdCol = newVarcharColumnDefBuilder().setColumnName("repo_id").setIsNullable(false).setLimit(256).build();
858 VarcharColumnDef projectUuidCol = newVarcharColumnDefBuilder().setColumnName(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(40).build();
859 context.execute(newTableBuilder(tableName)
860 .addPkColumn(newVarcharColumnBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
862 .addColumn(repoIdCol)
863 .addColumn(projectUuidCol)
864 .addColumn(newVarcharColumnBuilder("github_slug").setIsNullable(true).setLimit(256).build())
865 .addColumn(newVarcharColumnBuilder("url").setIsNullable(false).setLimit(2000).build())
866 .addColumn(TECHNICAL_CREATED_AT_COL)
867 .addColumn(TECHNICAL_UPDATED_AT_COL)
869 addIndex(context, tableName, tableName + "_alm_repo", true, almIdCol, repoIdCol);
870 addIndex(context, tableName, tableName + "_project", true, projectUuidCol);
873 private void createProjectBranches(Context context) {
874 String tableName = "project_branches";
875 VarcharColumnDef projectUuidCol = newVarcharColumnBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build();
876 VarcharColumnDef keeCol = newVarcharColumnBuilder("kee").setIsNullable(false).setLimit(255).build();
877 VarcharColumnDef keyTypeCol = newVarcharColumnBuilder("key_type").setIsNullable(false).setLimit(12).build();
879 newTableBuilder(tableName)
880 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(OLD_UUID_VARCHAR_SIZE).build())
881 .addColumn(projectUuidCol)
883 .addColumn(newVarcharColumnBuilder("branch_type").setIsNullable(true).setLimit(12).build())
884 .addColumn(newVarcharColumnBuilder("merge_branch_uuid").setIsNullable(true).setLimit(OLD_UUID_VARCHAR_SIZE).build())
885 .addColumn(keyTypeCol)
886 .addColumn(newBlobColumnDefBuilder().setColumnName("pull_request_binary").setIsNullable(true).build())
887 .addColumn(newVarcharColumnBuilder("manual_baseline_analysis_uuid").setIsNullable(true).setLimit(UUID_SIZE).build())
888 .addColumn(TECHNICAL_CREATED_AT_COL)
889 .addColumn(TECHNICAL_UPDATED_AT_COL)
891 addIndex(context, tableName, "project_branches_kee_key_type", true, projectUuidCol, keeCol, keyTypeCol);
894 private void createProjectLinks(Context context) {
895 String tableName = "project_links";
896 VarcharColumnDef projectUuidCol = newVarcharColumnBuilder(PROJECT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
897 context.execute(newTableBuilder(tableName)
898 .addPkColumn(newVarcharColumnBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
899 .addColumn(projectUuidCol)
900 .addColumn(newVarcharColumnBuilder("link_type").setLimit(20).setIsNullable(false).build())
901 .addColumn(newVarcharColumnBuilder("name").setLimit(128).setIsNullable(true).build())
902 .addColumn(newVarcharColumnBuilder("href").setLimit(2048).setIsNullable(false).build())
903 .addColumn(TECHNICAL_CREATED_AT_COL)
904 .addColumn(TECHNICAL_UPDATED_AT_COL)
906 addIndex(context, tableName, "project_links_project", false, projectUuidCol);
909 private void createProjectMappings(Context context) {
910 String tableName = "project_mappings";
911 VarcharColumnDef keyTypeCol = newVarcharColumnBuilder("key_type").setIsNullable(false).setLimit(200).build();
912 VarcharColumnDef keyCol = newVarcharColumnBuilder("kee").setIsNullable(false).setLimit(MAX_SIZE).build();
913 VarcharColumnDef projectUuidCol = newVarcharColumnBuilder(PROJECT_UUID_COL_NAME).setIsNullable(false).setLimit(UUID_SIZE).build();
914 context.execute(newTableBuilder(tableName)
915 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
916 .addColumn(keyTypeCol)
918 .addColumn(projectUuidCol)
919 .addColumn(TECHNICAL_CREATED_AT_COL)
921 addIndex(context, tableName, "key_type_kee", true, keyTypeCol, keyCol);
922 addIndex(context, tableName, PROJECT_UUID_COL_NAME, false, projectUuidCol);
925 private void createProjectMeasures(Context context) {
926 String tableName = "project_measures";
927 IntegerColumnDef personIdCol = newIntegerColumnDefBuilder().setColumnName("person_id").build();
928 IntegerColumnDef metricIdCol = newIntegerColumnDefBuilder().setColumnName(METRIC_ID_COL_NAME).setIsNullable(false).build();
929 VarcharColumnDef analysisUuidCol = newLenientVarcharBuilder(ANALYSIS_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
930 VarcharColumnDef componentUuidCol = newLenientVarcharBuilder(COMPONENT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
932 newTableBuilder(tableName)
933 .addPkColumn(newBigIntegerColumnDefBuilder().setColumnName("id").setIsNullable(false).build(), AUTO_INCREMENT)
934 .addColumn(newDecimalColumnDefBuilder().setColumnName("value").setPrecision(38).setScale(20).build())
935 .addColumn(metricIdCol)
936 .addColumn(analysisUuidCol)
937 .addColumn(componentUuidCol)
938 .addColumn(newLenientVarcharBuilder("text_value").setLimit(MAX_SIZE).build())
939 .addColumn(newLenientVarcharBuilder("alert_status").setLimit(5).build())
940 .addColumn(newLenientVarcharBuilder("alert_text").setLimit(MAX_SIZE).build())
941 .addColumn(newLenientVarcharBuilder(DESCRIPTION_COL_NAME).setLimit(MAX_SIZE).build())
942 .addColumn(personIdCol)
943 .addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_1").setPrecision(38).setScale(20).build())
944 .addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_2").setPrecision(38).setScale(20).build())
945 .addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_3").setPrecision(38).setScale(20).build())
946 .addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_4").setPrecision(38).setScale(20).build())
947 .addColumn(newDecimalColumnDefBuilder().setColumnName("variation_value_5").setPrecision(38).setScale(20).build())
948 .addColumn(newBlobColumnDefBuilder().setColumnName("measure_data").build())
950 addIndex(context, tableName, "measures_analysis_metric", false, analysisUuidCol, metricIdCol);
951 addIndex(context, tableName, "measures_component_uuid", false, componentUuidCol);
954 private void createProjectQprofiles(Context context) {
955 String tableName = "project_qprofiles";
956 VarcharColumnDef projectUuid = newLenientVarcharBuilder(PROJECT_UUID_COL_NAME).setLimit(50).setIsNullable(false).build();
957 VarcharColumnDef profileKey = newLenientVarcharBuilder("profile_key").setLimit(50).setIsNullable(false).build();
959 newTableBuilder(tableName)
960 .addPkColumn(ID_COL, AUTO_INCREMENT)
961 .addColumn(projectUuid)
962 .addColumn(profileKey)
964 addIndex(context, tableName, "uniq_project_qprofiles", true, projectUuid, profileKey);
967 private void createProjects(Context context) {
968 String tableName = "projects";
969 VarcharColumnDef uuidCol = newLenientVarcharBuilder("uuid").setLimit(50).setIsNullable(false).build();
970 VarcharColumnDef organizationUuidCol = newVarcharColumnBuilder(ORGANIZATION_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
971 VarcharColumnDef keeCol = newLenientVarcharBuilder("kee").setLimit(400).setIsNullable(true).build();
972 VarcharColumnDef qualifierCol = newLenientVarcharBuilder("qualifier").setLimit(10).setIsNullable(true).build();
973 VarcharColumnDef rootUuidCol = newVarcharColumnBuilder("root_uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
974 VarcharColumnDef projectUuidCol = newLenientVarcharBuilder(PROJECT_UUID_COL_NAME).setLimit(50).setIsNullable(false).build();
975 VarcharColumnDef moduleUuidCol = newLenientVarcharBuilder("module_uuid").setLimit(50).setIsNullable(true).build();
977 newTableBuilder(tableName)
978 .addPkColumn(ID_COL, AUTO_INCREMENT)
980 .addColumn(organizationUuidCol)
982 .addColumn(newLenientVarcharBuilder("deprecated_kee").setLimit(400).setIsNullable(true).build())
983 .addColumn(newLenientVarcharBuilder("name").setLimit(2_000).setIsNullable(true).build())
984 .addColumn(newLenientVarcharBuilder("long_name").setLimit(2_000).setIsNullable(true).build())
985 .addColumn(newLenientVarcharBuilder(DESCRIPTION_COL_NAME).setLimit(2_000).setIsNullable(true).build())
986 .addColumn(newBooleanColumnDefBuilder().setColumnName("enabled").setDefaultValue(true).setIsNullable(false).build())
987 .addColumn(newLenientVarcharBuilder("scope").setLimit(3).setIsNullable(true).build())
988 .addColumn(qualifierCol)
989 .addColumn(newBooleanColumnDefBuilder().setColumnName("private").setIsNullable(false).build())
990 .addColumn(rootUuidCol)
991 .addColumn(newLenientVarcharBuilder("language").setLimit(20).setIsNullable(true).build())
992 .addColumn(newVarcharColumnBuilder("copy_component_uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(true).build())
993 .addColumn(newVarcharColumnBuilder("developer_uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(true).build())
994 .addColumn(newLenientVarcharBuilder("path").setLimit(2_000).setIsNullable(true).build())
995 .addColumn(newLenientVarcharBuilder("uuid_path").setLimit(1_500).setIsNullable(false).build())
996 .addColumn(projectUuidCol)
997 .addColumn(moduleUuidCol)
998 .addColumn(newLenientVarcharBuilder("module_uuid_path").setLimit(1_500).setIsNullable(true).build())
999 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("authorization_updated_at").setIsNullable(true).build())
1000 .addColumn(newVarcharColumnBuilder("tags").setLimit(500).setIsNullable(true).build())
1001 .addColumn(newVarcharColumnBuilder("main_branch_project_uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(true).build())
1002 .addColumn(newBooleanColumnDefBuilder().setColumnName("b_changed").setIsNullable(true).build())
1003 .addColumn(newLenientVarcharBuilder("b_name").setLimit(500).setIsNullable(true).build())
1004 .addColumn(newLenientVarcharBuilder("b_long_name").setLimit(500).setIsNullable(true).build())
1005 .addColumn(newLenientVarcharBuilder("b_description").setLimit(2_000).setIsNullable(true).build())
1006 .addColumn(newBooleanColumnDefBuilder().setColumnName("b_enabled").setIsNullable(true).build())
1007 .addColumn(newLenientVarcharBuilder("b_qualifier").setLimit(10).setIsNullable(true).build())
1008 .addColumn(newLenientVarcharBuilder("b_language").setLimit(20).setIsNullable(true).build())
1009 .addColumn(newLenientVarcharBuilder("b_copy_component_uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(true).build())
1010 .addColumn(newLenientVarcharBuilder("b_path").setLimit(2_000).setIsNullable(true).build())
1011 .addColumn(newLenientVarcharBuilder("b_uuid_path").setLimit(1_500).setIsNullable(true).build())
1012 .addColumn(newLenientVarcharBuilder("b_module_uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(true).build())
1013 .addColumn(newLenientVarcharBuilder("b_module_uuid_path").setLimit(1_500).setIsNullable(true).build())
1014 .addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
1016 addIndex(context, tableName, "projects_organization", false, organizationUuidCol);
1017 addIndex(context, tableName, "projects_kee", true, keeCol);
1018 addIndex(context, tableName, "projects_module_uuid", false, moduleUuidCol);
1019 addIndex(context, tableName, "projects_project_uuid", false, projectUuidCol);
1020 addIndex(context, tableName, "projects_qualifier", false, qualifierCol);
1021 addIndex(context, tableName, "projects_root_uuid", false, rootUuidCol);
1022 // see SONAR-12341, index projects_uuid should actually be unique
1023 addIndex(context, tableName, "projects_uuid", false, uuidCol);
1026 private void createProperties(Context context) {
1027 String tableName = "properties";
1028 VarcharColumnDef propKey = newLenientVarcharBuilder("prop_key").setLimit(512).setIsNullable(false).build();
1029 context.execute(newTableBuilder(tableName)
1030 .addPkColumn(ID_COL, AUTO_INCREMENT)
1032 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build())
1033 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(true).build())
1034 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_empty").setIsNullable(false).build())
1035 .addColumn(newLenientVarcharBuilder("text_value").setLimit(MAX_SIZE).build())
1036 .addColumn(newClobColumnDefBuilder().setColumnName("clob_value").setIsNullable(true).build())
1037 .addColumn(TECHNICAL_CREATED_AT_COL)
1038 // table with be renamed to properties in following migration, use final constraint name right away
1039 .withPkConstraintName("pk_properties")
1041 addIndex(context, tableName, "properties_key", false, propKey);
1044 private void createQProfileChanges(Context context) {
1045 String tableName = "qprofile_changes";
1046 VarcharColumnDef rulesProfileUuidCol = newLenientVarcharBuilder("rules_profile_uuid").setLimit(255).setIsNullable(false).build();
1047 context.execute(newTableBuilder(tableName)
1048 .addPkColumn(newLenientVarcharBuilder("kee").setLimit(UUID_SIZE).setIsNullable(false).build())
1049 .addColumn(rulesProfileUuidCol)
1050 .addColumn(newLenientVarcharBuilder("change_type").setLimit(20).setIsNullable(false).build())
1051 .addColumn(newLenientVarcharBuilder(USER_UUID_COL_NAME).setLimit(255).setIsNullable(true).build())
1052 .addColumn(newClobColumnDefBuilder().setColumnName("change_data").setIsNullable(true).build())
1053 .addColumn(TECHNICAL_CREATED_AT_COL)
1055 addIndex(context, tableName, "qp_changes_rules_profile_uuid", false, rulesProfileUuidCol);
1058 private void createQProfileEditGroups(Context context) {
1059 String tableName = "qprofile_edit_groups";
1060 IntegerColumnDef groupCol = newIntegerColumnDefBuilder().setColumnName("group_id").setIsNullable(false).build();
1061 VarcharColumnDef qProfileUuidCol = newVarcharColumnBuilder("qprofile_uuid").setIsNullable(false).setLimit(255).build();
1062 context.execute(newTableBuilder(tableName)
1063 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
1064 .addColumn(groupCol)
1065 .addColumn(qProfileUuidCol)
1066 .addColumn(TECHNICAL_CREATED_AT_COL)
1068 addIndex(context, tableName, tableName + "_qprofile", false, qProfileUuidCol);
1069 addIndex(context, tableName, tableName + "_unique", true, groupCol, qProfileUuidCol);
1072 private void createQProfileEditUsers(Context context) {
1073 String tableName = "qprofile_edit_users";
1074 IntegerColumnDef userIdCol = newIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(false).build();
1075 VarcharColumnDef qProfileUuidCol = newVarcharColumnBuilder("qprofile_uuid").setIsNullable(false).setLimit(255).build();
1076 context.execute(newTableBuilder(tableName)
1077 .addPkColumn(newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build())
1078 .addColumn(userIdCol)
1079 .addColumn(qProfileUuidCol)
1080 .addColumn(TECHNICAL_CREATED_AT_COL)
1082 addIndex(context, tableName, tableName + "_qprofile", false, qProfileUuidCol);
1083 addIndex(context, tableName, tableName + "_unique", true, userIdCol, qProfileUuidCol);
1086 private void createQualityGateConditions(Context context) {
1088 newTableBuilder("quality_gate_conditions")
1089 .addPkColumn(ID_COL, AUTO_INCREMENT)
1090 .addColumn(newIntegerColumnDefBuilder().setColumnName("qgate_id").setIsNullable(true).build())
1091 .addColumn(newIntegerColumnDefBuilder().setColumnName(METRIC_ID_COL_NAME).setIsNullable(true).build())
1092 .addColumn(newIntegerColumnDefBuilder().setColumnName("period").setIsNullable(true).build())
1093 .addColumn(newLenientVarcharBuilder("operator").setLimit(3).setIsNullable(true).build())
1094 .addColumn(newLenientVarcharBuilder("value_error").setLimit(64).setIsNullable(true).build())
1095 .addColumn(newLenientVarcharBuilder("value_warning").setLimit(64).setIsNullable(true).build())
1096 .addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
1097 .addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
1101 private void createQualityGates(Context context) {
1102 String tableName = "quality_gates";
1103 VarcharColumnDef uuidCol = newVarcharColumnBuilder("uuid").setIsNullable(false).setLimit(UUID_SIZE).build();
1105 newTableBuilder(tableName)
1106 .addPkColumn(ID_COL, AUTO_INCREMENT)
1108 .addColumn(newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build())
1109 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_built_in").setIsNullable(false).build())
1110 .addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
1111 .addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
1113 addIndex(context, tableName, "uniq_quality_gates_uuid", true, uuidCol);
1116 private void createRulesRepository(Context context) {
1117 String tableName = "rule_repositories";
1118 context.execute(newTableBuilder(tableName)
1119 .addPkColumn(newLenientVarcharBuilder("kee").setLimit(200).setIsNullable(false).build())
1120 .addColumn(newLenientVarcharBuilder("language").setLimit(20).setIsNullable(false).build())
1121 .addColumn(newLenientVarcharBuilder("name").setLimit(4_000).setIsNullable(false).build())
1122 .addColumn(TECHNICAL_CREATED_AT_COL)
1126 private void createRules(Context context) {
1127 VarcharColumnDef pluginRuleKeyCol = newLenientVarcharBuilder("plugin_rule_key").setLimit(200).setIsNullable(false).build();
1128 VarcharColumnDef pluginNameCol = newLenientVarcharBuilder("plugin_name").setLimit(255).setIsNullable(false).build();
1130 newTableBuilder("rules")
1131 .addPkColumn(ID_COL, AUTO_INCREMENT)
1132 .addColumn(newLenientVarcharBuilder("name").setLimit(200).setIsNullable(true).build())
1133 .addColumn(pluginRuleKeyCol)
1134 .addColumn(newVarcharColumnBuilder("plugin_key").setLimit(200).setIsNullable(true).build())
1135 .addColumn(newLenientVarcharBuilder("plugin_config_key").setLimit(200).setIsNullable(true).build())
1136 .addColumn(pluginNameCol)
1137 .addColumn(newVarcharColumnBuilder("scope").setLimit(20).setIsNullable(false).build())
1138 .addColumn(newClobColumnDefBuilder().setColumnName(DESCRIPTION_COL_NAME).setIsNullable(true).build())
1139 .addColumn(newIntegerColumnDefBuilder().setColumnName("priority").setIsNullable(true).build())
1140 .addColumn(newIntegerColumnDefBuilder().setColumnName("template_id").setIsNullable(true).build())
1141 .addColumn(newLenientVarcharBuilder("status").setLimit(40).setIsNullable(true).build())
1142 .addColumn(newLenientVarcharBuilder("language").setLimit(20).setIsNullable(true).build())
1143 .addColumn(newLenientVarcharBuilder("def_remediation_function").setLimit(20).setIsNullable(true).build())
1144 .addColumn(newLenientVarcharBuilder("def_remediation_gap_mult").setLimit(20).setIsNullable(true).build())
1145 .addColumn(newLenientVarcharBuilder("def_remediation_base_effort").setLimit(20).setIsNullable(true).build())
1146 .addColumn(newLenientVarcharBuilder("gap_description").setLimit(MAX_SIZE).setIsNullable(true).build())
1147 .addColumn(newLenientVarcharBuilder("system_tags").setLimit(MAX_SIZE).setIsNullable(true).build())
1148 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_template").setIsNullable(false).setDefaultValue(false).build())
1149 .addColumn(newLenientVarcharBuilder("description_format").setLimit(20).setIsNullable(true).build())
1150 .addColumn(new TinyIntColumnDef.Builder().setColumnName("rule_type").setIsNullable(true).build())
1151 .addColumn(newVarcharColumnBuilder("security_standards").setIsNullable(true).setLimit(4_000).build())
1152 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_ad_hoc").setIsNullable(false).build())
1153 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_external").setIsNullable(false).build())
1154 .addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
1155 .addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
1157 addIndex(context, "rules", "rules_repo_key", true, pluginRuleKeyCol, pluginNameCol);
1160 private void createRulesMetadata(Context context) {
1161 String tableName = "rules_metadata";
1162 context.execute(newTableBuilder(tableName)
1163 .addPkColumn(newIntegerColumnDefBuilder().setColumnName("rule_id").setIsNullable(false).build())
1164 .addPkColumn(newVarcharColumnBuilder(ORGANIZATION_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
1165 .addColumn(newClobColumnDefBuilder().setColumnName("note_data").setIsNullable(true).build())
1166 .addColumn(newVarcharColumnBuilder("note_user_uuid").setLimit(255).setIsNullable(true).build())
1167 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("note_created_at").setIsNullable(true).build())
1168 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("note_updated_at").setIsNullable(true).build())
1169 .addColumn(newVarcharColumnBuilder("remediation_function").setLimit(20).setIsNullable(true).build())
1170 .addColumn(newVarcharColumnBuilder("remediation_gap_mult").setLimit(20).setIsNullable(true).build())
1171 .addColumn(newVarcharColumnBuilder("remediation_base_effort").setLimit(20).setIsNullable(true).build())
1172 .addColumn(newVarcharColumnBuilder("tags").setLimit(4_000).setIsNullable(true).build())
1173 .addColumn(newVarcharColumnBuilder("ad_hoc_name").setLimit(200).setIsNullable(true).build())
1174 .addColumn(newClobColumnDefBuilder().setColumnName("ad_hoc_description").setIsNullable(true).build())
1175 .addColumn(newVarcharColumnBuilder("ad_hoc_severity").setLimit(10).setIsNullable(true).build())
1176 .addColumn(newTinyIntColumnDefBuilder().setColumnName("ad_hoc_type").setIsNullable(true).build())
1177 .addColumn(TECHNICAL_CREATED_AT_COL)
1178 .addColumn(TECHNICAL_UPDATED_AT_COL)
1179 .withPkConstraintName("pk_" + tableName)
1183 private void createRulesParameters(Context context) {
1184 String tableName = "rules_parameters";
1185 IntegerColumnDef ruleIdCol = newIntegerColumnDefBuilder().setColumnName("rule_id").setIsNullable(false).build();
1186 VarcharColumnDef nameCol = newLenientVarcharBuilder("name").setLimit(128).setIsNullable(false).build();
1188 newTableBuilder(tableName)
1189 .addPkColumn(ID_COL, AUTO_INCREMENT)
1190 .addColumn(ruleIdCol)
1192 .addColumn(newLenientVarcharBuilder(DESCRIPTION_COL_NAME).setLimit(MAX_SIZE).setIsNullable(true).build())
1193 .addColumn(newLenientVarcharBuilder("param_type").setLimit(512).setIsNullable(false).build())
1194 .addColumn(newLenientVarcharBuilder("default_value").setLimit(MAX_SIZE).setIsNullable(true).build())
1196 addIndex(context, tableName, "rules_parameters_rule_id", false, ruleIdCol);
1197 addIndex(context, tableName, "rules_parameters_unique", true, ruleIdCol, nameCol);
1200 private void createRulesProfiles(Context context) {
1201 VarcharColumnDef keeCol = newLenientVarcharBuilder("kee").setLimit(255).setIsNullable(false).build();
1203 newTableBuilder("rules_profiles")
1204 .addPkColumn(ID_COL, AUTO_INCREMENT)
1205 .addColumn(newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build())
1206 .addColumn(newLenientVarcharBuilder("language").setLimit(20).setIsNullable(true).build())
1208 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_built_in").setIsNullable(false).build())
1209 .addColumn(newLenientVarcharBuilder("rules_updated_at").setLimit(100).setIsNullable(true).build())
1210 .addColumn(DEPRECATED_TECHNICAL_CREATED_AT_COL)
1211 .addColumn(DEPRECATED_TECHNICAL_UPDATED_AT_COL)
1213 addIndex(context, "rules_profiles", "uniq_qprof_key", true, keeCol);
1216 private void createSnapshots(Context context) {
1217 String tableName = "snapshots";
1218 VarcharColumnDef uuidCol = newLenientVarcharBuilder("uuid").setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
1219 VarcharColumnDef componentUuidCol = newLenientVarcharBuilder(COMPONENT_UUID_COL_NAME).setLimit(OLD_UUID_VARCHAR_SIZE).setIsNullable(false).build();
1221 newTableBuilder(tableName)
1222 .addPkColumn(ID_COL, AUTO_INCREMENT)
1224 .addColumn(componentUuidCol)
1225 .addColumn(newLenientVarcharBuilder("status").setLimit(4).setIsNullable(false).setDefaultValue("U").build())
1226 .addColumn(newBooleanColumnDefBuilder().setColumnName("islast").setIsNullable(false).setDefaultValue(false).build())
1227 .addColumn(newLenientVarcharBuilder("version").setLimit(500).setIsNullable(true).build())
1228 .addColumn(newIntegerColumnDefBuilder().setColumnName("purge_status").setIsNullable(true).build())
1229 .addColumn(newVarcharColumnBuilder("build_string").setLimit(100).setIsNullable(true).build())
1230 .addColumn(newVarcharColumnBuilder("revision").setLimit(100).setIsNullable(true).build())
1231 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("build_date").setIsNullable(true).build())
1232 .addColumn(newLenientVarcharBuilder("period1_mode").setLimit(100).setIsNullable(true).build())
1233 .addColumn(newLenientVarcharBuilder("period1_param").setLimit(100).setIsNullable(true).build())
1234 .addColumn(newLenientVarcharBuilder("period2_mode").setLimit(100).setIsNullable(true).build())
1235 .addColumn(newLenientVarcharBuilder("period2_param").setLimit(100).setIsNullable(true).build())
1236 .addColumn(newLenientVarcharBuilder("period3_mode").setLimit(100).setIsNullable(true).build())
1237 .addColumn(newLenientVarcharBuilder("period3_param").setLimit(100).setIsNullable(true).build())
1238 .addColumn(newLenientVarcharBuilder("period4_mode").setLimit(100).setIsNullable(true).build())
1239 .addColumn(newLenientVarcharBuilder("period4_param").setLimit(100).setIsNullable(true).build())
1240 .addColumn(newLenientVarcharBuilder("period5_mode").setLimit(100).setIsNullable(true).build())
1241 .addColumn(newLenientVarcharBuilder("period5_param").setLimit(100).setIsNullable(true).build())
1242 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("period1_date").setIsNullable(true).build())
1243 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("period2_date").setIsNullable(true).build())
1244 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("period3_date").setIsNullable(true).build())
1245 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("period4_date").setIsNullable(true).build())
1246 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("period5_date").setIsNullable(true).build())
1247 .addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
1249 addIndex(context, tableName, "analyses_uuid", true, uuidCol);
1250 addIndex(context, tableName, "snapshot_component", false, componentUuidCol);
1253 private void createUserProperties(Context context) {
1254 String tableName = "user_properties";
1255 VarcharColumnDef userUuidCol = newVarcharColumnBuilder(USER_UUID_COL_NAME).setLimit(255).setIsNullable(false).build();
1256 VarcharColumnDef keyCol = newVarcharColumnBuilder("kee").setLimit(100).setIsNullable(false).build();
1257 context.execute(newTableBuilder(tableName)
1258 .addPkColumn(newVarcharColumnBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
1259 .addColumn(userUuidCol)
1261 .addColumn(newVarcharColumnBuilder("text_value").setLimit(4_000).setIsNullable(false).build())
1262 .addColumn(TECHNICAL_CREATED_AT_COL)
1263 .addColumn(TECHNICAL_UPDATED_AT_COL)
1265 addIndex(context, tableName, "user_properties_user_uuid_kee", true, userUuidCol, keyCol);
1268 private void createUserRoles(Context context) {
1269 String tableName = "user_roles";
1270 IntegerColumnDef userIdCol = newIntegerColumnDefBuilder().setColumnName("user_id").setIsNullable(true).build();
1271 IntegerColumnDef resourceIdCol = newIntegerColumnDefBuilder().setColumnName("resource_id").setIsNullable(true).build();
1273 newTableBuilder(tableName)
1274 .addPkColumn(ID_COL, AUTO_INCREMENT)
1275 .addColumn(newLenientVarcharBuilder(ORGANIZATION_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build())
1276 .addColumn(userIdCol)
1277 .addColumn(resourceIdCol)
1278 .addColumn(newLenientVarcharBuilder("role").setLimit(64).setIsNullable(false).build())
1280 addIndex(context, tableName, "user_roles_resource", false, resourceIdCol);
1281 addIndex(context, tableName, "user_roles_user", false, userIdCol);
1284 private void createUserTokens(Context context) {
1285 String tableName = "user_tokens";
1286 VarcharColumnDef userUuidCol = newVarcharColumnBuilder(USER_UUID_COL_NAME).setLimit(255).setIsNullable(false).build();
1287 VarcharColumnDef nameCol = newVarcharColumnBuilder("name").setLimit(100).setIsNullable(false).build();
1288 VarcharColumnDef tokenHashCol = newVarcharColumnBuilder("token_hash").setLimit(255).setIsNullable(false).build();
1290 newTableBuilder(tableName)
1291 .addPkColumn(ID_COL, AUTO_INCREMENT)
1292 .addColumn(userUuidCol)
1294 .addColumn(tokenHashCol)
1295 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_connection_date").setIsNullable(true).build())
1296 .addColumn(TECHNICAL_CREATED_AT_COL)
1298 addIndex(context, tableName, "user_tokens_user_uuid_name", true, userUuidCol, nameCol);
1299 addIndex(context, tableName, "user_tokens_token_hash", true, tokenHashCol);
1302 private void createUsers(Context context) {
1303 String tableName = "users";
1304 VarcharColumnDef uuidCol = newVarcharColumnBuilder("uuid").setLimit(255).setIsNullable(false).build();
1305 VarcharColumnDef loginCol = newLenientVarcharBuilder("login").setLimit(255).setIsNullable(false).build();
1306 BigIntegerColumnDef updatedAtCol = NULLABLE_TECHNICAL_UPDATED_AT_COL;
1307 VarcharColumnDef externalLoginCol = newLenientVarcharBuilder("external_login").setLimit(255).setIsNullable(false).build();
1308 VarcharColumnDef externalIdentityProviderCol = newLenientVarcharBuilder("external_identity_provider").setLimit(100).setIsNullable(false).build();
1309 VarcharColumnDef externalIdCol = newVarcharColumnBuilder("external_id").setLimit(255).setIsNullable(false).build();
1311 newTableBuilder(tableName)
1312 .addPkColumn(ID_COL, AUTO_INCREMENT)
1314 .addColumn(loginCol)
1315 .addColumn(newVarcharColumnBuilder(ORGANIZATION_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build())
1316 .addColumn(newLenientVarcharBuilder("name").setLimit(200).setIsNullable(true).build())
1317 .addColumn(newLenientVarcharBuilder("email").setLimit(100).setIsNullable(true).build())
1318 .addColumn(newLenientVarcharBuilder("crypted_password").setLimit(100).setIsNullable(true).build())
1319 .addColumn(newLenientVarcharBuilder("salt").setLimit(40).setIsNullable(true).build())
1320 .addColumn(newVarcharColumnBuilder("hash_method").setLimit(10).setIsNullable(true).build())
1321 .addColumn(newBooleanColumnDefBuilder().setColumnName("active").setDefaultValue(true).setIsNullable(true).build())
1322 .addColumn(newLenientVarcharBuilder("scm_accounts").setLimit(MAX_SIZE).build())
1323 .addColumn(externalLoginCol)
1324 .addColumn(externalIdentityProviderCol)
1325 .addColumn(externalIdCol)
1326 .addColumn(newBooleanColumnDefBuilder().setColumnName("is_root").setIsNullable(false).build())
1327 .addColumn(newBooleanColumnDefBuilder().setColumnName("user_local").setIsNullable(true).build())
1328 .addColumn(newBooleanColumnDefBuilder().setColumnName("onboarded").setIsNullable(false).build())
1329 .addColumn(newVarcharColumnBuilder("homepage_type").setLimit(40).setIsNullable(true).build())
1330 .addColumn(newVarcharColumnBuilder("homepage_parameter").setLimit(40).setIsNullable(true).build())
1331 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("last_connection_date").setIsNullable(true).build())
1332 .addColumn(NULLABLE_TECHNICAL_CREATED_AT_COL)
1333 .addColumn(updatedAtCol)
1335 addIndex(context, tableName, "users_login", true, loginCol);
1336 addIndex(context, tableName, "users_updated_at", false, updatedAtCol);
1337 addIndex(context, tableName, "users_uuid", true, uuidCol);
1338 addIndex(context, tableName, "uniq_external_id", true, externalIdentityProviderCol, externalIdCol);
1339 addIndex(context, tableName, "uniq_external_login", true, externalIdentityProviderCol, externalLoginCol);
1342 private void createWebhookDeliveries(Context context) {
1343 String tableName = "webhook_deliveries";
1344 VarcharColumnDef componentUuidColumn = newLenientVarcharBuilder(COMPONENT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(false).build();
1345 VarcharColumnDef ceTaskUuidColumn = newLenientVarcharBuilder("ce_task_uuid").setLimit(UUID_SIZE).setIsNullable(true).build();
1346 context.execute(newTableBuilder(tableName)
1347 .addPkColumn(newLenientVarcharBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
1348 .addColumn(newVarcharColumnBuilder("webhook_uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
1349 .addColumn(componentUuidColumn)
1350 .addColumn(ceTaskUuidColumn)
1351 .addColumn(newVarcharColumnBuilder(ANALYSIS_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build())
1352 .addColumn(newLenientVarcharBuilder("name").setLimit(100).setIsNullable(false).build())
1353 .addColumn(newLenientVarcharBuilder("url").setLimit(2_000).setIsNullable(false).build())
1354 .addColumn(newBooleanColumnDefBuilder().setColumnName("success").setIsNullable(false).build())
1355 .addColumn(newIntegerColumnDefBuilder().setColumnName("http_status").setIsNullable(true).build())
1356 .addColumn(newBigIntegerColumnDefBuilder().setColumnName("duration_ms").setIsNullable(false).build())
1357 .addColumn(newClobColumnDefBuilder().setColumnName("payload").setIsNullable(false).build())
1358 .addColumn(newClobColumnDefBuilder().setColumnName("error_stacktrace").setIsNullable(true).build())
1359 .addColumn(TECHNICAL_CREATED_AT_COL)
1361 addIndex(context, tableName, COMPONENT_UUID_COL_NAME, false, componentUuidColumn);
1362 addIndex(context, tableName, "ce_task_uuid", false, ceTaskUuidColumn);
1365 private void createWebhooks(Context context) {
1366 String tableName = "webhooks";
1367 VarcharColumnDef organizationUuidCol = newVarcharColumnBuilder(ORGANIZATION_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
1368 VarcharColumnDef projectUuidCol = newVarcharColumnBuilder(PROJECT_UUID_COL_NAME).setLimit(UUID_SIZE).setIsNullable(true).build();
1369 context.execute(newTableBuilder(tableName)
1370 .addPkColumn(newVarcharColumnBuilder("uuid").setLimit(UUID_SIZE).setIsNullable(false).build())
1371 .addColumn(organizationUuidCol)
1372 .addColumn(projectUuidCol)
1373 .addColumn(newVarcharColumnBuilder("name").setLimit(100).setIsNullable(false).build())
1374 .addColumn(newVarcharColumnBuilder("url").setLimit(2_000).setIsNullable(false).build())
1375 .addColumn(newVarcharColumnBuilder("secret").setLimit(200).setIsNullable(true).build())
1376 .addColumn(TECHNICAL_CREATED_AT_COL)
1377 .addColumn(NULLABLE_TECHNICAL_UPDATED_AT_COL)
1379 addIndex(context, tableName, "organization_webhook", false, organizationUuidCol);
1380 addIndex(context, tableName, "project_webhook", false, projectUuidCol);
1383 private static void addIndex(Context context, String table, String index, boolean unique, ColumnDef firstColumn, ColumnDef... otherColumns) {
1384 CreateIndexBuilder builder = new CreateIndexBuilder()
1388 concat(of(firstColumn), stream(otherColumns)).forEach(builder::addColumn);
1389 context.execute(builder.build());
1392 private static VarcharColumnDef.Builder newLenientVarcharBuilder(String column) {
1393 return new VarcharColumnDef.Builder().setColumnName(column).setIgnoreOracleUnit(true);
1396 private static VarcharColumnDef.Builder newVarcharColumnBuilder(String column) {
1397 return newVarcharColumnDefBuilder().setColumnName(column);
1400 private CreateTableBuilder newTableBuilder(String tableName) {
1401 return new CreateTableBuilder(getDialect(), tableName);