# Litestream configuration for SQLite replication to Cloudflare R2
#
# Set these env vars in .env / GitLab CI variables:
#   LITESTREAM_R2_BUCKET        e.g. padelnomics-backups
#   LITESTREAM_R2_ACCESS_KEY_ID
#   LITESTREAM_R2_SECRET_ACCESS_KEY
#   LITESTREAM_R2_ENDPOINT      e.g. <account-id>.r2.cloudflarestorage.com
#
# Recovery (app database):
#   litestream restore -config /etc/litestream.yml /app/data/app.db
#   litestream restore -config /etc/litestream.yml -timestamp "2026-01-15T12:00:00Z" /app/data/app.db
#
# Recovery (extraction state):
#   litestream restore -config /etc/litestream.yml /data/landing/.state.sqlite

dbs:
  - path: /app/data/app.db
    replicas:
      - url: s3://${LITESTREAM_R2_BUCKET}/padelnomics/app.db
        access-key-id: ${LITESTREAM_R2_ACCESS_KEY_ID}
        secret-access-key: ${LITESTREAM_R2_SECRET_ACCESS_KEY}
        endpoint: https://${LITESTREAM_R2_ENDPOINT}
        retention: 8760h
        snapshot-interval: 6h

  - path: /data/landing/.state.sqlite
    replicas:
      - url: s3://${LITESTREAM_R2_BUCKET}/padelnomics/state.sqlite
        access-key-id: ${LITESTREAM_R2_ACCESS_KEY_ID}
        secret-access-key: ${LITESTREAM_R2_SECRET_ACCESS_KEY}
        endpoint: https://${LITESTREAM_R2_ENDPOINT}
        retention: 8760h
        snapshot-interval: 24h
