footing 0.4.4

Feature-gated foundations for Rust backend services
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
//! SQLite settings validation and immutable runtime configuration.

use std::{fmt, str::FromStr, time::Duration};

use serde::{Deserialize, Serialize};
use sqlx::sqlite::SqliteConnectOptions;

use crate::settings::{SettingsIssues, SettingsValidationError};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
/// Validated immutable SQLite pool configuration.
pub struct SqlitePoolConfig {
    pub(super) max_connections: u32,
    pub(super) min_connections: u32,
    pub(super) acquire_timeout: Duration,
    pub(super) idle_timeout: Option<Duration>,
    pub(super) max_lifetime: Option<Duration>,
    pub(super) test_before_acquire: bool,
}

impl Default for SqlitePoolConfig {
    fn default() -> Self {
        Self {
            max_connections: 5,
            min_connections: 0,
            acquire_timeout: Duration::from_secs(5),
            idle_timeout: Some(Duration::from_secs(10 * 60)),
            max_lifetime: Some(Duration::from_secs(30 * 60)),
            test_before_acquire: true,
        }
    }
}

impl SqlitePoolConfig {
    #[must_use]
    /// Returns the maximum number of connections.
    pub const fn max_connections(&self) -> u32 {
        self.max_connections
    }

    #[must_use]
    /// Returns the minimum number of idle connections.
    pub const fn min_connections(&self) -> u32 {
        self.min_connections
    }

    #[must_use]
    /// Returns the maximum wait for a pooled connection.
    pub const fn acquire_timeout(&self) -> Duration {
        self.acquire_timeout
    }

    #[must_use]
    /// Returns the optional idle connection timeout.
    pub const fn idle_timeout(&self) -> Option<Duration> {
        self.idle_timeout
    }

    #[must_use]
    /// Returns the optional maximum connection lifetime.
    pub const fn max_lifetime(&self) -> Option<Duration> {
        self.max_lifetime
    }

    #[must_use]
    /// Returns whether pooled connections are tested before acquisition.
    pub const fn test_before_acquire(&self) -> bool {
        self.test_before_acquire
    }
}

#[cfg_attr(feature = "tier", derive(tier::TierConfig))]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(default, deny_unknown_fields)]
#[non_exhaustive]
/// Serializable SQLite pool settings.
///
/// For in-memory databases, empty filenames, and native `file:` URI filenames,
/// the connection helpers use one connection without testing or recycling to
/// preserve databases that would otherwise disappear when a connection closes.
pub struct SqlitePoolSettings {
    /// Maximum number of connections maintained by the pool.
    pub max_connections: u32,
    /// Minimum number of idle connections maintained by the pool.
    pub min_connections: u32,
    #[serde(with = "crate::settings::human_duration")]
    /// Maximum time to wait for a connection.
    pub acquire_timeout: Duration,
    #[serde(with = "crate::settings::human_duration::option")]
    /// Optional idle duration after which a connection is closed.
    pub idle_timeout: Option<Duration>,
    #[serde(with = "crate::settings::human_duration::option")]
    /// Optional maximum lifetime of a connection.
    pub max_lifetime: Option<Duration>,
    /// Whether connections are checked before being returned to callers.
    pub test_before_acquire: bool,
}

impl Default for SqlitePoolSettings {
    fn default() -> Self {
        Self::from(SqlitePoolConfig::default())
    }
}

impl From<SqlitePoolConfig> for SqlitePoolSettings {
    fn from(value: SqlitePoolConfig) -> Self {
        Self {
            max_connections: value.max_connections,
            min_connections: value.min_connections,
            acquire_timeout: value.acquire_timeout,
            idle_timeout: value.idle_timeout,
            max_lifetime: value.max_lifetime,
            test_before_acquire: value.test_before_acquire,
        }
    }
}

impl SqlitePoolSettings {
    #[must_use]
    /// Configures the maximum connections.
    pub const fn with_max_connections(mut self, max_connections: u32) -> Self {
        self.max_connections = max_connections;
        self
    }

    #[must_use]
    /// Configures the minimum idle connections.
    pub const fn with_min_connections(mut self, min_connections: u32) -> Self {
        self.min_connections = min_connections;
        self
    }

    #[must_use]
    /// Configures the connection acquisition timeout.
    pub const fn with_acquire_timeout(mut self, acquire_timeout: Duration) -> Self {
        self.acquire_timeout = acquire_timeout;
        self
    }

    #[must_use]
    /// Configures the idle connection timeout.
    /// `None` disables idle connection eviction.
    pub const fn with_idle_timeout(mut self, idle_timeout: Option<Duration>) -> Self {
        self.idle_timeout = idle_timeout;
        self
    }

    #[must_use]
    /// Configures the maximum connection lifetime.
    /// `None` disables connection recycling based on age.
    pub const fn with_max_lifetime(mut self, max_lifetime: Option<Duration>) -> Self {
        self.max_lifetime = max_lifetime;
        self
    }

    #[must_use]
    /// Configures connection testing before acquisition.
    pub const fn with_test_before_acquire(mut self, test_before_acquire: bool) -> Self {
        self.test_before_acquire = test_before_acquire;
        self
    }

    /// Builds validated runtime pool configuration.
    pub fn build(self) -> Result<SqlitePoolConfig, SettingsValidationError> {
        self.validate()?;
        Ok(self.into_config())
    }

    fn into_config(self) -> SqlitePoolConfig {
        SqlitePoolConfig {
            max_connections: self.max_connections,
            min_connections: self.min_connections,
            acquire_timeout: self.acquire_timeout,
            idle_timeout: self.idle_timeout,
            max_lifetime: self.max_lifetime,
            test_before_acquire: self.test_before_acquire,
        }
    }

    /// Validates all pool settings.
    pub fn validate(&self) -> Result<(), SettingsValidationError> {
        self.validate_at("sqlite.pool")
    }

    pub(crate) fn validate_at(&self, path: &str) -> Result<(), SettingsValidationError> {
        let mut issues = SettingsIssues::new();
        issues.require(
            self.max_connections > 0,
            format!("{path}.max_connections"),
            "must be greater than zero",
        );
        issues.require(
            !self.acquire_timeout.is_zero()
                && std::time::Instant::now()
                    .checked_add(self.acquire_timeout)
                    .is_some(),
            format!("{path}.acquire_timeout"),
            "must be greater than zero and fit the runtime timer range",
        );
        issues.require(
            self.min_connections <= self.max_connections,
            format!("{path}.min_connections"),
            "must be less than or equal to max_connections",
        );
        for (field, timeout) in [
            ("idle_timeout", self.idle_timeout),
            ("max_lifetime", self.max_lifetime),
        ] {
            issues.require(
                timeout.is_none_or(|timeout| {
                    !timeout.is_zero() && std::time::Instant::now().checked_add(timeout).is_some()
                }),
                format!("{path}.{field}"),
                "must be omitted or greater than zero and fit the runtime timer range",
            );
        }
        issues.into_result()
    }
}

#[cfg_attr(feature = "tier", derive(tier::TierConfig))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
/// SQLite journal mode applied when opening each connection.
pub enum SqliteJournalMode {
    /// Delete the rollback journal after each transaction.
    Delete,
    /// Truncate the rollback journal after each transaction.
    Truncate,
    /// Preserve the rollback journal file for reuse.
    Persist,
    /// Keep the rollback journal in memory.
    Memory,
    /// Use write-ahead logging.
    Wal,
    /// Disable the rollback journal; a failed transaction may corrupt the database.
    Off,
}

#[cfg_attr(feature = "tier", derive(tier::TierConfig))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
/// SQLite synchronization policy applied when opening each connection.
pub enum SqliteSynchronousMode {
    /// Disable synchronization barriers.
    ///
    /// A system or power failure can corrupt the database in this mode.
    Off,
    /// Use SQLite's normal synchronization policy.
    Normal,
    /// Fully synchronize critical database operations.
    Full,
    /// Add synchronization after rollback journal deletion.
    Extra,
}

#[derive(Clone, PartialEq, Eq)]
#[non_exhaustive]
/// Validated immutable SQLite connection configuration.
pub struct SqliteConnectionConfig {
    pub(super) database_url: String,
    pub(super) create_if_missing: bool,
    pub(super) read_only: bool,
    pub(super) foreign_keys: bool,
    pub(super) busy_timeout: Duration,
    pub(super) journal_mode: Option<SqliteJournalMode>,
    pub(super) synchronous: Option<SqliteSynchronousMode>,
    pub(super) statement_cache_capacity: usize,
}

impl fmt::Debug for SqliteConnectionConfig {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("SqliteConnectionConfig")
            .field("database_url", &"[REDACTED]")
            .field("create_if_missing", &self.create_if_missing)
            .field("read_only", &self.read_only)
            .field("foreign_keys", &self.foreign_keys)
            .field("busy_timeout", &self.busy_timeout)
            .field("journal_mode", &self.journal_mode)
            .field("synchronous", &self.synchronous)
            .field("statement_cache_capacity", &self.statement_cache_capacity)
            .finish()
    }
}

impl SqliteConnectionConfig {
    #[must_use]
    /// Returns the SQLite connection URL.
    pub fn database_url(&self) -> &str {
        &self.database_url
    }

    #[must_use]
    /// Returns whether a missing database file is created.
    pub const fn create_if_missing(&self) -> bool {
        self.create_if_missing
    }

    #[must_use]
    /// Returns whether the database is opened read-only.
    pub const fn read_only(&self) -> bool {
        self.read_only
    }

    #[must_use]
    /// Returns whether foreign key enforcement is enabled.
    pub const fn foreign_keys(&self) -> bool {
        self.foreign_keys
    }

    #[must_use]
    /// Returns how long SQLite waits for a locked database.
    pub const fn busy_timeout(&self) -> Duration {
        self.busy_timeout
    }

    #[must_use]
    /// Returns the explicitly configured journal mode.
    pub const fn journal_mode(&self) -> Option<SqliteJournalMode> {
        self.journal_mode
    }

    #[must_use]
    /// Returns the explicitly configured synchronization policy.
    pub const fn synchronous(&self) -> Option<SqliteSynchronousMode> {
        self.synchronous
    }

    #[must_use]
    /// Returns the prepared statement cache capacity per connection.
    pub const fn statement_cache_capacity(&self) -> usize {
        self.statement_cache_capacity
    }
}

#[cfg_attr(feature = "tier", derive(tier::TierConfig))]
#[derive(Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
/// Serializable SQLite connection settings.
///
/// The URL accepts the simple SQLx `sqlite:` forms without query parameters or
/// nested native `file:` URIs. Advanced SQLite URI filenames and SQLx options
/// can be supplied through the explicit options-based runtime functions.
pub struct SqliteConnectionSettings {
    /// SQLite connection URL. Debug output redacts file-system locations.
    pub database_url: String,
    #[serde(default)]
    /// Whether a missing database file is created during connection.
    pub create_if_missing: bool,
    #[serde(default)]
    /// Whether the database is opened read-only.
    pub read_only: bool,
    #[serde(default = "default_true")]
    /// Whether SQLite enforces foreign key constraints.
    pub foreign_keys: bool,
    #[serde(
        default = "default_busy_timeout",
        with = "crate::settings::human_duration"
    )]
    /// How long SQLite waits when the database is locked.
    pub busy_timeout: Duration,
    #[serde(default)]
    /// Optional journal mode; `None` preserves the database's existing mode.
    pub journal_mode: Option<SqliteJournalMode>,
    #[serde(default)]
    /// Optional synchronization policy; `None` preserves SQLite's default.
    pub synchronous: Option<SqliteSynchronousMode>,
    #[serde(default = "default_statement_cache_capacity")]
    /// Prepared statement cache capacity per connection.
    pub statement_cache_capacity: usize,
}

impl fmt::Debug for SqliteConnectionSettings {
    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
        formatter
            .debug_struct("SqliteConnectionSettings")
            .field("database_url", &"[REDACTED]")
            .field("create_if_missing", &self.create_if_missing)
            .field("read_only", &self.read_only)
            .field("foreign_keys", &self.foreign_keys)
            .field("busy_timeout", &self.busy_timeout)
            .field("journal_mode", &self.journal_mode)
            .field("synchronous", &self.synchronous)
            .field("statement_cache_capacity", &self.statement_cache_capacity)
            .finish()
    }
}

impl SqliteConnectionSettings {
    #[must_use]
    /// Creates SQLite connection settings for a URL.
    ///
    /// Uses read-write access with foreign keys enabled, but does not create a
    /// missing database file. Journal and synchronization modes are left to
    /// SQLite. Use [`Self::with_create_if_missing`] to opt into file creation,
    /// then [`Self::build`] to validate settings before connecting.
    pub fn new(database_url: impl Into<String>) -> Self {
        Self {
            database_url: database_url.into(),
            create_if_missing: false,
            read_only: false,
            foreign_keys: true,
            busy_timeout: default_busy_timeout(),
            journal_mode: None,
            synchronous: None,
            statement_cache_capacity: default_statement_cache_capacity(),
        }
    }

    #[must_use]
    /// Configures creation of a missing database file.
    pub const fn with_create_if_missing(mut self, create_if_missing: bool) -> Self {
        self.create_if_missing = create_if_missing;
        self
    }

    #[must_use]
    /// Configures read-only access.
    pub const fn with_read_only(mut self, read_only: bool) -> Self {
        self.read_only = read_only;
        self
    }

    #[must_use]
    /// Configures foreign key enforcement.
    pub const fn with_foreign_keys(mut self, foreign_keys: bool) -> Self {
        self.foreign_keys = foreign_keys;
        self
    }

    #[must_use]
    /// Configures the SQLite busy timeout.
    pub const fn with_busy_timeout(mut self, busy_timeout: Duration) -> Self {
        self.busy_timeout = busy_timeout;
        self
    }

    #[must_use]
    /// Configures the SQLite journal mode.
    pub const fn with_journal_mode(mut self, journal_mode: Option<SqliteJournalMode>) -> Self {
        self.journal_mode = journal_mode;
        self
    }

    #[must_use]
    /// Configures the SQLite synchronization policy.
    pub const fn with_synchronous(mut self, synchronous: Option<SqliteSynchronousMode>) -> Self {
        self.synchronous = synchronous;
        self
    }

    #[must_use]
    /// Configures the prepared statement cache capacity.
    pub const fn with_statement_cache_capacity(mut self, capacity: usize) -> Self {
        self.statement_cache_capacity = capacity;
        self
    }

    /// Validates all SQLite connection settings.
    pub fn validate(&self) -> Result<(), SettingsValidationError> {
        self.validate_at("sqlite.connection")
    }

    pub(crate) fn validate_at(&self, path: &str) -> Result<(), SettingsValidationError> {
        let mut issues = SettingsIssues::new();
        issues.require_non_empty(format!("{path}.database_url"), &self.database_url);
        // SQLite's busy handler accepts a signed 32-bit millisecond timeout.
        issues.require(
            self.busy_timeout.as_millis() <= i32::MAX as u128,
            format!("{path}.busy_timeout"),
            "must not exceed 2147483647 milliseconds",
        );
        if !self.database_url.trim().is_empty() {
            let options = SqliteConnectOptions::from_str(&self.database_url);
            issues.require(
                self.database_url.starts_with("sqlite:") && options.is_ok(),
                format!("{path}.database_url"),
                "must be a valid SQLite connection URL beginning with 'sqlite:'",
            );
            issues.require(
                !self.database_url.contains('?'),
                format!("{path}.database_url"),
                "must not contain connection parameters; use explicit settings instead",
            );
            if let Ok(options) = options {
                // SQLx decodes the filename before SQLite parses native URIs.
                // Inspect that filename so encoded query delimiters cannot
                // override explicit settings through a nested file: URI.
                // These two plain memory URLs generate a file: name inside
                // SQLx itself and remain supported.
                let plain_memory_url = matches!(
                    self.database_url.as_str(),
                    "sqlite::memory:" | "sqlite://:memory:"
                );
                issues.require(
                    plain_memory_url
                        || !options
                            .get_filename()
                            .as_os_str()
                            .as_encoded_bytes()
                            .starts_with(b"file:"),
                    format!("{path}.database_url"),
                    "must not contain a native file: URI; use explicit SQLx options instead",
                );
            }
        }
        issues.require(
            !(self.read_only && self.create_if_missing),
            format!("{path}.create_if_missing"),
            "must be false when read_only is true",
        );
        issues.require(
            !(self.read_only && self.journal_mode.is_some()),
            format!("{path}.journal_mode"),
            "must be omitted when read_only is true",
        );
        issues.into_result()
    }

    /// Builds validated immutable SQLite connection configuration.
    pub fn build(self) -> Result<SqliteConnectionConfig, SettingsValidationError> {
        self.validate()?;
        Ok(self.into_config())
    }

    fn into_config(self) -> SqliteConnectionConfig {
        SqliteConnectionConfig {
            database_url: self.database_url,
            create_if_missing: self.create_if_missing,
            read_only: self.read_only,
            foreign_keys: self.foreign_keys,
            busy_timeout: self.busy_timeout,
            journal_mode: self.journal_mode,
            synchronous: self.synchronous,
            statement_cache_capacity: self.statement_cache_capacity,
        }
    }
}

impl From<SqliteConnectionConfig> for SqliteConnectionSettings {
    fn from(value: SqliteConnectionConfig) -> Self {
        Self {
            database_url: value.database_url,
            create_if_missing: value.create_if_missing,
            read_only: value.read_only,
            foreign_keys: value.foreign_keys,
            busy_timeout: value.busy_timeout,
            journal_mode: value.journal_mode,
            synchronous: value.synchronous,
            statement_cache_capacity: value.statement_cache_capacity,
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
/// Validated immutable SQLite startup configuration.
pub struct SqliteBootstrapConfig {
    pub(super) connection_config: SqliteConnectionConfig,
    pub(super) pool_config: SqlitePoolConfig,
    pub(super) migrate_on_startup: bool,
}

impl SqliteBootstrapConfig {
    #[must_use]
    /// Returns the connection configuration.
    pub const fn connection_config(&self) -> &SqliteConnectionConfig {
        &self.connection_config
    }

    #[must_use]
    /// Returns the pool configuration.
    pub const fn pool_config(&self) -> SqlitePoolConfig {
        self.pool_config
    }

    #[must_use]
    /// Returns whether migrations run during startup.
    pub const fn migrate_on_startup(&self) -> bool {
        self.migrate_on_startup
    }
}

#[cfg_attr(feature = "tier", derive(tier::TierConfig))]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
#[non_exhaustive]
/// Serializable settings for SQLite startup.
///
/// Startup migrations are disabled by default and must be explicitly enabled.
pub struct SqliteBootstrapSettings {
    /// SQLite connection settings.
    pub connection: SqliteConnectionSettings,
    #[serde(default)]
    /// Connection pool settings.
    pub pool: SqlitePoolSettings,
    #[serde(default)]
    /// Whether to apply migrations during startup.
    pub migrate_on_startup: bool,
}

impl SqliteBootstrapSettings {
    #[must_use]
    /// Creates SQLite startup settings for a connection URL.
    ///
    /// Uses [`SqliteConnectionSettings::new`] and the default pool settings.
    /// Startup migrations are disabled; enable them explicitly when the
    /// application controls migration concurrency. Building settings performs
    /// validation without opening the database.
    pub fn new(database_url: impl Into<String>) -> Self {
        Self::from_connection(SqliteConnectionSettings::new(database_url))
    }

    #[must_use]
    /// Creates SQLite startup settings from explicit connection settings.
    pub fn from_connection(connection: SqliteConnectionSettings) -> Self {
        Self {
            connection,
            pool: SqlitePoolSettings::default(),
            migrate_on_startup: false,
        }
    }

    #[must_use]
    /// Configures the connection settings.
    pub fn with_connection(mut self, connection: SqliteConnectionSettings) -> Self {
        self.connection = connection;
        self
    }

    #[must_use]
    /// Configures the pool settings.
    pub fn with_pool(mut self, pool: SqlitePoolSettings) -> Self {
        self.pool = pool;
        self
    }

    #[must_use]
    /// Configures startup migrations.
    pub const fn with_migrate_on_startup(mut self, migrate_on_startup: bool) -> Self {
        self.migrate_on_startup = migrate_on_startup;
        self
    }

    /// Validates all SQLite startup settings.
    pub fn validate(&self) -> Result<(), SettingsValidationError> {
        self.validate_at("sqlite")
    }

    pub(crate) fn validate_at(&self, path: &str) -> Result<(), SettingsValidationError> {
        let mut issues = SettingsIssues::new();
        issues.extend_result(self.connection.validate_at(&format!("{path}.connection")));
        issues.extend_result(self.pool.validate_at(&format!("{path}.pool")));
        issues.require(
            !(self.connection.read_only && self.migrate_on_startup),
            format!("{path}.migrate_on_startup"),
            "must be false when connection.read_only is true",
        );
        issues.into_result()
    }

    /// Builds validated immutable SQLite startup configuration.
    pub fn build(self) -> Result<SqliteBootstrapConfig, SettingsValidationError> {
        self.validate()?;
        Ok(SqliteBootstrapConfig {
            connection_config: self.connection.into_config(),
            pool_config: self.pool.into_config(),
            migrate_on_startup: self.migrate_on_startup,
        })
    }
}

impl From<SqliteBootstrapConfig> for SqliteBootstrapSettings {
    fn from(value: SqliteBootstrapConfig) -> Self {
        Self {
            connection: SqliteConnectionSettings::from(value.connection_config),
            pool: SqlitePoolSettings::from(value.pool_config),
            migrate_on_startup: value.migrate_on_startup,
        }
    }
}

const fn default_busy_timeout() -> Duration {
    Duration::from_secs(5)
}

const fn default_statement_cache_capacity() -> usize {
    100
}

const fn default_true() -> bool {
    true
}