In this setup, each of my apps, production and staging, have their own sqlite.db file hence their own data.
Is it possible to point both my production and staging apps at the same database file, so they reuse the same data? I know LiteFS can be distributed within the same app by scaling up a primary instance to multiple replicas. My question is based on entirely different apps (potentially created on different Fly accounts). Another use-case might be I want to use production data in my local environment.
With Postgres or Mongo I would just reuse the same connection string or database URL on each app. What is the equivalent here?
I’m still not clear though on whether this is up-to-date, and how to go about implementing this. What is the unique DB identifier each app needs to point to?
If you want to do the same as you do with Postgres or Mongo, and solve the different Fly accounts issue, you can use Query (I’m the author).
Query is a Rust server for your remote SQLite databases and a CLI to manage them.
To set up a staging environment, you can create a branch from a production database and work with it. Essentially, a branch is a copy of the database that allows you to use the same data as in the production database and make modifications to it without affecting your production environment. This ensures that any changes you make can be safely tested and refined before being implemented in the live environment.
hey @gcv, thanks a lot for the answer. No worries on the plug, I need something just like Query Studio! I’ll check it out as soon as I get this working.
I attempted to reuse the same key and FLY_CONSUL_URL as per Ben’s suggestion, but am now getting this error: cannot connect, \"consul\" lease already initialized with different ID: LFSC829A040769612D30
Here are my Fly logs:
bos [info] INFO Preparing to run: `docker-entrypoint.sh litefs mount` as root
bos [info] INFO [fly api proxy] listening at /.fly/api
bos [info]2023/10/30 11:23:58 listening on [fdaa:0:56a6:a7b:ec:e3ea:6ad6:2]:22 (DNS: [fdaa::3]:53)
bos [info]config file read from /etc/litefs.yml
bos [info]LiteFS v0.5.0, commit=39b247aa6b5b9cce970cccd61d0024c6f32aa732
bos [info]level=INFO msg="host environment detected" type=fly.io
bos [info]level=INFO msg="no backup client configured, skipping"
bos [info]level=INFO msg="Using Consul to determine primary"
bos [info]level=INFO msg="initializing consul: key=litefs/remilia-platform-0aa9-v2 url=https://:a38b2643-48e3-ef03-c8eb-54e06346320a@consul-iad-8.fly-shared.net/remilia-platform-0aa9-yexkqwo03kn1m38d/ hostname=e2865517fe5078 advertise-url=http://e2865517fe5078.vm.remilia-platform-0aa9.internal:20202"
bos [info]level=INFO msg="wal-sync: no wal file exists on \"cache.db\", skipping sync with ltx"
bos [info]level=INFO msg="wal-sync: no wal file exists on \"sqlite.db\", skipping sync with ltx"
bos [info]level=INFO msg="LiteFS mounted to: /litefs/data"
bos [info]level=INFO msg="http server listening on: http://localhost:20202"
bos [info]level=INFO msg="waiting to connect to cluster"
bos [info]level=INFO msg="cannot connect, \"consul\" lease already initialized with different ID: LFSC829A040769612D30"
bos [info]level=INFO msg="cannot connect, \"consul\" lease already initialized with different ID: LFSC829A040769612D30"
bos [info]level=INFO msg="cannot connect, \"consul\" lease already initialized with different ID: LFSC829A040769612D30"
bos [info]level=INFO msg="cannot connect, \"consul\" lease already initialized with different ID: LFSC829A040769612D30"
bos [info]level=INFO msg="cannot connect, \"consul\" lease already initialized with different ID: LFSC829A040769612D30"
Restoring the candidate and advertise-url fields to their original values didn’t seem to make a difference, I’m still getting the same “lease already initialized” error.