Skip to content

Conversation

corylanou
Copy link
Collaborator

@corylanou corylanou commented Sep 11, 2025

Summary

Implements comprehensive global replica defaults to eliminate configuration duplication. This addresses issue #504 and replaces the outdated PR #553.

Users can now set global default settings for replica configurations at the top level of their configuration files, which are automatically inherited by all replicas while still allowing per-replica overrides.

Key Features

  • 🌍 Global defaults for all replica types: S3, ABS, SFTP, NATS, file, and GCS
  • 📝 All configurable settings supported: credentials, regions, endpoints, timing intervals, encryption keys
  • 🔧 Smart override behavior: Individual replicas can override any global setting
  • 🔄 Full backward compatibility: Existing configurations work unchanged
  • Comprehensive test coverage: Covers all replica types and override scenarios

Configuration Examples

Before: Verbose with duplication

dbs:
  - path: /db1.sqlite
    replica:
      type: s3
      access-key-id: AKIA...
      secret-access-key: xxx...
      region: us-west-2
      endpoint: custom.endpoint.com
      retention: 168h
      bucket: bucket1
      
  - path: /db2.sqlite  
    replica:
      type: s3
      access-key-id: AKIA...      # duplicated
      secret-access-key: xxx...   # duplicated  
      region: us-west-2           # duplicated
      endpoint: custom.endpoint.com # duplicated
      retention: 168h             # duplicated
      bucket: bucket2

After: Clean with global defaults

# Global defaults inherited by all replicas
access-key-id: AKIA...
secret-access-key: xxx...
region: us-west-2
endpoint: custom.endpoint.com
retention: 168h
sync-interval: 30s

dbs:
  - path: /db1.sqlite
    replica:
      type: s3
      bucket: bucket1
      
  - path: /db2.sqlite
    replica:
      type: s3
      bucket: bucket2
      region: us-east-1  # Override global region for this replica

Multi-replica-type example

# Global settings apply to appropriate replica types
access-key-id: AKIA...           # S3/GCS
secret-access-key: xxx...        # S3/GCS
account-name: myaccount          # ABS
account-key: abskey...           # ABS  
host: backup.example.com         # SFTP
user: backupuser                 # SFTP
sync-interval: 1m                # All types
validation-interval: 24h         # All types

dbs:
  - path: /s3-db.sqlite
    replica:
      type: s3
      bucket: s3-backups
      
  - path: /abs-db.sqlite
    replica:
      type: abs  
      bucket: abs-container
      
  - path: /sftp-db.sqlite
    replica:
      type: sftp
      path: /backup/path

Global Settings Supported

All Replica Types:

  • sync-interval
  • validation-interval

S3 & Compatible:

  • access-key-id, secret-access-key
  • region, endpoint
  • force-path-style, skip-verify

Azure Blob Storage:

  • account-name, account-key

SFTP:

  • host, user, password, key-path
  • concurrent-writes

NATS JetStream:

  • jwt, seed, creds, nkey
  • username, password, token
  • tls, root-cas, client-cert, client-key
  • max-reconnects, reconnect-wait, timeout

Age Encryption:

  • age.identities[], age.recipients[]

Implementation Details

  • New ReplicaSettings struct: Contains all shared replica configuration fields
  • Embedded with inline YAML tags: Allows seamless field access and parsing
  • Smart default propagation: SetDefaults() method handles inheritance with override logic
  • Maintains existing API: No breaking changes to current configuration formats

Testing

Added comprehensive test coverage including:

  • Global defaults with various override scenarios
  • Multiple replica types inheriting appropriate settings
  • Backward compatibility with existing configurations
  • Legacy replicas: array format support

Related

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

corylanou and others added 2 commits September 11, 2025 15:44
This feature allows users to define global default settings for replica configurations,
eliminating the need to duplicate common settings across multiple database entries.

## What's Changed

- **New ReplicaSettings struct**: Contains all configurable replica fields (S3, ABS, SFTP, NATS, Age encryption, timing settings)
- **Embedded in Config**: Global defaults can be set at the top level of configuration files
- **Embedded in ReplicaConfig**: Individual replicas inherit from global settings but can override any field
- **Smart default propagation**: SetDefaults() method merges global settings with replica-specific settings
- **Full backward compatibility**: Existing configurations continue to work unchanged
- **Comprehensive test coverage**: Tests cover all replica types and override scenarios

## Supported Global Settings

- **S3**: access-key-id, secret-access-key, region, endpoint, force-path-style, skip-verify
- **ABS**: account-name, account-key
- **SFTP**: host, user, password, key-path, concurrent-writes
- **NATS**: jwt, seed, creds, nkey, username, token, tls, root-cas, client-cert, client-key, etc.
- **Timing**: sync-interval, validation-interval
- **Encryption**: age identities and recipients

## Example Configuration

Before (verbose with duplication):
```yaml
dbs:
  - path: /db1.sqlite
    replica:
      type: s3
      access-key-id: AKIA...
      secret-access-key: xxx...
      region: us-west-2
      endpoint: custom.endpoint.com
      bucket: bucket1

  - path: /db2.sqlite
    replica:
      type: s3
      access-key-id: AKIA...      # duplicated
      secret-access-key: xxx...   # duplicated
      region: us-west-2           # duplicated
      endpoint: custom.endpoint.com # duplicated
      bucket: bucket2
```

After (clean with global defaults):
```yaml
# Global defaults
access-key-id: AKIA...
secret-access-key: xxx...
region: us-west-2
endpoint: custom.endpoint.com

dbs:
  - path: /db1.sqlite
    replica:
      type: s3
      bucket: bucket1

  - path: /db2.sqlite
    replica:
      type: s3
      bucket: bucket2
```

Fixes #504
Closes #553

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Consolidate tests into existing test file instead of creating a separate file.
All tests remain unchanged, just moved to the appropriate location.
@corylanou corylanou force-pushed the feature/global-replica-defaults branch from dfab6a2 to b8dc34c Compare September 12, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement comprehensive global replica defaults Feature request: Allow global variables to avoid duplication
1 participant