@@ -30,14 +30,11 @@ table_t::table_t(std::string const &name, std::string type, columns_t columns,
3030 hstore_column hstore_mode,
3131 std::shared_ptr<db_copy_thread_t > const ©_thread,
3232 std::string const &schema)
33- : m_target(std::make_shared<db_target_descr_t >(name.c_str() , " osm_id" )),
33+ : m_target(std::make_shared<db_target_descr_t >(schema, name, " osm_id" )),
3434 m_type (std::move(type)), m_srid(fmt::to_string(srid)), m_append(append),
3535 m_hstore_mode(hstore_mode), m_columns(std::move(columns)),
3636 m_hstore_columns(std::move(hstore_columns)), m_copy(copy_thread)
3737{
38- assert (!schema.empty ());
39- m_target->schema = schema;
40-
4138 // if we dont have any columns
4239 if (m_columns.empty () && m_hstore_mode != hstore_column::all) {
4340 throw fmt_error (" No columns provided for table {}." , name);
@@ -78,17 +75,17 @@ void table_t::start(std::string const &conninfo, std::string const &table_space)
7875{
7976 if (m_sql_conn) {
8077 throw fmt_error (" {} cannot start, its already started." ,
81- m_target->name );
78+ m_target->name () );
8279 }
8380
8481 m_conninfo = conninfo;
8582 m_table_space = tablespace_clause (table_space);
8683
8784 connect ();
88- log_info (" Setting up table '{}'" , m_target->name );
89- auto const qual_name = qualified_name (m_target->schema , m_target->name );
90- auto const qual_tmp_name = qualified_name (
91- m_target->schema , m_target->name + " _tmp" );
85+ log_info (" Setting up table '{}'" , m_target->name () );
86+ auto const qual_name = qualified_name (m_target->schema () , m_target->name () );
87+ auto const qual_tmp_name =
88+ qualified_name ( m_target->schema () , m_target->name () + " _tmp" );
9289
9390 // we are making a new table
9491 if (!m_append) {
@@ -135,8 +132,8 @@ void table_t::start(std::string const &conninfo, std::string const &table_space)
135132 m_sql_conn->exec (sql);
136133
137134 if (m_srid != " 4326" ) {
138- create_geom_check_trigger (m_sql_conn.get (), m_target->schema ,
139- m_target->name , " ST_IsValid(NEW.way)" );
135+ create_geom_check_trigger (m_sql_conn.get (), m_target->schema () ,
136+ m_target->name () , " ST_IsValid(NEW.way)" );
140137 }
141138 }
142139
@@ -146,7 +143,7 @@ void table_t::start(std::string const &conninfo, std::string const &table_space)
146143void table_t::prepare ()
147144{
148145 // let postgres cache this query as it will presumably happen a lot
149- auto const qual_name = qualified_name (m_target->schema , m_target->name );
146+ auto const qual_name = qualified_name (m_target->schema () , m_target->name () );
150147 m_sql_conn->exec (" PREPARE get_wkb(int8) AS"
151148 " SELECT way FROM {} WHERE osm_id = $1" ,
152149 qual_name);
@@ -176,7 +173,7 @@ void table_t::generate_copy_column_list()
176173 // add geom column
177174 joiner.add (" way" );
178175
179- m_target->rows = joiner ();
176+ m_target->set_rows ( joiner () );
180177}
181178
182179void table_t::stop (bool updateable, bool enable_hstore_index,
@@ -185,17 +182,17 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
185182 // make sure that all data is written to the DB before continuing
186183 m_copy.sync ();
187184
188- auto const qual_name = qualified_name (m_target->schema , m_target->name );
189- auto const qual_tmp_name = qualified_name (
190- m_target->schema , m_target->name + " _tmp" );
185+ auto const qual_name = qualified_name (m_target->schema () , m_target->name () );
186+ auto const qual_tmp_name =
187+ qualified_name ( m_target->schema () , m_target->name () + " _tmp" );
191188
192189 if (!m_append) {
193190 if (m_srid != " 4326" ) {
194- drop_geom_check_trigger (m_sql_conn.get (), m_target->schema ,
195- m_target->name );
191+ drop_geom_check_trigger (m_sql_conn.get (), m_target->schema () ,
192+ m_target->name () );
196193 }
197194
198- log_info (" Clustering table '{}' by geometry..." , m_target->name );
195+ log_info (" Clustering table '{}' by geometry..." , m_target->name () );
199196
200197 std::string sql = fmt::format (" CREATE TABLE {} {} AS SELECT * FROM {}" ,
201198 qual_tmp_name, m_table_space, qual_name);
@@ -205,7 +202,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
205202 sql += " ORDER BY " ;
206203 if (postgis_version.major == 2 && postgis_version.minor < 4 ) {
207204 log_debug (" Using GeoHash for clustering table '{}'" ,
208- m_target->name );
205+ m_target->name () );
209206 if (m_srid == " 4326" ) {
210207 sql += " ST_GeoHash(way,10)" ;
211208 } else {
@@ -214,7 +211,7 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
214211 sql += " COLLATE \" C\" " ;
215212 } else {
216213 log_debug (" Using native order for clustering table '{}'" ,
217- m_target->name );
214+ m_target->name () );
218215 // Since Postgis 2.4 the order function for geometries gives
219216 // useful results.
220217 sql += " way" ;
@@ -224,9 +221,9 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
224221
225222 m_sql_conn->exec (" DROP TABLE {}" , qual_name);
226223 m_sql_conn->exec (R"( ALTER TABLE {} RENAME TO "{}")" , qual_tmp_name,
227- m_target->name );
224+ m_target->name () );
228225
229- log_info (" Creating geometry index on table '{}'..." , m_target->name );
226+ log_info (" Creating geometry index on table '{}'..." , m_target->name () );
230227
231228 // Use fillfactor 100 for un-updatable imports
232229 m_sql_conn->exec (" CREATE INDEX ON {} USING GIST (way) {} {}" , qual_name,
@@ -235,20 +232,21 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
235232
236233 /* slim mode needs this to be able to apply diffs */
237234 if (updateable) {
238- log_info (" Creating osm_id index on table '{}'..." , m_target->name );
235+ log_info (" Creating osm_id index on table '{}'..." ,
236+ m_target->name ());
239237 m_sql_conn->exec (" CREATE INDEX ON {} USING BTREE (osm_id) {}" ,
240238 qual_name, tablespace_clause (table_space_index));
241239 if (m_srid != " 4326" ) {
242- create_geom_check_trigger (m_sql_conn.get (), m_target->schema ,
243- m_target->name ,
240+ create_geom_check_trigger (m_sql_conn.get (), m_target->schema () ,
241+ m_target->name () ,
244242 " ST_IsValid(NEW.way)" );
245243 }
246244 }
247245
248246 /* Create hstore index if selected */
249247 if (enable_hstore_index) {
250248 log_info (" Creating hstore indexes on table '{}'..." ,
251- m_target->name );
249+ m_target->name () );
252250 if (m_hstore_mode != hstore_column::none) {
253251 m_sql_conn->exec (" CREATE INDEX ON {} USING GIN (tags) {}" ,
254252 qual_name,
@@ -260,8 +258,8 @@ void table_t::stop(bool updateable, bool enable_hstore_index,
260258 tablespace_clause (table_space_index));
261259 }
262260 }
263- log_info (" Analyzing table '{}'..." , m_target->name );
264- analyze_table (*m_sql_conn, m_target->schema , m_target->name );
261+ log_info (" Analyzing table '{}'..." , m_target->name () );
262+ analyze_table (*m_sql_conn, m_target->schema () , m_target->name () );
265263 }
266264 teardown ();
267265}
@@ -372,7 +370,7 @@ void table_t::write_hstore_columns(taglist_t const &tags)
372370void table_t::task_wait ()
373371{
374372 auto const run_time = m_task_result.wait ();
375- log_info (" All postprocessing on table '{}' done in {}." , m_target->name ,
373+ log_info (" All postprocessing on table '{}' done in {}." , m_target->name () ,
376374 util::human_readable_duration (run_time));
377375}
378376
0 commit comments