You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: docs/design/schema-compatibility.md
+36-35
Original file line number
Diff line number
Diff line change
@@ -2,38 +2,36 @@
2
2
3
3
Schema changes can cover a wide range of modifications with varying impacts on application compatibility and data integrity. Below are use cases with strategies to manage schema changes and ensure compatibility.
4
4
5
-
## Multiple versions can live in parallel
5
+
## I. Multiple versions can live in parallel
6
6
7
-
### Strategy for Compatible Changes
7
+
### 1. Strategy for Compatible Changes
8
8
9
9
For changes that are backward-compatible, such as adding optional fields or extending enumerations.
10
10
11
-
**Description:**
12
-
13
-
Add an optional version field to all DCL schema to track the schema version.
11
+
#### Option A: Add an optional version field to all DCL schema
14
12
15
-
This strategy is straightforward and quick to implement, but only suitable for compatible changes.
13
+
**Description:**
14
+
Implement an optional version field in all DCL schemas to track the schema version. This approach is simple and quick to execute, suitable primarily for compatible updates.
16
15
17
16
**Strategy steps:**
18
17
19
18
- One time actions:
20
19
- Add an optional version field to all DCL schema
21
20
- For each update:
22
21
- Update the schema by introducing compatible changes (such as adding a new optional field).
23
-
- Update update transactions and queries if needed.
22
+
- Update transactions and queries if needed.
24
23
- DCL doesn't fulfill the Schema version automatically
25
24
- It will be up to the transaction submitter (Vendor) to specify a correct Schema version
26
25
- If Schema Version is not set - then the initial version (version 0 or 1) is assumed
27
26
- It will be up to the client application to process the Schema version
28
27
29
-
### Strategy for Non-Compatible Changes
28
+
### 2. Strategy for Non-Compatible Changes
30
29
31
30
For significant changes that directly impact compatibility, such as adding mandatory fields or removing fields, splitting or merging schemas, changing enumerations.
32
31
33
-
#### Option 1: Separate Schemas for Each Version
32
+
#### Option B: Separate Schemas for Each Version
34
33
35
34
**Description:**
36
-
37
35
Each version has its distinct schema, state and its own queries/requests. This strategy eliminates the need for data migration and allows different schema versions to coexist seamlessly.
38
36
39
37
**Strategy steps:**
@@ -42,10 +40,9 @@ Each version has its distinct schema, state and its own queries/requests. This s
42
40
- Create a new version of a Schema and state (a new .proto file)
43
41
- Implement transactions and queries for the new schema version.
44
42
45
-
#### Option 2: Generic Schema Storage (Not Recommended for Production)
43
+
#### Option C: Generic Schema Storage (Not Recommended for Production)
46
44
47
45
**Description:**
48
-
49
46
Implement a flexible, generic schema structure that can support a wide range of data formats.
50
47
51
48
While offering a robust solution for handling radical changes, this method requires careful planning and development, which can potentially take a significant amount of time.
@@ -61,14 +58,15 @@ While offering a robust solution for handling radical changes, this method requi
61
58
- Create a new Schema version (a new .proto file)
62
59
- Implement transactions and queries that can handle data according to its version, including mechanisms for converting generic values into the corresponding schema version.
63
60
64
-
## New version replaces the legacy one (V2 replaces V1)
61
+
## II. New version replaces the legacy one (V2 replaces V1)
65
62
66
-
### Strategy for Compatible changes (Not keeping backward compatibility in API)
63
+
### 1. Strategy for Compatible or Convertible changes
67
64
68
-
For changes that are backward-compatible, such as adding optional fields or extending enumerations.
65
+
For changes that are backward-compatible, such as adding optional or mandatory fields or extending enumerations
69
66
70
-
**Description:**
67
+
#### Option D: Not keeping backward compatibility in API
71
68
69
+
**Description:**
72
70
This strategy focuses on updating the schema without ensuring backward compatibility at the API level. Since the schemas are compatible, there will likely be no need for migration.
73
71
74
72
**Strategy steps:**
@@ -78,27 +76,9 @@ This strategy focuses on updating the schema without ensuring backward compatibi
78
76
- Migrate old states to the newer if needed.
79
77
- Update transactions and queries if needed.
80
78
81
-
### Strategy for Non-Compatible changes (Not keeping backward compatibility in API)
82
-
83
-
For changes that affect compatibility, like adding mandatory fields.
79
+
#### Option E: Keeping backward compatibility in API
84
80
85
81
**Description:**
86
-
87
-
This strategy focuses on updating the schema without ensuring backward compatibility at the API level. Since the schemas are not compatible, migration is carried out manually through a special transaction.
88
-
89
-
**Strategy steps:**
90
-
91
-
- For each update:
92
-
- Update the schema by introducing changes.
93
-
- Update transactions and queries if needed.
94
-
- Add a new transaction to fulfill new required fields (essentially this is a manual migration via transactions)
95
-
96
-
### Strategy for Non-Compatible changes (Keeping backward compatibility in API)
97
-
98
-
For changes that affect compatibility but can be converted, adding mandatory fields and changing enumerations.
99
-
100
-
**Description:**
101
-
102
82
The main idea of this strategy is the dynamically converting newer schemas into older ones. However, this method is only possible if there is compatibility between the newer and legacy schemas, allowing them to be converted to each other. Due to the on-the-fly data conversion, this approach does not support the Light Client in legacy APIs because the converted data is not stored in the state, preventing the generation of proofs.
103
83
104
84
**Strategy steps:**
@@ -114,6 +94,27 @@ The main idea of this strategy is the dynamically converting newer schemas into
114
94
- modelsV2/vid/pid
115
95
- modelsV3/vid/pid
116
96
97
+
### 2. Strategy for Non-Compatible changes
98
+
99
+
For significant changes that directly impact compatibility, such as adding mandatory fields or removing fields, splitting or merging schemas, changing enumerations.
100
+
101
+
#### Optiona F: Not keeping backward compatibility in API
102
+
103
+
**Description:**
104
+
This strategy focuses on updating the schema without ensuring backward compatibility at the API level. Since the schemas are not compatible, migration is carried out manually through a special transaction.
105
+
106
+
**Strategy steps:**
107
+
108
+
- For each update:
109
+
- Update the schema by introducing changes.
110
+
- Update transactions and queries if needed.
111
+
- Add a new transaction to fulfill new required fields (essentially this is a manual migration via transactions)
112
+
113
+
#### Option G: Keeping backward compatibility in API
114
+
115
+
**Description:**
116
+
It's not possible to replace an old version here. [Multiple versions can live in parallel: Strategy for Non-Compatible Changes](#2-strategy-for-non-compatible-changes) options should be used instead.
117
+
117
118
## Conclusion
118
119
119
120
To lay the foundation for future compatibility improvements, it's a good idea to start by adding a version field to each schema. For subsequent changes, we will then select the most appropriate strategy based on the nature of these changes.
0 commit comments