Skip to main content

schema/deployment/
source.rs

1use schema_core::{
2    ConnectionSpec, ConnectionUrl, ResolveError, SourceType, resolve_connection_url,
3};
4use serde::{Deserialize, Serialize};
5
6/// The database documents are read from. Today that's always Postgres.
7///
8/// The connection is stored unresolved (a literal or an environment reference)
9/// and resolved at runtime by [`resolve_connection_url`](Source::resolve_connection_url),
10/// so a compiled config carries no secret it wasn't given literally.
11#[derive(Debug, Clone, Serialize, Deserialize)]
12pub struct Source {
13    pub source_type: SourceType,
14    /// How to reach the database. `None` means "rely entirely on
15    /// `DATABASE_URL`", checked when the connection is resolved.
16    #[serde(default, skip_serializing_if = "Option::is_none")]
17    pub connection: Option<ConnectionSpec>,
18    /// Whether flusso may auto-create/extend the publication to cover every
19    /// table the indexes read. Defaults to `true`; a CLI flag can override it
20    /// per run. See [`crate`] docs and the publication-management design.
21    #[serde(default = "default_manage_publication")]
22    pub manage_publication: bool,
23}
24
25/// Publication management is on unless explicitly disabled — and a default keeps
26/// older compiled locks (written before this field existed) deserializing.
27fn default_manage_publication() -> bool {
28    true
29}
30
31impl Source {
32    /// Resolve the connection URL now, in the current environment, applying the
33    /// `DATABASE_URL` deployment override. Call this at connect time, not at
34    /// load time, so the value is read where the pipeline runs.
35    pub fn resolve_connection_url(&self) -> Result<ConnectionUrl, ResolveError> {
36        resolve_connection_url(self.connection.as_ref())
37    }
38}