]> source.dussan.org Git - sonarqube.git/blob
6ca3cb8ffead4289755b88782f0b37f325ede78c
[sonarqube.git] /
1 /*
2  * SonarQube
3  * Copyright (C) 2009-2024 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.v00;
21
22 import java.sql.Connection;
23 import java.sql.ResultSet;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.Locale;
27 import java.util.Set;
28 import org.junit.Rule;
29 import org.junit.Test;
30 import org.sonar.db.MigrationDbTester;
31
32 import static org.assertj.core.api.Assertions.assertThat;
33
34 public class CreateInitialSchemaIT {
35
36   private static final Set<String> SCHEMAS_TO_IGNORE = Set.of("INFORMATION_SCHEMA", "sys", "SYS", "SYSTEM", "CTXSYS", "MDSYS", "XDB");
37
38   @Rule
39   public final MigrationDbTester dbTester = MigrationDbTester.createForMigrationStep(CreateInitialSchema.class);
40
41   private final CreateInitialSchema underTest = new CreateInitialSchema(dbTester.database());
42
43   @Test
44   public void creates_tables_on_empty_db() throws Exception {
45     underTest.execute();
46
47     List<String> tables = new ArrayList<>();
48     try (Connection connection = dbTester.openConnection();
49          ResultSet rs = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"})) {
50
51       while (rs.next()) {
52         String schema = rs.getString("TABLE_SCHEM");
53         if (!SCHEMAS_TO_IGNORE.contains(schema)) {
54           tables.add(rs.getString("TABLE_NAME").toLowerCase(Locale.ENGLISH));
55         }
56       }
57     }
58
59     assertThat(tables)
60       .containsOnly(
61         "active_rules",
62         "active_rule_parameters",
63         "app_branch_project_branch",
64         "alm_pats",
65         "app_projects",
66         "alm_settings",
67         "audits",
68         "project_alm_settings",
69         "analysis_properties",
70         "ce_activity",
71         "ce_queue",
72         "ce_scanner_context",
73         "ce_task_characteristics",
74         "ce_task_input",
75         "ce_task_message",
76         "components",
77         "default_qprofiles",
78         "deprecated_rule_keys",
79         "duplications_index",
80         "es_queue",
81         "events",
82         "event_component_changes",
83         "file_sources",
84         "groups",
85         "groups_users",
86         "group_roles",
87         "internal_component_props",
88         "internal_properties",
89         "issues",
90         "issue_changes",
91         "live_measures",
92         "metrics",
93         "new_code_periods",
94         "new_code_reference_issues",
95         "notifications",
96         "org_qprofiles",
97         "permission_templates",
98         "perm_templates_groups",
99         "perm_templates_users",
100         "perm_tpl_characteristics",
101         "plugins",
102         "portfolios",
103         "portfolio_projects",
104         "portfolio_proj_branches",
105         "portfolio_references",
106         "projects",
107         "project_badge_token",
108         "project_branches",
109         "project_links",
110         "project_mappings",
111         "project_measures",
112         "project_qprofiles",
113         "project_qgates",
114         "properties",
115         "push_events",
116         "qgate_group_permissions",
117         "qgate_user_permissions",
118         "qprofile_changes",
119         "qprofile_edit_groups",
120         "qprofile_edit_users",
121         "quality_gates",
122         "quality_gate_conditions",
123         "rules",
124         "rules_parameters",
125         "rules_profiles",
126         "rule_repositories",
127         "rule_desc_sections",
128         "saml_message_ids",
129         "scanner_analysis_cache",
130         "schema_migrations",
131         "scim_users",
132         "session_tokens",
133         "snapshots",
134         "users",
135         "user_dismissed_messages",
136         "user_roles",
137         "user_tokens",
138         "webhooks",
139         "webhook_deliveries");
140   }
141
142 }