Skip to content

Commit 6e870e5

Browse files
chore(core) final push in the pg-move (#2192)
This is the final push in the postgres move to core. For the function/table resolver, this needs a bit of an refactoring before these would be publicly usefull. I am clasifying them as "configuration"-stuff and moving them to the config-file area. I am not sure if this is the final resting place, but for now this seems an OK place to push this to. This PR also fixes two unrelated issues: - some of our constants are `static` instead of `const` - the `postgres` configuration module (in the config file "postgres") is named `pg`
1 parent 9395110 commit 6e870e5

File tree

22 files changed

+85
-80
lines changed

22 files changed

+85
-80
lines changed

martin/src/config/args/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ mod connections;
22
pub use connections::State;
33

44
#[cfg(feature = "postgres")]
5-
mod pg;
5+
mod postgres;
66
#[cfg(feature = "postgres")]
7-
pub use pg::{BoundsCalcType, DEFAULT_BOUNDS_TIMEOUT, PgArgs};
7+
pub use postgres::{BoundsCalcType, DEFAULT_BOUNDS_TIMEOUT, PgArgs};
88

99
mod root;
1010
pub use root::*;

martin/src/config/args/pg.rs renamed to martin/src/config/args/postgres.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize};
1010
use super::connections::Arguments;
1111
use super::connections::State::{Ignore, Take};
1212
use crate::config::file::UnrecognizedValues;
13-
use crate::config::file::pg::{POOL_SIZE_DEFAULT, PgConfig, PgSslCerts};
13+
use crate::config::file::postgres::{POOL_SIZE_DEFAULT, PgConfig, PgSslCerts};
1414
// Must match the help string for BoundsType::Quick
1515
pub const DEFAULT_BOUNDS_TIMEOUT: Duration = Duration::from_secs(5);
1616

martin/src/config/args/root.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use super::connections::Arguments;
1010
use super::srv::SrvArgs;
1111
use crate::MartinError::ConfigAndConnectionsError;
1212
use crate::MartinResult;
13+
#[cfg(feature = "postgres")]
14+
use crate::config::args::PgArgs;
1315
use crate::config::file::Config;
1416
#[cfg(any(
1517
feature = "cog",
@@ -45,7 +47,7 @@ pub struct Args {
4547
pub srv: SrvArgs,
4648
#[cfg(feature = "postgres")]
4749
#[command(flatten)]
48-
pub pg: Option<super::pg::PgArgs>,
50+
pub pg: Option<PgArgs>,
4951
}
5052

5153
// None of these params will be transferred to the config
@@ -231,6 +233,8 @@ mod tests {
231233
fn cli_with_config() {
232234
use martin_core::config::OptOneMany;
233235

236+
use crate::config::file::postgres::PgConfig;
237+
234238
let args = parse(&["martin", "--config", "c.toml"]).unwrap();
235239
let meta = MetaArgs {
236240
config: Some(PathBuf::from("c.toml")),
@@ -248,7 +252,7 @@ mod tests {
248252

249253
let args = parse(&["martin", "postgres://connection"]).unwrap();
250254
let cfg = Config {
251-
postgres: OptOneMany::One(crate::config::file::pg::PgConfig {
255+
postgres: OptOneMany::One(PgConfig {
252256
connection_string: Some("postgres://connection".to_string()),
253257
..Default::default()
254258
}),

martin/src/config/file/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub struct Config {
5050

5151
#[cfg(feature = "postgres")]
5252
#[serde(default, skip_serializing_if = "OptOneMany::is_none")]
53-
pub postgres: OptOneMany<super::pg::PgConfig>,
53+
pub postgres: OptOneMany<super::postgres::PgConfig>,
5454

5555
#[cfg(feature = "pmtiles")]
5656
#[serde(default, skip_serializing_if = "FileConfigEnum::is_none")]

martin/src/config/file/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ pub mod cog;
1212
pub mod fonts;
1313
#[cfg(feature = "mbtiles")]
1414
pub mod mbtiles;
15-
#[cfg(feature = "postgres")]
16-
pub mod pg;
1715
#[cfg(feature = "pmtiles")]
1816
pub mod pmtiles;
17+
#[cfg(feature = "postgres")]
18+
pub mod postgres;
1919
#[cfg(feature = "sprites")]
2020
pub mod sprites;
2121
#[cfg(feature = "styles")]

martin/src/config/file/pg/utils.rs

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

martin/src/pg/builder.rs renamed to martin/src/config/file/postgres/builder.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::cmp::Ordering;
2-
use std::collections::{BTreeMap, HashSet};
2+
use std::collections::HashSet;
33

44
use futures::future::join_all;
55
use itertools::Itertools as _;
@@ -10,20 +10,16 @@ use martin_core::tiles::BoxedSource;
1010
use martin_core::tiles::postgres::{PgError, PgPool, PgResult, PgSource, PgSqlInfo};
1111

1212
use crate::config::args::BoundsCalcType;
13-
use crate::config::file::pg::{
14-
FuncInfoSources, FunctionInfo, POOL_SIZE_DEFAULT, PgCfgPublish, PgCfgPublishFuncs, PgConfig,
15-
PgInfo, TableInfo, TableInfoSources,
13+
use crate::config::file::postgres::resolver::{
14+
query_available_function, query_available_tables, table_to_query,
15+
};
16+
use crate::config::file::postgres::utils::{find_info, find_kv_ignore_case, normalize_key};
17+
use crate::config::file::postgres::{
18+
FuncInfoSources, POOL_SIZE_DEFAULT, PgCfgPublish, PgCfgPublishFuncs, PgConfig, PgInfo,
19+
TableInfo, TableInfoSources,
1620
};
17-
use crate::pg::query_functions::query_available_function;
18-
use crate::pg::query_tables::{query_available_tables, table_to_query};
19-
use crate::pg::utils::{find_info, find_kv_ignore_case, normalize_key};
2021
use crate::utils::IdResolver;
2122

22-
/// Map of `PostgreSQL` functions organized by schema and function name.
23-
pub type SqlFuncInfoMapMap = BTreeMap<String, BTreeMap<String, (PgSqlInfo, FunctionInfo)>>;
24-
/// Map of `PostgreSQL` tables organized by schema, table, and geometry column.
25-
pub type SqlTableInfoMapMapMap = BTreeMap<String, BTreeMap<String, BTreeMap<String, TableInfo>>>;
26-
2723
/// Builder for auto-discovering `PostgreSQL` tile sources.
2824
#[derive(Debug)]
2925
pub struct PgBuilder {
@@ -118,11 +114,13 @@ impl PgBuilder {
118114
}
119115

120116
/// Returns the bounds calculation type for this builder.
117+
#[must_use]
121118
pub fn auto_bounds(&self) -> BoundsCalcType {
122119
self.auto_bounds
123120
}
124121

125122
/// ID under which this [`PgBuilder`] is identified externally
123+
#[must_use]
126124
pub fn get_id(&self) -> &str {
127125
self.pool.get_id()
128126
}
@@ -131,7 +129,6 @@ impl PgBuilder {
131129
#[allow(clippy::too_many_lines)]
132130
pub async fn instantiate_tables(&self) -> PgResult<(Vec<BoxedSource>, TableInfoSources)> {
133131
// FIXME: this function has gotten too long due to the new formatting rules, need to be refactored
134-
//
135132
let mut db_tables_info = query_available_tables(&self.pool).await?;
136133

137134
// Match configured sources with the discovered ones and add them to the pending list.

martin/src/config/file/pg/config.rs renamed to martin/src/config/file/postgres/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ use tokio::time::timeout;
1414
use super::{FuncInfoSources, TableInfoSources};
1515
use crate::MartinResult;
1616
use crate::config::args::{BoundsCalcType, DEFAULT_BOUNDS_TIMEOUT};
17+
use crate::config::file::postgres::PgBuilder;
1718
use crate::config::file::{
1819
ConfigExtras, UnrecognizedKeys, UnrecognizedValues, copy_unrecognized_keys_from_config,
1920
};
20-
use crate::pg::builder::PgBuilder;
2121
use crate::utils::IdResolver;
2222

2323
pub trait PgInfo {
@@ -324,7 +324,7 @@ mod tests {
324324
use tilejson::Bounds;
325325

326326
use super::*;
327-
use crate::config::file::pg::{FunctionInfo, TableInfo};
327+
use crate::config::file::postgres::{FunctionInfo, TableInfo};
328328
use crate::config::file::{Config, parse_config};
329329

330330
pub fn parse_cfg(yaml: &str) -> Config {

martin/src/config/file/pg/config_function.rs renamed to martin/src/config/file/postgres/config_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use tilejson::{Bounds, TileJSON};
55

66
use super::config::PgInfo;
77
use crate::config::file::UnrecognizedValues;
8-
use crate::config::file::pg::utils::patch_json;
8+
use crate::config::file::postgres::utils::patch_json;
99

1010
pub type FuncInfoSources = BTreeMap<String, FunctionInfo>;
1111

martin/src/config/file/pg/config_table.rs renamed to martin/src/config/file/postgres/config_table.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use tilejson::{Bounds, TileJSON, VectorLayer};
66

77
use super::PgInfo;
88
use crate::config::file::UnrecognizedValues;
9-
use crate::config::file::pg::utils::patch_json;
10-
use crate::pg::utils::normalize_key;
9+
use crate::config::file::postgres::utils::{normalize_key, patch_json};
1110

1211
pub type TableInfoSources = BTreeMap<String, TableInfo>;
1312

0 commit comments

Comments
 (0)