• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / etl / 15885763648

25 Jun 2025 07:49PM UTC coverage: 60.073% (-1.4%) from 61.443%
15885763648

Pull #152

github

web-flow
Merge 2b95001e0 into 9f0201c2d
Pull Request #152: feat: add postgres state store to allow state to be persisted to the source db

81 of 313 new or added lines in 16 files covered. (25.88%)

29 existing lines in 8 files now uncovered.

5576 of 9282 relevant lines covered (60.07%)

27.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.64
/postgres/src/sqlx/config.rs
1
use std::fmt::Display;
2

3
use secrecy::{ExposeSecret, Secret};
4
use serde::Deserialize;
5
use sqlx::postgres::{PgConnectOptions, PgSslMode as SqlxPgSslMode};
6

7
/// Connection config for a PostgreSQL database to be used with `sqlx`.
8
///
9
/// Contains the connection parameters needed to establish a connection to a PostgreSQL
10
/// database server, including network location, authentication credentials, and security
11
/// settings.
12
#[derive(Debug, Clone, Deserialize)]
13
pub struct PgConnectionConfig {
14
    /// Host name or IP address of the PostgreSQL server
15
    pub host: String,
16
    /// Port number that the PostgreSQL server listens on
17
    pub port: u16,
18
    /// Name of the target database
19
    pub name: String,
20
    /// Username for authentication
21
    pub username: String,
22
    /// Optional password for authentication, wrapped in [`Secret`] for secure handling
23
    pub password: Option<Secret<String>>,
24
    /// TLS config for the connection
25
    pub tls_config: PgTlsConfig,
26
}
27

28
impl PgConnectionConfig {
29
    /// Creates connection options for connecting to the PostgreSQL server without
30
    /// specifying a database.
31
    ///
32
    /// Returns [`PgConnectOptions`] configured with the host, port, username, SSL mode
33
    /// and optional password from this instance. Useful for administrative operations
34
    /// that must be performed before connecting to a specific database, like database
35
    /// creation.
36
    pub fn without_db(&self) -> PgConnectOptions {
177✔
37
        let options = PgConnectOptions::new_without_pgpass()
177✔
38
            .host(&self.host)
177✔
39
            .username(&self.username)
177✔
40
            .port(self.port)
177✔
41
            .ssl_mode(self.tls_config.ssl_mode.clone().into())
177✔
42
            .ssl_root_cert_from_pem(self.tls_config.trusted_root_certs.clone());
177✔
43

44
        if let Some(password) = &self.password {
177✔
45
            options.password(password.expose_secret())
177✔
46
        } else {
47
            options
×
48
        }
49
    }
177✔
50

51
    /// Creates connection options for connecting to a specific database.
52
    ///
53
    /// Returns [`PgConnectOptions`] configured with all connection parameters including
54
    /// the database name from this instance.
55
    pub fn with_db(&self) -> PgConnectOptions {
59✔
56
        self.without_db().database(&self.name)
59✔
57
    }
59✔
58
}
59

60
/// We use our own type because the sqlx enum doesn't implement Deserialize
61
#[derive(Debug, Clone, Deserialize)]
62
pub enum PgSslMode {
63
    /// Only try a non-SSL connection.
64
    Disable,
65

66
    /// First try a non-SSL connection; if that fails, try an SSL connection.
67
    Allow,
68

69
    /// First try an SSL connection; if that fails, try a non-SSL connection.
70
    ///
71
    Prefer,
72

73
    /// Only try an SSL connection. If a root CA file is present, verify the connection
74
    /// in the same way as if `VerifyCa` was specified.
75
    Require,
76

77
    /// Only try an SSL connection, and verify that the server certificate is issued by a
78
    /// trusted certificate authority (CA).
79
    VerifyCa,
80

81
    /// Only try an SSL connection; verify that the server certificate is issued by a trusted
82
    /// CA and that the requested server host name matches that in the certificate.
83
    VerifyFull,
84
}
85

86
impl Display for PgSslMode {
NEW
87
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
×
NEW
88
        write!(
×
NEW
89
            f,
×
NEW
90
            "{}",
×
NEW
91
            match self {
×
NEW
92
                PgSslMode::Disable => "disable",
×
NEW
93
                PgSslMode::Allow => "allow",
×
NEW
94
                PgSslMode::Prefer => "prefer",
×
NEW
95
                PgSslMode::Require => "require",
×
NEW
96
                PgSslMode::VerifyCa => "verify-ca",
×
NEW
97
                PgSslMode::VerifyFull => "verify-full",
×
98
            }
99
        )
NEW
100
    }
×
101
}
102

103
impl From<PgSslMode> for SqlxPgSslMode {
104
    fn from(value: PgSslMode) -> Self {
177✔
105
        match value {
177✔
NEW
106
            PgSslMode::Disable => SqlxPgSslMode::Disable,
×
NEW
107
            PgSslMode::Allow => SqlxPgSslMode::Allow,
×
108
            PgSslMode::Prefer => SqlxPgSslMode::Prefer,
177✔
NEW
109
            PgSslMode::Require => SqlxPgSslMode::Require,
×
NEW
110
            PgSslMode::VerifyCa => SqlxPgSslMode::VerifyCa,
×
NEW
111
            PgSslMode::VerifyFull => SqlxPgSslMode::VerifyFull,
×
112
        }
113
    }
177✔
114
}
115

116
impl From<SqlxPgSslMode> for PgSslMode {
NEW
117
    fn from(value: SqlxPgSslMode) -> Self {
×
NEW
118
        match value {
×
NEW
119
            SqlxPgSslMode::Disable => PgSslMode::Disable,
×
NEW
120
            SqlxPgSslMode::Allow => PgSslMode::Allow,
×
NEW
121
            SqlxPgSslMode::Prefer => PgSslMode::Prefer,
×
NEW
122
            SqlxPgSslMode::Require => PgSslMode::Require,
×
NEW
123
            SqlxPgSslMode::VerifyCa => PgSslMode::VerifyCa,
×
NEW
124
            SqlxPgSslMode::VerifyFull => PgSslMode::VerifyFull,
×
125
        }
NEW
126
    }
×
127
}
128

129
#[derive(Debug, Clone, Deserialize)]
130
pub struct PgTlsConfig {
131
    /// The SSL verification to use when making a TLS connection to Postgres
132
    pub ssl_mode: PgSslMode,
133

134
    /// The trusted root certificates to ues for the TLS connection verification.
135
    /// The certificate should be in pem format
136
    pub trusted_root_certs: Vec<u8>,
137
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc