Skip to content

Commit eff5b95

Browse files
authored
Merge pull request #1843 from joto/refactor-db-capabilities
Consolidate database capability checks
2 parents 7205422 + cdc523d commit eff5b95

18 files changed

+242
-218
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,15 @@ jobs:
3939
env:
4040
PGHOST: /tmp
4141

42-
43-
ubuntu18-pg95-gcc7-jit:
42+
ubuntu18-pg96-gcc7-jit:
4443
runs-on: ubuntu-18.04
4544

4645
env:
4746
CC: gcc-7
4847
CXX: g++-7
4948
LUA_VERSION: 5.3
5049
LUAJIT_OPTION: ON
51-
POSTGRESQL_VERSION: 9.5
50+
POSTGRESQL_VERSION: 9.6
5251
POSTGIS_VERSION: 2.4
5352
BUILD_TYPE: Release
5453

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ if (NOT WIN32 AND NOT APPLE)
6666
set(PostgreSQL_TYPE_INCLUDE_DIR /usr/include)
6767
endif()
6868

69-
set(MINIMUM_POSTGRESQL_SERVER_VERSION "9.5")
70-
set(MINIMUM_POSTGRESQL_SERVER_VERSION_NUM "90500")
69+
set(MINIMUM_POSTGRESQL_SERVER_VERSION "9.6")
70+
set(MINIMUM_POSTGRESQL_SERVER_VERSION_NUM "90600")
7171

72-
set(PostgreSQL_ADDITIONAL_VERSIONS "14" "13" "12" "11" "10" "9.6" "9.5")
72+
set(PostgreSQL_ADDITIONAL_VERSIONS "15" "14" "13" "12" "11" "10" "9.6")
7373

7474
#############################################################
7575
# Version

src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
add_library(osm2pgsql_lib STATIC)
33

44
target_sources(osm2pgsql_lib PRIVATE
5-
db-check.cpp
65
db-copy.cpp
76
dependency-manager.cpp
87
expire-tiles.cpp

src/db-check.cpp

Lines changed: 0 additions & 79 deletions
This file was deleted.

src/db-check.hpp

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/flex-table.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void table_connection_t::start(bool append)
255255
{
256256
assert(m_db_connection);
257257

258-
if (!has_schema(*m_db_connection, table().schema())) {
258+
if (!has_schema(table().schema())) {
259259
throw std::runtime_error{
260260
"Schema '{0}' not available. "
261261
"Use 'CREATE SCHEMA \"{0}\";' to create it."_format(
@@ -264,7 +264,7 @@ void table_connection_t::start(bool append)
264264

265265
for (auto const &ts :
266266
{table().data_tablespace(), table().index_tablespace()}) {
267-
if (!has_tablespace(*m_db_connection, ts)) {
267+
if (!has_tablespace(ts)) {
268268
throw std::runtime_error{
269269
"Tablespace '{0}' not available. "
270270
"Use 'CREATE TABLESPACE \"{0}\" ...;' to create it."_format(
@@ -273,7 +273,7 @@ void table_connection_t::start(bool append)
273273
}
274274

275275
if (table().has_hstore_column()) {
276-
if (!has_extension(*m_db_connection, "hstore")) {
276+
if (!has_extension("hstore")) {
277277
throw std::runtime_error{"Extension 'hstore' not available. Use "
278278
"'CREATE EXTENSION hstore;' to load it."};
279279
}
@@ -333,7 +333,7 @@ void table_connection_t::stop(bool updateable, bool append)
333333
std::string sql = "INSERT INTO {} ({}) SELECT {} FROM {}"_format(
334334
table().full_tmp_name(), columns, columns, table().full_name());
335335

336-
auto const postgis_version = get_postgis_version(*m_db_connection);
336+
auto const postgis_version = get_postgis_version();
337337

338338
sql += " ORDER BY ";
339339
if (postgis_version.major == 2 && postgis_version.minor < 4) {

src/osm2pgsql.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77
* For a full list of authors see the git log.
88
*/
99

10-
#include "db-check.hpp"
1110
#include "dependency-manager.hpp"
1211
#include "input.hpp"
1312
#include "logging.hpp"
1413
#include "middle.hpp"
1514
#include "options.hpp"
1615
#include "osmdata.hpp"
1716
#include "output.hpp"
17+
#include "pgsql.hpp"
18+
#include "pgsql-capabilities.hpp"
19+
#include "pgsql-helper.hpp"
1820
#include "util.hpp"
1921
#include "version.hpp"
2022

@@ -76,6 +78,26 @@ static void run(options_t const &options)
7678
osmdata.stop();
7779
}
7880

81+
void check_db(options_t const &options)
82+
{
83+
pg_conn_t db_connection{options.conninfo};
84+
85+
init_database_capabilities(db_connection);
86+
87+
// If we are in append mode and the middle nodes table isn't there,
88+
// it probably means we used a flat node store when we created this
89+
// database. Check for that and stop if it looks like we are missing
90+
// the node location store option.
91+
if (options.append && options.flat_node_file.empty()) {
92+
if (!has_table(db_connection, options.middle_dbschema,
93+
options.prefix + "_nodes")) {
94+
throw std::runtime_error{
95+
"You seem to not have a nodes table. Did "
96+
"you forget the --flat-nodes option?"};
97+
}
98+
}
99+
}
100+
79101
int main(int argc, char *argv[])
80102
{
81103
try {

0 commit comments

Comments
 (0)