Name SQL cluster configuration explicitly
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Cluster, ConfigError, DeploymentConfig, Driver, ObjectStorage, validate_name};
|
||||
use crate::{ConfigError, DeploymentConfig, Driver, ObjectStorage, SqlCluster, validate_name};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case")]
|
||||
pub enum Resource {
|
||||
Sql(Cluster),
|
||||
Sql(SqlCluster),
|
||||
ObjectStore(ObjectStorage),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum ResourceRef<'a> {
|
||||
Sql(&'a Cluster),
|
||||
Sql(&'a SqlCluster),
|
||||
ObjectStore(&'a ObjectStorage),
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,9 @@ pub use catalog::{Resource, ResourceRef};
|
||||
pub use driver::*;
|
||||
pub use format::{ConfigFormat, FormatError, ImportFormat};
|
||||
pub use object_storage::ObjectStorage;
|
||||
pub use sql::{Address, Cluster, ResolvedSql, Tls};
|
||||
/// Compatibility name for the SQL cluster configuration.
|
||||
pub use sql::SqlCluster as Cluster;
|
||||
pub use sql::{Address, ResolvedSql, SqlCluster, Tls};
|
||||
|
||||
pub const DOCUMENTS: &str = "documents";
|
||||
|
||||
@@ -26,7 +28,8 @@ pub struct DeploymentConfig {
|
||||
pub config_version: String,
|
||||
/// Legacy shorthand for sql.documents.
|
||||
pub cluster: Option<String>,
|
||||
pub clusters: BTreeMap<String, Cluster>,
|
||||
/// Named SQL targets that can be bound to entries in `sql`.
|
||||
pub clusters: BTreeMap<String, SqlCluster>,
|
||||
/// SQL role to named cluster.
|
||||
pub sql: BTreeMap<String, String>,
|
||||
pub object_storage: BTreeMap<String, ObjectStorage>,
|
||||
@@ -137,7 +140,7 @@ impl DeploymentConfig {
|
||||
if !targets.is_empty() {
|
||||
return Err(ConfigError::ClusterRequired);
|
||||
}
|
||||
let local = Cluster {
|
||||
let local = SqlCluster {
|
||||
driver: SqlDriver::Sqlite,
|
||||
primary: self.sqlite_path.clone(),
|
||||
replicas: vec![],
|
||||
|
||||
@@ -42,9 +42,10 @@ impl Address {
|
||||
}
|
||||
}
|
||||
|
||||
/// A SQL target with a primary connection and optional read replicas.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Cluster {
|
||||
pub struct SqlCluster {
|
||||
pub driver: SqlDriver,
|
||||
pub primary: Address,
|
||||
#[serde(default)]
|
||||
@@ -72,7 +73,7 @@ pub struct ResolvedSql {
|
||||
pub max_connections: u32,
|
||||
}
|
||||
|
||||
impl Cluster {
|
||||
impl SqlCluster {
|
||||
pub(crate) fn resolve(
|
||||
&self,
|
||||
deployment: &str,
|
||||
@@ -104,7 +105,7 @@ impl Cluster {
|
||||
}
|
||||
|
||||
fn resolve_address(
|
||||
cluster: &Cluster,
|
||||
cluster: &SqlCluster,
|
||||
address: &Address,
|
||||
read_only: bool,
|
||||
) -> Result<Address, ConfigError> {
|
||||
|
||||
Reference in New Issue
Block a user