[App Server] Using anvil.yaml db_schema

I’m trying to make some edits to our database by editing the db_schema section in anvil.yaml. The schema is pretty self-explanatory and the edits seem to work. If I run anvil-app-server locally (migrating or rebuilding the database), I get the expected results. But, I want to check that I’m not doing something that will cause unexpected issues later. I have a couple of questions:

  1. The tables in the database have unique integer id’s, e.g.
- name: MyTable
  id: 1

These id’s are not contiguous (I have a table 1 and a table 31, but no table 2). Are these numbers unique to my app? Are they perhaps unique to our team’s account on the our enterprise Anvil server? In other words, if I pick a random unused integer and push my changes up to our server, could I potentially mess up another app’s data on the server?

  1. The column identifiers look like random strings of length 12, e.g.
columns:
  KQh8MDOa1aQ=:
  name: my_column

But they are not quite random. Is there any significance to the fact that these identifiers always seem to end with “=”? If I pick a random string I’d have to be pretty unlucky to get a name conflict, but is it possible for me to pick a bad identifier?

Thanks for any help!

Any time there’s a program that assigns its own ID (numeric or text) to something, I always leave that ID alone. Unless you’re the author of that program, there’s no telling what else is tied to that ID, deep in the guts of the system.

These distinct IDs allow tables to be shared among different Anvil Apps, and potentially to have a different name in each App, e.g., to resolve conflicts with an App’s existing tables. (Each App also has a unique ID.)

Regarding column IDs, I recognize the encoding as a variant of Base64 (6 bits per character). It ends that way because it is encoding a 64-bit integer; and 64 is not a multiple of 6.

Again, this looks like a machine-assigned ID. Whatever program creates and maintains these, it would be wise to keep using it.

In my case, it’s the Anvil IDE – or something behind the IDE, running on Anvil’s servers. So I use the IDE to maintain and change schemas.

This way, if the table descriptor structure changes – which I’m sure has already happened – Anvil takes care of the details for me.

Thanks @p.colbert! That’s helpful.

I’m not going to change any existing IDs, but I was hoping to be able to add new tables and columns offline, which involves adding new IDs. I’d like to be able to do it offline if it’s safe to do so. You are right, using the Anvil IDE would be a more guaranteed safe way to do this.

It also raises the question of what happens if it becomes necessary to migrate a project from one Anvil server to another. Presumably table IDs only make sense in the context of the server that created them.

I think this may already be happening. That is, you’re already migrating schemas from one server (Anvil’s) to another (your own).

I agree, but I was speculating more on what happens when you try to migrate into a server that has other pre-existing apps on it. Our standalone runtimes are only running the one app, so there’s no chance of (for instance) a table ID collision, if such a thing is possible.

If all the schemas are maintained in the IDE, then (by definition?) they can’t conflict with each other. So this might be one route to go.