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
Add schema versioning, upgrade compatibility checking, and auto-migration
Introduces a schema introspection and diff engine that detects breaking
changes between entity versions and rejects upgrades that lack a migrate()
method. Safe changes (new fields with defaults) are auto-migrated without
developer intervention.
Closes#8
Co-authored-by: Cursor <cursoragent@cursor.com>
Copy file name to clipboardExpand all lines: README.md
+86Lines changed: 86 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ A lightweight key-value database with entity relationships and audit logging cap
12
12
13
13
-**Persistent Storage**: Works with StableBTreeMap stable structure for persistent storage on your canister's stable memory so your data persists automatically across canister upgrades.
14
14
-**Entity-Relational Database**: Create, read and write entities with OneToOne, OneToMany, ManyToOne, and ManyToMany relationships.
15
+
-**Schema Versioning & Upgrade Safety**: Automatic schema introspection, compatibility checking, and auto-migration for safe changes. Breaking changes without a `migrate()` method are rejected, preventing data corruption on canister upgrades.
15
16
-**Entity Hooks**: Intercept and control entity lifecycle events (create, modify, delete) with `on_event` hooks.
16
17
-**Access Control**: Thread-safe context management for user identity tracking and ownership-based permissions.
17
18
-**Namespaces**: Organize entities into namespaces to avoid type conflicts when you have multiple entities with the same class name.
ic-python-db includes built-in upgrade compatibility checking. The system introspects your Entity class definitions to detect schema changes and ensure safe upgrades.
274
+
275
+
### Auto-migration for safe changes
276
+
277
+
Adding a field with a default value requires no migration code — the system handles it automatically:
278
+
279
+
```python
280
+
# v1
281
+
classProduct(Entity):
282
+
__version__=1
283
+
name = String()
284
+
285
+
# v2 — just add the field with a default, no migrate() needed
286
+
classProduct(Entity):
287
+
__version__=2
288
+
name = String()
289
+
price = Float(default=0.0) # auto-injected for existing entities
290
+
active = Boolean(default=True) # auto-injected for existing entities
291
+
```
292
+
293
+
### Custom migration for breaking changes
294
+
295
+
For type changes, field renames, or data transformations, override `migrate()`:
296
+
297
+
```python
298
+
classProduct(Entity):
299
+
__version__=2
300
+
name = String()
301
+
price_dollars = Float() # was price_cents: Integer in v1
0 commit comments