mirror of
https://github.com/osm2pgsql-dev/osm2pgsql.git
synced 2025-08-16 15:04:27 +00:00
Merge pull request #1875 from joto/earlier-db-compat-checks
Earlier database compatibility checks
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
|
||||
#include "flex-table-column.hpp"
|
||||
#include "format.hpp"
|
||||
#include "pgsql-capabilities.hpp"
|
||||
#include "util.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@ -82,7 +83,14 @@ flex_table_column_t::flex_table_column_t(std::string name,
|
||||
: m_name(std::move(name)), m_type_name(lowercase(type)),
|
||||
m_sql_type(std::move(sql_type)),
|
||||
m_type(get_column_type_from_string(m_type_name))
|
||||
{}
|
||||
{
|
||||
if (m_type == table_column_type::hstore) {
|
||||
if (!has_extension("hstore")) {
|
||||
throw std::runtime_error{"Extension 'hstore' not available. Use "
|
||||
"'CREATE EXTENSION hstore;' to load it."};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void flex_table_column_t::set_projection(char const *projection)
|
||||
{
|
||||
|
@ -74,14 +74,6 @@ bool flex_table_t::has_id_column() const noexcept
|
||||
(m_columns[0].type() == table_column_type::id_num);
|
||||
}
|
||||
|
||||
bool flex_table_t::has_hstore_column() const noexcept
|
||||
{
|
||||
auto const it = std::find_if(begin(), end(), [&](auto const &column) {
|
||||
return column.type() == table_column_type::hstore;
|
||||
});
|
||||
return it != end();
|
||||
}
|
||||
|
||||
bool flex_table_t::matches_type(osmium::item_type type) const noexcept
|
||||
{
|
||||
// This table takes any type -> okay
|
||||
@ -261,29 +253,6 @@ void table_connection_t::start(bool append)
|
||||
{
|
||||
assert(m_db_connection);
|
||||
|
||||
if (!has_schema(table().schema())) {
|
||||
throw fmt_error("Schema '{0}' not available."
|
||||
" Use 'CREATE SCHEMA \"{0}\";' to create it.",
|
||||
table().schema());
|
||||
}
|
||||
|
||||
for (auto const &ts :
|
||||
{table().data_tablespace(), table().index_tablespace()}) {
|
||||
if (!has_tablespace(ts)) {
|
||||
throw fmt_error(
|
||||
"Tablespace '{0}' not available."
|
||||
" Use 'CREATE TABLESPACE \"{0}\" ...;' to create it.",
|
||||
ts);
|
||||
}
|
||||
}
|
||||
|
||||
if (table().has_hstore_column()) {
|
||||
if (!has_extension("hstore")) {
|
||||
throw std::runtime_error{"Extension 'hstore' not available. Use "
|
||||
"'CREATE EXTENSION hstore;' to load it."};
|
||||
}
|
||||
}
|
||||
|
||||
m_db_connection->exec("SET client_min_messages = WARNING");
|
||||
|
||||
if (!append) {
|
||||
|
@ -64,21 +64,24 @@ public:
|
||||
return m_index_tablespace;
|
||||
}
|
||||
|
||||
void set_schema(std::string const &schema) noexcept { m_schema = schema; }
|
||||
void set_schema(std::string schema) noexcept
|
||||
{
|
||||
m_schema = std::move(schema);
|
||||
}
|
||||
|
||||
void set_cluster_by_geom(bool cluster) noexcept
|
||||
{
|
||||
m_cluster_by_geom = cluster;
|
||||
}
|
||||
|
||||
void set_data_tablespace(std::string const &tablespace) noexcept
|
||||
void set_data_tablespace(std::string tablespace) noexcept
|
||||
{
|
||||
m_data_tablespace = tablespace;
|
||||
m_data_tablespace = std::move(tablespace);
|
||||
}
|
||||
|
||||
void set_index_tablespace(std::string const &tablespace) noexcept
|
||||
void set_index_tablespace(std::string tablespace) noexcept
|
||||
{
|
||||
m_index_tablespace = tablespace;
|
||||
m_index_tablespace = std::move(tablespace);
|
||||
}
|
||||
|
||||
osmium::item_type id_type() const noexcept { return m_id_type; }
|
||||
@ -104,8 +107,6 @@ public:
|
||||
return m_geom_column != std::numeric_limits<std::size_t>::max();
|
||||
}
|
||||
|
||||
bool has_hstore_column() const noexcept;
|
||||
|
||||
/// Get the (first, if there are multiple) geometry column.
|
||||
flex_table_column_t const &geom_column() const noexcept
|
||||
{
|
||||
|
@ -434,6 +434,16 @@ int output_flex_t::app_as_geometrycollection()
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void check_tablespace(std::string const &tablespace)
|
||||
{
|
||||
if (!has_tablespace(tablespace)) {
|
||||
throw fmt_error(
|
||||
"Tablespace '{0}' not available."
|
||||
" Use 'CREATE TABLESPACE \"{0}\" ...;' to create it.",
|
||||
tablespace);
|
||||
}
|
||||
}
|
||||
|
||||
flex_table_t &output_flex_t::create_flex_table()
|
||||
{
|
||||
std::string const table_name =
|
||||
@ -455,6 +465,11 @@ flex_table_t &output_flex_t::create_flex_table()
|
||||
if (lua_isstring(lua_state(), -1)) {
|
||||
std::string const schema = lua_tostring(lua_state(), -1);
|
||||
check_identifier(schema, "schema field");
|
||||
if (!has_schema(schema)) {
|
||||
throw fmt_error("Schema '{0}' not available."
|
||||
" Use 'CREATE SCHEMA \"{0}\";' to create it.",
|
||||
schema);
|
||||
}
|
||||
new_table.set_schema(schema);
|
||||
}
|
||||
lua_pop(lua_state(), 1);
|
||||
@ -486,6 +501,7 @@ flex_table_t &output_flex_t::create_flex_table()
|
||||
if (lua_isstring(lua_state(), -1)) {
|
||||
std::string const tablespace = lua_tostring(lua_state(), -1);
|
||||
check_identifier(tablespace, "data_tablespace field");
|
||||
check_tablespace(tablespace);
|
||||
new_table.set_data_tablespace(tablespace);
|
||||
}
|
||||
lua_pop(lua_state(), 1);
|
||||
@ -495,6 +511,7 @@ flex_table_t &output_flex_t::create_flex_table()
|
||||
if (lua_isstring(lua_state(), -1)) {
|
||||
std::string const tablespace = lua_tostring(lua_state(), -1);
|
||||
check_identifier(tablespace, "index_tablespace field");
|
||||
check_tablespace(tablespace);
|
||||
new_table.set_index_tablespace(tablespace);
|
||||
}
|
||||
lua_pop(lua_state(), 1);
|
||||
|
Reference in New Issue
Block a user