Skip to main content

compare_schemas

Function compare_schemas 

Source
pub fn compare_schemas(before: &SchemaGraph, after: &SchemaGraph) -> SchemaDiff
Expand description

Compare two schema graphs and return a structured diff.

ยงExample

use surql_parser::{SchemaGraph, diff::compare_schemas};

let before = SchemaGraph::from_source("
    DEFINE TABLE user SCHEMAFULL;
    DEFINE FIELD name ON user TYPE string;
").unwrap();

let after = SchemaGraph::from_source("
    DEFINE TABLE user SCHEMAFULL;
    DEFINE FIELD name ON user TYPE string;
    DEFINE FIELD email ON user TYPE string;
    DEFINE TABLE post SCHEMALESS;
").unwrap();

let diff = compare_schemas(&before, &after);
assert_eq!(diff.added_tables, vec!["post"]);
assert_eq!(diff.added_fields, vec![("user".to_string(), "email".to_string())]);