Skip to main content

Saga State Model

Description

A persistence model specifically for storing the state of Sagas.

Definition Schema

The definition for a saga_state_model component expects the following structure:

{
"$defs": {
"FieldArgumentsInputDTO": {
"description": "Arguments for sqlmodel.Field()",
"example": {
"default_str": "None",
"description": "The unique identifier.",
"foreign_key_str": "'user.id'",
"index": true,
"nullable": false,
"primary_key": true
},
"properties": {
"default_str": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "String representation of the default value. If it represents a callable (e.g., 'uuid.uuid4'), it's treated as default_factory. Examples: 'None', '\"text\"', '123', 'datetime.utcnow'.",
"title": "Default Str"
},
"primary_key": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Primary Key"
},
"nullable": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"description": "Explicitly set Field(nullable=...). SQLModel typically infers this from Optional[T] in type hint.",
"title": "Nullable"
},
"index": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Index"
},
"unique": {
"anyOf": [
{
"type": "boolean"
},
{
"type": "null"
}
],
"default": null,
"title": "Unique"
},
"foreign_key_str": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "String representation of the foreign key, e.g., \"'other_table.id'\"",
"title": "Foreign Key Str"
},
"max_length": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Max Length"
},
"min_length": {
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"default": null,
"title": "Min Length"
},
"description": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Description"
},
"title": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Title"
},
"sa_column_str": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Full string for sa_column argument, e.g., 'Column(String, unique=True)'. Requires appropriate imports.",
"title": "Sa Column Str"
}
},
"title": "FieldArgumentsInputDTO",
"type": "object"
},
"ModelFieldInputDTO": {
"description": "Defines a single field within a SQLModel class.",
"example_field": {
"field_details": {
"default_str": "None",
"primary_key": true
},
"is_relationship": false,
"name": "id",
"type_str": "Optional[int]"
},
"example_field_required": {
"field_details": {
"index": true,
"unique": true
},
"is_relationship": false,
"name": "username",
"type_str": "str"
},
"example_field_with_default_factory": {
"field_details": {
"default_str": "uuid.uuid4",
"index": true
},
"is_relationship": false,
"name": "uid",
"type_str": "uuid.UUID"
},
"example_relationship": {
"is_relationship": true,
"name": "items",
"relationship_details": {
"back_populates": "'user'"
},
"type_str": "List['Item']"
},
"properties": {
"name": {
"description": "Name of the field.",
"title": "Name",
"type": "string"
},
"type_str": {
"description": "Python type hint for the field as a string, e.g., 'str', 'Optional[int]', 'List[\"Item\"]'. Use quotes for forward references.",
"title": "Type Str",
"type": "string"
},
"is_relationship": {
"default": false,
"description": "Set to True if this field is a SQLModel Relationship, False for a regular Field.",
"title": "Is Relationship",
"type": "boolean"
},
"field_details": {
"anyOf": [
{
"$ref": "#/$defs/FieldArgumentsInputDTO"
},
{
"type": "null"
}
],
"default": null,
"description": "Arguments for sqlmodel.Field(). Used if is_relationship is False."
},
"relationship_details": {
"anyOf": [
{
"$ref": "#/$defs/RelationshipArgumentsInputDTO"
},
{
"type": "null"
}
],
"default": null,
"description": "Arguments for sqlmodel.Relationship(). Used if is_relationship is True."
}
},
"required": [
"name",
"type_str"
],
"title": "ModelFieldInputDTO",
"type": "object"
},
"RelationshipArgumentsInputDTO": {
"description": "Arguments for sqlmodel.Relationship()",
"example": {
"back_populates": "'posts'",
"link_model_str": "'PostTagLink'",
"sa_relationship_kwargs_str": {
"lazy": "'joined'"
}
},
"properties": {
"back_populates": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Back Populates"
},
"link_model_str": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Name of the link model for many-to-many if an explicit link model is used (as a string).",
"title": "Link Model Str"
},
"sa_relationship_kwargs_str": {
"anyOf": [
{
"additionalProperties": {
"type": "string"
},
"type": "object"
},
{
"type": "null"
}
],
"default": null,
"description": "String dictionary for sa_relationship_kwargs, e.g., {\"lazy\": \"'selectin'\"}. Values should be valid Python expressions as strings.",
"title": "Sa Relationship Kwargs Str"
}
},
"title": "RelationshipArgumentsInputDTO",
"type": "object"
}
},
"description": "Defines a SQLModel class to be generated.",
"example": {
"base_class_module_str": "sqlmodel",
"base_class_name_str": "SQLModel",
"docstring": "Represents a user in the system.",
"fields": [
{
"field_details": {
"default_str": "None",
"primary_key": true
},
"is_relationship": false,
"name": "id",
"type_str": "Optional[int]"
},
{
"field_details": {
"index": true,
"unique": true
},
"is_relationship": false,
"name": "username",
"type_str": "str"
},
{
"field_details": {
"unique": true
},
"is_relationship": false,
"name": "email",
"type_str": "str"
},
{
"is_relationship": true,
"name": "posts",
"relationship_details": {
"back_populates": "'author'"
},
"type_str": "List['Post']"
}
],
"is_table_model": true,
"name": "User"
},
"properties": {
"name": {
"description": "Name of the SQLModel class.",
"title": "Name",
"type": "string"
},
"fields": {
"description": "List of fields for the model.",
"items": {
"$ref": "#/$defs/ModelFieldInputDTO"
},
"title": "Fields",
"type": "array"
},
"is_table_model": {
"default": false,
"description": "If True, adds ', table=True' to the class definition, making it a database table model.",
"title": "Is Table Model",
"type": "boolean"
},
"docstring": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Optional docstring for the generated class.",
"title": "Docstring"
},
"base_class_name_str": {
"default": "SQLModel",
"description": "The name of the base class to inherit from. Defaults to 'SQLModel'.",
"title": "Base Class Name Str",
"type": "string"
},
"base_class_module_str": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": "sqlmodel",
"description": "The module from which to import the base class. Defaults to 'sqlmodel'. Set to None if the base class is a built-in or globally available.",
"title": "Base Class Module Str"
}
},
"required": [
"name",
"fields"
],
"title": "ModelInputDTO",
"type": "object"
}

Naming and Location Conventions

Class: PascalCase, typically ends with 'SagaStateModel'. File: ${saga_state_model_name}.py (based on ${saga_state_model_name}). Location: app/infrastructure/persistence/${bounded_ctx}/repositories. (Requires context: ['bounded_ctx'])

Example Definition

{
"name": "User",
"is_table_model": true,
"docstring": "Represents a user in the system.",
"fields": [
{
"name": "id",
"type_str": "Optional[int]",
"is_relationship": false,
"field_details": {
"default_str": "None",
"primary_key": true
}
},
{
"name": "username",
"type_str": "str",
"is_relationship": false,
"field_details": {
"index": true,
"unique": true
}
},
{
"name": "email",
"type_str": "str",
"is_relationship": false,
"field_details": {
"unique": true
}
},
{
"name": "posts",
"type_str": "List['Post']",
"is_relationship": true,
"relationship_details": {
"back_populates": "'author'"
}
}
],
"base_class_name_str": "SQLModel",
"base_class_module_str": "sqlmodel"
}