Schema¶
The table schema: declared fields, their metadata, primary key, unique
constraints, indexes, and foreign keys. TinyStore stores a schema fingerprint per
table in metadata.json and compares it on open to detect breaking changes.
schema
¶
Schema metadata: per-table descriptions, fingerprints, and compatibility checks.
A :class:TableSchema is a serializable snapshot of a model's structure. It is
persisted in metadata.json so that reopening a database can detect
incompatible schema changes rather than silently corrupting data.
FieldMetadata
dataclass
¶
FieldMetadata(
name: str,
type_str: str,
primary_key: bool = False,
autoincrement: bool = False,
unique: bool = False,
index: bool = False,
nullable: bool = True,
foreign_key: str | None = None,
on_delete: str = "RESTRICT",
default_repr: str | None = None,
)
Static description of a single model field as seen by TinyStore.
TableSchema
dataclass
¶
TableSchema(
name: str,
model_qualname: str,
fields: tuple[FieldMetadata, ...] = field(
default_factory=tuple
),
relationships: tuple[
tuple[str, str, str, str], ...
] = field(default_factory=tuple),
)
Serializable schema snapshot for one table.
SchemaChange
dataclass
¶
A single difference between two table schemas.
kind is one of: additive (safe), breaking (rejected),
compatible (no semantic impact, e.g. model qualname rename).
classify_change
¶
Compare a previously-persisted schema to the currently-registered one.
Returns a list of changes. If any change is breaking, the caller should
raise :class:~tinystore.exceptions.SchemaError.