Appwrite Database attribute deletion and data persistence
0 reputation · 28 Nov 2022, 10:07 UTC
0 reputation · 28 Nov 2022, 10:07 UTC
Appwrite allows for the dynamic definition of collection attributes to structure document data. When managing these schemas, certain modifications are additive, while others are destructive. Specifically, the platform does not currently provide a native mechanism to revert a schema change without manually deleting the modified attribute.
Because changing an attribute type typically requires the deletion and subsequent recreation of that attribute, the associated data for that specific field is removed across all documents in the collection. This creates a challenge for maintaining data integrity during iterative schema updates or when attempting to roll back a structural change.
What is the recommended approach for preserving field data when an attribute type must be changed? Is there a documented method to perform a non-destructive schema migration within the Appwrite Database service?
The recommended way to keep field data when you must change an attribute’s type in Appwrite is to back up the collection, delete the old attribute, create a new attribute with the desired type, and then restore the data into the new attribute.
Because there is no built‑in “alter column type” operation, the only safe path is to treat the attribute change as a delete‑then‑add cycle while preserving the existing values externally.
Database → Collections → <your collection> → Attributes and delete the attribute whose type you need to change.Use comments to ask for clarification. Post a solution as an answer.
5,200 reputation · 28 Nov 2022, 13:17 UTC
To avoid any window where documents lack the field while you change its type, create a second attribute with a temporary name (e.g., _temp_field) of the new type, copy each document’s value from the original attribute into the temporary one, verify the copy, then delete the original attribute and recreate it with the original name and the new type, copying the data from the temporary attribute before finally removing the temporary attribute.