Skip to content

Commit 004b6dd

Browse files
author
qwe7002
committed
docs: remove outdated Data Structure Version Management guide
1 parent 1119a6b commit 004b6dd

4 files changed

Lines changed: 64 additions & 130 deletions

File tree

.vitepress/config.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export default defineConfigWithTheme<ExtendedConfig>({
3535
items: [
3636
{ text: "Crypto Module Documentation", link: "/CRYPTO_DOC" },
3737
{ text: "Data Structure Version Management", link: "/DATA_STRUCTURE_VERSION" },
38-
{ text: "Data Structure - Quick Guide", link: "/DATA_STRUCTURE_VERSION_QUICK" },
3938
{ text: "Self-hosted Bot API", link: "/self_hosted_bot_api" },
4039
{ text: "Carbon Copy Provider Implementation", link: "/CarbonCopyProvider" },
4140
{ text: "String Resources Organization", link: "/STRING_RESOURCES" },

docs/DATA_STRUCTURE_VERSION.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,67 @@ This data structure version management system automatically handles application
1616
4. **Data Backup**: Provides data backup functionality to ensure safe migration
1717
5. **Extensibility**: Easy to add new version migration logic
1818

19+
## Quick Start
20+
21+
The system is automatically integrated into the application — no additional configuration is required. Data migration checks and execution happen automatically on each app startup.
22+
23+
### When to upgrade the version?
24+
25+
Upgrade the data structure version whenever you need to:
26+
27+
1. ✅ Add new configuration fields
28+
2. ✅ Modify existing field data types (e.g., `String``Long`)
29+
3. ✅ Remove unused fields
30+
4. ✅ Reorganize data into different storage locations
31+
5. ✅ Modify data formats or structures
32+
33+
### Add a new version in 3 steps
34+
35+
```kotlin
36+
// Step 1 — bump the version in DataMigrationManager.kt
37+
const val CURRENT_DATA_VERSION = 2 // Change from 1 to 2
38+
39+
// Step 2 — add a migration case in performMigration()
40+
when (nextVersion) {
41+
1 -> migrateToVersion1(context, MMKV.defaultMMKV())
42+
2 -> migrateToVersion2(context, MMKV.defaultMMKV()) // Add this line
43+
}
44+
45+
// Step 3 — implement the migration function
46+
private fun migrateToVersion2(context: Context, preferences: MMKV) {
47+
Log.d(TAG, "Migrating to version 2")
48+
if (!preferences.contains("new_setting")) {
49+
preferences.putBoolean("new_setting", false)
50+
}
51+
}
52+
```
53+
54+
### Common migration patterns
55+
56+
```kotlin
57+
// 1. Add a new field
58+
if (!preferences.contains("new_field")) {
59+
preferences.putBoolean("new_field", false)
60+
}
61+
62+
// 2. Convert a data type
63+
val oldValue = preferences.getString("chat_id", "")
64+
if (oldValue.isNotEmpty()) {
65+
preferences.putLong("chat_id_long", oldValue.toLong())
66+
}
67+
68+
// 3. Remove an old field
69+
preferences.remove("deprecated_field")
70+
71+
// 4. Migrate to a new MMKV instance
72+
val settingsMMKV = MMKV.mmkvWithID("settings")
73+
settingsMMKV.putString("setting_key", MMKV.defaultMMKV().getString("setting_key", ""))
74+
```
75+
76+
> ⚠️ Increment the version by 1 for every data-structure change, make migration logic handle **all** older versions, test thoroughly, and document each change.
77+
>
78+
> The sections below cover the same workflow in detail, plus the API reference, version history, fuller scenarios, and troubleshooting.
79+
1980
## Usage
2081

2182
### Initialization
@@ -179,6 +240,8 @@ Reset data structure version. **Warning**: Use with caution, may cause data inco
179240

180241
## Example Scenarios
181242

243+
For runnable, practical examples, also see `MigrationExamples.kt` alongside `DataMigrationManager.kt`.
244+
182245
### Scenario 1: Adding New Feature Requiring New Field
183246

184247
```kotlin

docs/DATA_STRUCTURE_VERSION_QUICK.md

Lines changed: 0 additions & 128 deletions
This file was deleted.

docs/instructions/project.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ When making significant changes to the codebase, AI assistants should create or
458458
- Explain rationale for changes
459459

460460
3. **API Changes**: When changing APIs or data structures:
461-
- Update `DATA_STRUCTURE_VERSION.md` or `DATA_STRUCTURE_VERSION_QUICK.md`
461+
- Update `DATA_STRUCTURE_VERSION.md`
462462
- Document breaking changes
463463
- Provide migration guides
464464

0 commit comments

Comments
 (0)