Skip to main content

sdif_db.schema

SDIFSchemaConfig Objects

class SDIFSchemaConfig()

Configuration for comparing SDIF structural schemas. Defines which aspects of the schema to enforce during comparison.

Attributes:

  • enforce_sdif_version - If True, compares the 'sdif_version' from properties.

  • enforce_table_names - If True, tables are matched by name. If False, the set of table structures is compared, ignoring original names.

  • enforce_column_order - If True, the order of columns within a table must match.

  • enforce_column_names - If True, columns are matched by name. If False (and enforce_column_order is True), columns are compared by their position.

  • enforce_column_types - If True, SQLite data types of columns must match.

  • enforce_column_not_null_constraints - If True, NOT NULL constraints must match.

  • enforce_column_default_values - If True, column default values must match.

  • enforce_primary_keys - If True, compares the ordered list of column names forming each table's primary key.

  • enforce_foreign_keys - If True, compares foreign key definitions (target table, ordered source/target columns).

  • enforce_foreign_key_referential_actions - If True (and enforce_foreign_keys is True), 'ON UPDATE' and 'ON DELETE' referential actions must match.

  • enforce_table_names0 - Defines how JSON objects in 'sdif_objects' are compared.

  • enforce_table_names1 - Objects are not compared.

  • enforce_table_names2 - Only the set of object names is compared.

  • enforce_table_names3 - Object names and the content of their 'schema_hint' (if present and valid) are compared.

  • enforce_table_names4 - Defines how media items in 'sdif_media' are compared.

  • enforce_table_names1 - Media items are not compared.

  • enforce_table_names2 - Only the set of media names is compared.

  • enforce_table_names7 - Media names and 'media_type' are compared.

  • enforce_table_names8 - Media names, 'media_type', and 'original_format' are compared.

  • enforce_table_names9 - Defines how 'technical_metadata' for media items is compared.

  • enforce_table_names1 - Technical metadata is not compared.

  • enforce_column_order1 - The content of 'technical_metadata' (if present and valid JSON) is compared.

  • enforce_column_order2 - Defines how links in 'sdif_semantic_links' are compared.

  • enforce_table_names1 - Semantic links are not compared.

  • enforce_column_order4 - Only the set of unique 'link_type' values is compared.

  • enforce_column_order5 - All structural aspects of links (type, from/to element type and spec, excluding 'link_id' and 'description') are compared.

Notes:

Comparison of non-primary-key UNIQUE constraints and CHECK constraints on tables is currently NOT SUPPORTED, as SDIFDatabase.get_schema() does not extract them.

apply_rules_to_schema

def apply_rules_to_schema(full_schema: Dict[str, Any],
config: SDIFSchemaConfig) -> Dict[str, Any]

Transforms a full structural schema (from SDIFDatabase.get_schema()) into a minimal, canonical schema based on the provided configuration.

Arguments:

  • full_schema - The schema dictionary from SDIFDatabase.get_schema().

  • config - An SDIFSchemaConfig instance defining the comparison rules.

Returns:

A minimal, canonical schema dictionary, ready for direct comparison.