Hi!
I’ve been trying to find a solution to my concerns about data loss when the canister data model changes.
Let me explain the idea briefly (please feel free to critique it). Here’s how I’m thinking, illustrated with an example.
I chose to keep everything in text format to avoid dependencies and the need for parsing data, thus reducing the risk of errors when saving or retrieving data.
Although this approach may not offer optimal performance, I’ve made an exception for the created and updated timestamps which are Numbers. You can offcource add createdBy and uppdatedBy, but I recomend to add those as attribute.
Here is my model
DataObject = {
id: Text,
parent_id: Text,
type: Text,
path: Text, // path is the name of the object it self, it can ve a vehicle, human, or any kind of object
owner_id: Text,
status: Text, // You may want to flag the object with any kind of status, like DELETED, BLOCKED, HIDDEN, NOTACTIVE, …
created: Int,
updated: Int,
attributes: [Attribute]
};
Attribute = {
id: Text,
parent_id: Text,
status: Text, // Same as DataObject.status
type: Text,
name: Text, // name, value pair
value: Text, // name, value pair
created: Int,
updated: Int
};
Below simple example how to use it,
let userDataObject: DataObject = {
id: “user123”,
parent_id: “”,
type: “User”,
path: “User”,
owner_id: “admin”,
status: “Active”,
created: 1632654400, // October 1, 2021
updated: 1632654500, // 100 seconds later
attributes: [
{ id: “user123_name”, parent_id: “user123”, status: “Active”, type: “string”, name: “name”, value: “John Doe”, created: 1632654400, updated: 1632654400 },
{ id: “user123_age”, parent_id: “user123”, status: “Active”, type: “int”, name: “age”, value: “30”, created: 1632654400, updated: 1632654400 },
{ id: “user123_email”, parent_id: “user123”, status: “Active”, type: “string”, name: “email”, value: “john@example.com”, created: 1632654400, updated: 1632654400 }
]
};
Please try to break it with more complext objects like
Object { id: ‘’, property1: AnotherObject, property2: ReferenceToAnotherObject, property3: ListOfObject, …} etc