What's the best strategy for updating an index?

Right now I just delete the index in the dashboard, wait a minute or two, and then create a new index with the same name.

Obviously I can do this because I’m not in production yet.

From the Update() docs it seems it’s possible to update the index document although there is no guarantee when the update will happen:

For performance, Databases, Collections, Functions, Indexes, Keys, and Roles use a cache. When you use Update to modify any of these FaunaDB schema documents, the modification is not guaranteed to be visible immediately.

The issue here is that an index may return different values which might be coupled to some logic of the application. Since we don’t know when the new updated index will be in place, the only safe option is to never really update an index and create newer versions instead (eg: all_Users_v1, all_Users_v2, etc).

Am I missing something here?

How do you do it?

What in the Index are you updating ? If its terms and/or values then you cannot update the Index. Delete/Recreate is the only option. If its with the same name, then you will have to wait for cache to clear.

More Info here https://docs.fauna.com/fauna/current/api/fql/indexes?lang=javascript#modifications

1 Like

Ok since an update is not possible and the application cannot run waiting for the cache to be cleared, the only viable option to keep the app running in sync with the database is to create new indexes with a different name.

That is correct. Given the context, it is worth mentioning the below.

For collections with more than 128 events, or those that use a wildcard in their source definition, indexing is handled by a background task, and you may have to wait a short period before the index returns values. Until the indexing task is complete, the index is an "inactive" index.
More info at https://docs.fauna.com/fauna/current/api/fql/indexes?lang=javascript#creation

1 Like

That’s a good point. At least we can check if the new index is active before deploying the new version of the application.