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.v80;
22 import java.sql.Connection;
23 import java.sql.SQLException;
24 import org.sonar.db.Database;
25 import org.sonar.db.DatabaseUtils;
26 import org.sonar.server.platform.db.migration.def.BigIntegerColumnDef;
27 import org.sonar.server.platform.db.migration.def.VarcharColumnDef;
28 import org.sonar.server.platform.db.migration.sql.CreateTableBuilder;
29 import org.sonar.server.platform.db.migration.step.DdlChange;
31 import static org.sonar.server.platform.db.migration.def.BigIntegerColumnDef.newBigIntegerColumnDefBuilder;
32 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.UUID_SIZE;
33 import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder;
36 public class CreateNewCodePeriodTable extends DdlChange {
38 private static final String TABLE_NAME = "new_code_periods";
40 private static final VarcharColumnDef UUID_COLUMN = newVarcharColumnDefBuilder()
41 .setColumnName("uuid")
46 private static final VarcharColumnDef PROJECT_UUID_COLUMN = newVarcharColumnDefBuilder()
47 .setColumnName("project_uuid")
51 private static final VarcharColumnDef BRANCH_UUID_COLUMN = newVarcharColumnDefBuilder()
52 .setColumnName("branch_uuid")
64 private static final VarcharColumnDef TYPE = newVarcharColumnDefBuilder()
65 .setColumnName("type")
70 private static final VarcharColumnDef VALUE = newVarcharColumnDefBuilder()
71 .setColumnName("value")
76 private static final BigIntegerColumnDef UPDATED_AT = newBigIntegerColumnDefBuilder()
77 .setColumnName("updated_at")
81 private static final BigIntegerColumnDef CREATED_AT = newBigIntegerColumnDefBuilder()
82 .setColumnName("created_at")
87 public CreateNewCodePeriodTable(Database db) {
92 public void execute(Context context) throws SQLException {
96 context.execute(new CreateTableBuilder(getDialect(), TABLE_NAME)
97 .addPkColumn(UUID_COLUMN)
98 .addColumn(PROJECT_UUID_COLUMN)
99 .addColumn(BRANCH_UUID_COLUMN)
102 .addColumn(UPDATED_AT)
103 .addColumn(CREATED_AT)
107 private boolean tableExists() throws SQLException {
108 try (Connection connection = getDatabase().getDataSource().getConnection()) {
109 return DatabaseUtils.tableExists(TABLE_NAME, connection);