Crates.io | rusty-schema-diff |
lib.rs | rusty-schema-diff |
version | 0.1.1 |
source | src |
created_at | 2024-12-11 08:34:34.386638 |
updated_at | 2024-12-11 08:41:34.777893 |
description | A powerful schema evolution analyzer supporting JSON Schema, OpenAPI, Protobuf, and SQL DDL |
homepage | https://github.com/rusty-libraries/rusty-schema-diff |
repository | |
max_upload_size | |
id | 1479745 |
size | 91,405 |
Welcome to Rusty Schema Diff, a powerful schema evolution analyzer that supports multiple schema formats including JSON Schema, OpenAPI, Protobuf, and SQL DDL. This library helps you analyze and manage schema changes across different versions, detect breaking changes, and generate migration paths.
Add this to your Cargo.toml
:
[dependencies]
rusty-schema-diff = "0.1.1"
use rusty_schema_diff::{Schema, SchemaFormat, JsonSchemaAnalyzer, SchemaAnalyzer};
use semver::Version;
// Create schema instances
let old_schema = Schema::new(
SchemaFormat::JsonSchema,
r#"{"type": "object", "properties": {"name": {"type": "string"}}}"#.to_string(),
Version::parse("1.0.0").unwrap()
);
let new_schema = Schema::new(
SchemaFormat::JsonSchema,
r#"{"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "integer"}}}"#.to_string(),
Version::parse("1.1.0").unwrap()
);
// Analyze compatibility
let analyzer = JsonSchemaAnalyzer;
let report = analyzer.analyze_compatibility(&old_schema, &new_schema).unwrap();
println!("Compatible: {}", report.is_compatible);
println!("Score: {}", report.compatibility_score);
use rusty_schema_diff::prelude::*;
let analyzer = JsonSchemaAnalyzer;
let report = analyzer.analyze_compatibility(&old_schema, &new_schema).unwrap();
// Generate migration plan
let plan = analyzer.generate_migration_path(&old_schema, &new_schema).unwrap();
for step in plan.steps {
println!("Migration step: {}", step);
}
use rusty_schema_diff::prelude::*;
let analyzer = OpenApiAnalyzer;
let report = analyzer.analyze_compatibility(&old_api, &new_api).unwrap();
println!("Breaking changes:");
for change in report.changes.iter().filter(|c| c.is_breaking) {
println!("- {}: {}", change.location, change.description);
}
use rusty_schema_diff::prelude::*;
let analyzer = SqlAnalyzer;
let report = analyzer.analyze_compatibility(&old_ddl, &new_ddl).unwrap();
// Generate SQL migration statements
let plan = analyzer.generate_migration_path(&old_ddl, &new_ddl).unwrap();
for statement in plan.steps {
println!("SQL: {}", statement);
}
For detailed information on all available analyzers and their functionality, please refer to the API Documentation.
This library is licensed under the MIT License. See the LICENSE file for details.