@@ -3,7 +3,7 @@ title: CLI Commands
33description : Complete reference for all LUMOS CLI commands
44---
55
6- The LUMOS CLI (` lumos ` ) provides four main commands for working with ` .lumos ` schema files .
6+ The LUMOS CLI (` lumos ` ) provides commands for code generation, validation, and schema evolution .
77
88## Installation
99
@@ -312,6 +312,254 @@ jobs:
312312
313313---
314314
315+ ## Schema Evolution Commands
316+
317+ These commands help you manage schema changes and migrations between versions.
318+
319+ ### ` lumos diff`
320+
321+ Compare two schema files and show differences.
322+
323+ # ### Usage
324+
325+ ` ` ` bash
326+ lumos diff <SCHEMA1> <SCHEMA2> [OPTIONS]
327+ ` ` `
328+
329+ # ### Arguments
330+
331+ - ` <SCHEMA1>` - Path to the first (older) schema file
332+ - ` <SCHEMA2>` - Path to the second (newer) schema file
333+
334+ # ### Options
335+
336+ | Option | Short | Description | Default |
337+ |--------|-------|-------------|---------|
338+ | `--format` | `-f` | Output format (`text` or `json`) | `text` |
339+ | `--help` | `-h` | Print help information | - |
340+
341+ # ### Examples
342+
343+ **Compare two versions:**
344+ ` ` ` bash
345+ lumos diff schema-v1.lumos schema-v2.lumos
346+ ` ` `
347+
348+ **Output (text):**
349+ ```
350+ Schema Differences
351+ ==================
352+
353+ + Added struct: PlayerStats
354+ - level: u16
355+ - experience: u64
356+
357+ ~ Modified struct: PlayerAccount
358+ + Added field: stats (PlayerStats)
359+ - Removed field: score (u32)
360+
361+ - Removed enum: OldStatus
362+ ```
363+
364+ **JSON output for scripting:**
365+ ```bash
366+ lumos diff schema-v1.lumos schema-v2.lumos --format json
367+ ```
368+
369+ ``` json
370+ {
371+ "added" : [
372+ { "type" : " struct" , "name" : " PlayerStats" }
373+ ],
374+ "modified" : [
375+ {
376+ "type" : " struct" ,
377+ "name" : " PlayerAccount" ,
378+ "changes" : {
379+ "added_fields" : [" stats" ],
380+ "removed_fields" : [" score" ]
381+ }
382+ }
383+ ],
384+ "removed" : [
385+ { "type" : " enum" , "name" : " OldStatus" }
386+ ]
387+ }
388+ ```
389+
390+ ---
391+
392+ ### ` lumos check-compat `
393+
394+ Check backward compatibility between two schema versions.
395+
396+ #### Usage
397+
398+ ``` bash
399+ lumos check-compat < FROM_SCHEMA> < TO_SCHEMA> [OPTIONS]
400+ ```
401+
402+ #### Arguments
403+
404+ - ` <FROM_SCHEMA> ` - Path to the old schema file (v1)
405+ - ` <TO_SCHEMA> ` - Path to the new schema file (v2)
406+
407+ #### Options
408+
409+ | Option | Short | Description | Default |
410+ | --------| -------| -------------| ---------|
411+ | ` --format ` | ` -f ` | Output format (` text ` or ` json ` ) | ` text ` |
412+ | ` --verbose ` | ` -v ` | Show detailed explanations | ` false ` |
413+ | ` --strict ` | ` -s ` | Treat warnings as errors | ` false ` |
414+ | ` --help ` | ` -h ` | Print help information | - |
415+
416+ #### Examples
417+
418+ ** Check compatibility:**
419+ ``` bash
420+ lumos check-compat schema-v1.lumos schema-v2.lumos
421+ ```
422+
423+ ** Output (compatible):**
424+ ```
425+ ✓ Schema is backward compatible
426+
427+ Changes detected:
428+ - Added optional field: PlayerAccount.nickname (Option<String>)
429+ - Added struct: AchievementData
430+
431+ These changes are safe for existing on-chain accounts.
432+ ```
433+
434+ ** Output (breaking changes):**
435+ ```
436+ ✗ Schema has breaking changes
437+
438+ Breaking changes detected:
439+ ✗ Changed field type: PlayerAccount.score (u32 → u64)
440+ Reason: Different byte size (4 → 8 bytes)
441+ Impact: Existing accounts cannot be deserialized
442+
443+ ✗ Removed field: PlayerAccount.legacy_data
444+ Reason: Field removal changes Borsh layout
445+ Impact: Data corruption on deserialization
446+
447+ Run 'lumos migrate' to generate migration code.
448+ ```
449+
450+ ** Verbose mode for CI/CD:**
451+ ``` bash
452+ lumos check-compat old.lumos new.lumos --verbose --strict
453+ ```
454+
455+ #### Use Cases
456+
457+ 1 . ** Pre-merge check** - Validate schema changes in PR
458+ 2 . ** Release validation** - Ensure new version won't break production
459+ 3 . ** CI/CD pipeline** - Automated compatibility testing
460+
461+ #### Example: GitHub Actions
462+
463+ ``` yaml
464+ - name : Check Schema Compatibility
465+ run : |
466+ lumos check-compat main-schema.lumos pr-schema.lumos --strict
467+ ` ` `
468+
469+ ---
470+
471+ ### ` lumos migrate`
472+
473+ Generate migration code from one schema version to another.
474+
475+ # ### Usage
476+
477+ ` ` ` bash
478+ lumos migrate <FROM_SCHEMA> <TO_SCHEMA> [OPTIONS]
479+ ` ` `
480+
481+ # ### Arguments
482+
483+ - ` <FROM_SCHEMA>` - Path to the old schema file (v1)
484+ - ` <TO_SCHEMA>` - Path to the new schema file (v2)
485+
486+ # ### Options
487+
488+ | Option | Short | Description | Default |
489+ |--------|-------|-------------|---------|
490+ | `--output` | `-o` | Output file path | stdout |
491+ | `--language` | `-l` | Target language (`rust`, `typescript`, `both`) | `both` |
492+ | `--dry-run` | `-n` | Show changes without generating code | `false` |
493+ | `--force` | `-f` | Force generation for unsafe migrations | `false` |
494+ | `--help` | `-h` | Print help information | - |
495+
496+ # ### Examples
497+
498+ **Preview migration (dry run):**
499+ ` ` ` bash
500+ lumos migrate schema-v1.lumos schema-v2.lumos --dry-run
501+ ` ` `
502+
503+ **Output:**
504+ ```
505+ Migration: schema-v1.lumos → schema-v2.lumos
506+
507+ Required migrations:
508+ 1 . PlayerAccount.score: u32 → u64
509+ - Requires account reallocation (+4 bytes)
510+ - Safe: value range expansion
511+
512+ 2 . PlayerAccount.stats: (new field)
513+ - Requires account reallocation (+10 bytes)
514+ - Default value needed
515+
516+ Generated files (dry run):
517+ - migration.rs (Rust migration instruction)
518+ - migration.ts (TypeScript client helper)
519+ ```
520+
521+ **Generate Rust migration:**
522+ ```bash
523+ lumos migrate schema-v1.lumos schema-v2.lumos -l rust -o migration.rs
524+ ```
525+
526+ ** Generated ` migration.rs ` :**
527+ ``` rust
528+ use anchor_lang :: prelude :: * ;
529+
530+ /// Migration from v1 to v2
531+ pub fn migrate_player_account (
532+ old_data : & [u8 ],
533+ new_account : & mut PlayerAccountV2 ,
534+ ) -> Result <()> {
535+ // Read old format
536+ let old = PlayerAccountV1 :: try_from_slice (old_data )? ;
537+
538+ // Transform to new format
539+ new_account . wallet = old . wallet;
540+ new_account . score = old . score as u64 ; // Safe upcast
541+ new_account . stats = PlayerStats :: default (); // New field
542+
543+ Ok (())
544+ }
545+ ```
546+
547+ ** Generate TypeScript migration:**
548+ ``` bash
549+ lumos migrate schema-v1.lumos schema-v2.lumos -l typescript -o migration.ts
550+ ```
551+
552+ ** Force unsafe migration:**
553+ ``` bash
554+ lumos migrate schema-v1.lumos schema-v2.lumos --force
555+ ```
556+
557+ ::: caution [ Unsafe Migrations]
558+ Use ` --force ` only when you understand the risks. Unsafe migrations may cause data loss if not handled correctly.
559+ :::
560+
561+ ---
562+
315563## Global Options
316564
317565Available for all commands:
@@ -419,3 +667,5 @@ Generated files are overwritten on every `generate`. Make schema changes in `.lu
419667- [ Type System] ( /api/types ) - Supported types and mappings
420668- [ Attributes] ( /api/attributes ) - Available schema attributes
421669- [ Generated Code] ( /api/generated-code ) - Understanding output
670+ - [ Schema Versioning] ( /guides/versioning ) - Version your schemas safely
671+ - [ Schema Migrations] ( /guides/schema-migrations ) - Migration strategies and patterns
0 commit comments