Skip to content

Commit

Permalink
feat: add model upgrades page (#385)
Browse files Browse the repository at this point in the history
Co-authored-by: glihm <[email protected]>
  • Loading branch information
remybar and glihm authored Feb 5, 2025
1 parent e5b969e commit f4e8dda
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
53 changes: 53 additions & 0 deletions docs/pages/framework/models/upgrades.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Upgrades models in Dojo
description: Learn how to upgrade models in Dojo.
---

# Upgrades

In Dojo, all models are upgradeable, which means that when their code changes, they are redeployed
to the same address, preserving the existing model storage and therefore the existing model data.

However, to be able to preserve existing model data, there are some limitations.

## General rules

- To be upgradeable, the layout of a model must not be packed (using `IntrospectPacked`).

- For composite data structures like `struct`, `enum`, `tuple` and `array`
- they are upgreadable as soon as all their elements are upgreadable,
- existing elements cannot be removed, they can only be modified according to the rules described
on this page. New elements can be freely added.

- Each element of a data structure must keep the same type (i.e a `tuple` must remain a `tuple`), the same name and
the same attributes if any (such as `#[key]` for model members).

- A primitive type can be upgraded to a larger primitive type as soon as its felt252 representation uses the same number of felts
(for example, `u8` to `u128` but not `u128` to `u256`). See the next chapter for more details.

- A key model member is upgradeable only if its type is an upgreadable primitive or an enum with new variants only (existing variants cannot be
modified for a key member).

## Primitive upgrades

This table lists the allowed upgrades for every primitive types.
The type `usize` is not supported since it is a architecture-dependent type.

| Current | Allowed upgrades |
| --------------- | ---------------- |
| bool | bool, felt252 |
| u8 | u8 to u128, felt252 |
| u16 | u16 to u128, felt252 |
| u32 | u32 to u128, felt252 |
| u64 | u64 and u128, felt252 |
| u128 | u128, felt252 |
| u256 | u256 |
| i8 | i8 to i128, felt252 |
| i16 | i16 to i128, felt252 |
| i32 | i32 to i128, felt252 |
| i64 | i64 and i128, felt252 |
| i128 | i128, felt252 |
| felt252 | felt252, ClassHash, ContractAddress |
| ClassHash | felt252, ClassHash, ContractAddress |
| ContractAddress | felt252, ClassHash, ContractAddress |
| EthAddress | felt252, ClassHash, ContractAddress, EthAddress |
1 change: 1 addition & 0 deletions routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export const routes = [
},
{ text: "Entities", link: "/framework/models/entities" },
{ text: "Enum", link: "/framework/models/enum" },
{ text: "Upgrades", link: "/framework/models/upgrades" },
],
},
{
Expand Down

0 comments on commit f4e8dda

Please sign in to comment.