Skip to content

Commit d78cfbf

Browse files
committed
Change the structure of the schema compatibility document
1 parent a202f16 commit d78cfbf

File tree

1 file changed

+36
-35
lines changed

1 file changed

+36
-35
lines changed

docs/design/schema-compatibility.md

+36-35
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,36 @@
22

33
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.
44

5-
## Multiple versions can live in parallel
5+
## I. Multiple versions can live in parallel
66

7-
### Strategy for Compatible Changes
7+
### 1. Strategy for Compatible Changes
88

99
For changes that are backward-compatible, such as adding optional fields or extending enumerations.
1010

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
1412

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.
1615

1716
**Strategy steps:**
1817

1918
- One time actions:
2019
- Add an optional version field to all DCL schema
2120
- For each update:
2221
- 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.
2423
- DCL doesn't fulfill the Schema version automatically
2524
- It will be up to the transaction submitter (Vendor) to specify a correct Schema version
2625
- If Schema Version is not set - then the initial version (version 0 or 1) is assumed
2726
- It will be up to the client application to process the Schema version
2827

29-
### Strategy for Non-Compatible Changes
28+
### 2. Strategy for Non-Compatible Changes
3029

3130
For significant changes that directly impact compatibility, such as adding mandatory fields or removing fields, splitting or merging schemas, changing enumerations.
3231

33-
#### Option 1: Separate Schemas for Each Version
32+
#### Option B: Separate Schemas for Each Version
3433

3534
**Description:**
36-
3735
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.
3836

3937
**Strategy steps:**
@@ -42,10 +40,9 @@ Each version has its distinct schema, state and its own queries/requests. This s
4240
- Create a new version of a Schema and state (a new .proto file)
4341
- Implement transactions and queries for the new schema version.
4442

45-
#### Option 2: Generic Schema Storage (Not Recommended for Production)
43+
#### Option C: Generic Schema Storage (Not Recommended for Production)
4644

4745
**Description:**
48-
4946
Implement a flexible, generic schema structure that can support a wide range of data formats.
5047

5148
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
6158
- Create a new Schema version (a new .proto file)
6259
- Implement transactions and queries that can handle data according to its version, including mechanisms for converting generic values into the corresponding schema version.
6360

64-
## New version replaces the legacy one (V2 replaces V1)
61+
## II. New version replaces the legacy one (V2 replaces V1)
6562

66-
### Strategy for Compatible changes (Not keeping backward compatibility in API)
63+
### 1. Strategy for Compatible or Convertible changes
6764

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
6966

70-
**Description:**
67+
#### Option D: Not keeping backward compatibility in API
7168

69+
**Description:**
7270
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.
7371

7472
**Strategy steps:**
@@ -78,27 +76,9 @@ This strategy focuses on updating the schema without ensuring backward compatibi
7876
- Migrate old states to the newer if needed.
7977
- Update transactions and queries if needed.
8078

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
8480

8581
**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-
10282
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.
10383

10484
**Strategy steps:**
@@ -114,6 +94,27 @@ The main idea of this strategy is the dynamically converting newer schemas into
11494
- modelsV2/vid/pid
11595
- modelsV3/vid/pid
11696

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+
117118
## Conclusion
118119

119120
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

Comments
 (0)