[Anvil Server] Running 2 Anvil apps from the same directory with auto-migrate wipes the database

What I’m trying to do:
Run 2 apps from the same directory and on the same port (at different times of course)

What I’ve tried and what’s not working:
I can definitely run both apps alternating from the same directory, but run into issues with the database schemas overlapping for some reason:

  1. Run App A that has a database. Add some rows just to see that the database isn’t empty.
  2. Shut down App A.
  3. Run App B that doesn’t have a database (Anvil Extras in my case).
  4. Error because of a mismatch of database schema (I don’t know why since Extras doesn’t use the database).
  5. Shut down App B
  6. Restart App B with --auto-migrate
  7. Shutdown App B again
  8. Rerun App A
  9. Check for the rows added above
  10. See that the whole database has been deleted.

I know I could run it with --ignore-invalid-schema – which I will certainly do now – but it seems that the database of an app run from the same directory shouldn’t be cleared by running another app there too.

This is not an issue if the two app folders live in the same directory, but are run within the app folder itself with --app .

Any thoughts on whether this is a big or of there’s some other cause?

I think that the anvil_app_server assumes that it is running a single app so it will overwrite the db. If you want to use the same app server, but keep the databases separate, then you can use the

--data-dir DIRECTORY

To point to different database folders. That would keep the database from overwriting itself.

Maybe App A uses the default but App B uses --data-dir ./appb_data

3 Likes