How don't remove data in the sync table during syncing

Hi guys!

I have this architecture on my tables. All data for the tables come from API.
image

In the table “Tasks” I have reference to the user. For this action I use the “Lookup()” formula.

Sometimes people in the table “Users” can be removed on the API side. After syncing the user removing in the table too. But the Tasks table has a reference to the removed user. After syncing I see an empty array image in the needed row.
How I can allow only adding and updating data in the Users table during syncing and deny removing rows in the table?
Could you share some links to documentation, please? Maybe I miss something.

The Users table was created using this way:

pack.addSyncTable({
  name: "Users",
  schema: schema.UsersSchema,
  identityName: "Users",
  formula: {
    name: "Users",
    description: "Sync Users",
    parameters: [],
    execute: async function ([], context) {
      let response = await fetcher.getUsers(context);
      let results = [];
      for (let user of response['users']) {
        results.push({
          id: user.id,
          firstname: user.firstname ?? null,
          lastname: user.lastname ?? null,
          mail: user.mail ?? null,
        });
      }
      return {
        result: results,
      };
    },
  },
});

Thank you!

There’s a user-side preference for how to handle deletions in a sync table (keep them, or discard them):

The only way I can think of to impact this from the server side though, is to create your own intermediary server where you’re caching all the data in your own DB, and using that to fill in the deleted records. So I’d lean toward instructing users about the preference.

3 Likes

Another option is to use reference schemas in your sync table rather than the Lookup() formula. Reference schemas shown a grayed-out chip for broken references and allow you to assign some custom text (“Not found” in the example below).

image