3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.server.platform.db.migration.history;
22 import java.sql.Connection;
23 import java.sql.SQLException;
24 import java.sql.Statement;
25 import java.sql.Types;
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.sonar.db.dialect.MsSql;
29 import org.sonar.db.MigrationDbTester;
31 import static org.assertj.core.api.Assertions.assertThat;
33 public class MigrationHistoryTableImplIT {
34 private static final String TABLE_SCHEMA_MIGRATIONS = "schema_migrations";
37 public MigrationDbTester dbTester = MigrationDbTester.createEmpty();
39 private MigrationHistoryTableImpl underTest = new MigrationHistoryTableImpl(dbTester.database());
42 public void start_creates_table_on_empty_schema() {
49 public void start_does_not_fail_if_table_exists() throws SQLException {
50 executeDdl(String.format("create table %s (version %s(255) not null)", TABLE_SCHEMA_MIGRATIONS, getFieldType()));
58 private String getFieldType() {
59 if (dbTester.database().getDialect().getId().equals(MsSql.ID)) {
65 private void executeDdl(String sql) throws SQLException {
66 try (Connection connection = dbTester.database().getDataSource().getConnection()) {
67 connection.setAutoCommit(false);
68 try (Statement statement = connection.createStatement()) {
69 statement.execute(sql);
75 private void verifyTable() {
76 assertThat(dbTester.countRowsOfTable(TABLE_SCHEMA_MIGRATIONS)).isZero();
77 dbTester.assertColumnDefinition(TABLE_SCHEMA_MIGRATIONS, "version", Types.VARCHAR, 255, false);