Domain Models¶
Project Model¶
bani.domain.project
¶
Project model — represents a parsed BDL migration project (Section 7).
These dataclasses hold the in-memory representation of a BDL document after
parsing. The BDL parser (separate module) creates ProjectModel instances;
the orchestrator consumes them.
SyncStrategy
¶
WriteStrategy
¶
ErrorHandlingStrategy
¶
ConnectionConfig
dataclass
¶
Connection configuration for a source or target database.
Credential values are never stored directly — only ${env:VAR}
references that are resolved at runtime.
Attributes:
| Name | Type | Description |
|---|---|---|
dialect |
str
|
Database dialect, e.g. |
host |
str
|
Database host. |
port |
int
|
Database port. |
database |
str
|
Database name. |
username_env |
str
|
Environment variable name for the username. |
password_env |
str
|
Environment variable name for the password. |
extra |
tuple[tuple[str, str], ...]
|
Additional connector-specific configuration. |
encrypt |
bool
|
Whether to use TLS (default |
Source code in src/bani/domain/project.py
ColumnMapping
dataclass
¶
Mapping for a single column in a table.
Attributes:
| Name | Type | Description |
|---|---|---|
source_name |
str
|
Source column name. |
target_name |
str
|
Target column name. |
target_type |
str | None
|
Optional type override for the target column. |
Source code in src/bani/domain/project.py
TypeMappingOverride
dataclass
¶
Type mapping override from source to target type.
Attributes:
| Name | Type | Description |
|---|---|---|
source_type |
str
|
Source data type. |
target_type |
str
|
Target data type to map to. |
Source code in src/bani/domain/project.py
ProjectOptions
dataclass
¶
Project-level configuration options.
Attributes:
| Name | Type | Description |
|---|---|---|
batch_size |
int
|
Number of rows per batch. |
parallel_workers |
int
|
Number of parallel workers. |
memory_limit_mb |
int
|
Memory limit in MB. |
on_error |
ErrorHandlingStrategy
|
Error handling strategy. |
create_target_schema |
bool
|
Whether to create target schema. |
drop_target_tables_first |
bool
|
Whether to drop target tables first. |
transfer_indexes |
bool
|
Whether to transfer indexes. |
transfer_foreign_keys |
bool
|
Whether to transfer foreign keys. |
transfer_defaults |
bool
|
Whether to transfer default values. |
transfer_check_constraints |
bool
|
Whether to transfer check constraints. |
Source code in src/bani/domain/project.py
ScheduleConfig
dataclass
¶
Configuration for scheduled migrations.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether the schedule is enabled. |
cron |
str | None
|
Cron expression for scheduling (optional). |
timezone |
str
|
Timezone for cron evaluation. |
max_retries |
int
|
Maximum number of retries on failure. |
retry_delay_seconds |
int
|
Delay in seconds between retries. |
Source code in src/bani/domain/project.py
SyncConfig
dataclass
¶
Configuration for incremental sync.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether sync is enabled. |
strategy |
SyncStrategy
|
Sync strategy to use. |
tracking_columns |
tuple[tuple[str, str], ...]
|
Tuples of (table, column) for tracking changes. |
Source code in src/bani/domain/project.py
TableMapping
dataclass
¶
Mapping configuration for a single table.
Attributes:
| Name | Type | Description |
|---|---|---|
source_schema |
str
|
Source schema name. |
source_table |
str
|
Source table name. |
target_schema |
str
|
Target schema name (may differ from source). |
target_table |
str
|
Target table name (may differ from source). |
column_mappings |
tuple[ColumnMapping, ...]
|
Tuple of column mappings (empty = all). |
filter_sql |
str | None
|
Optional WHERE clause to filter source rows. |
write_strategy |
WriteStrategy
|
How to write data to the target. |
batch_size |
int | None
|
Number of rows per batch ( |
Source code in src/bani/domain/project.py
HookConfig
dataclass
¶
Configuration for a pre- or post-migration hook.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Human-readable hook name. |
event |
str
|
When the hook runs (e.g. |
command |
str
|
Command text (SQL statement or shell command). |
hook_type |
str
|
|
target |
str
|
For SQL hooks, which connection to run against:
|
table_name |
str
|
For per-table hooks, the table this applies to. |
timeout_seconds |
int
|
Maximum execution time before the hook is killed. |
on_failure |
str
|
Action on failure: |
Source code in src/bani/domain/project.py
ProjectModel
dataclass
¶
In-memory representation of a parsed BDL migration project.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Project name. |
source |
ConnectionConfig | None
|
Source database connection configuration. |
target |
ConnectionConfig | None
|
Target database connection configuration. |
description |
str
|
Optional project description. |
author |
str
|
Project author. |
created |
datetime | None
|
Project creation timestamp. |
tags |
tuple[str, ...]
|
Tuple of project tags. |
table_mappings |
tuple[TableMapping, ...]
|
Tuple of per-table mapping configurations. |
type_overrides |
tuple[TypeMappingOverride, ...]
|
Optional user-supplied type mapping overrides. |
options |
ProjectOptions | None
|
Project-level configuration options. |
hooks |
tuple[HookConfig, ...]
|
Tuple of pre/post migration hooks. |
schedule |
ScheduleConfig | None
|
Schedule configuration for migrations. |
sync |
SyncConfig | None
|
Sync configuration for incremental migrations. |
Source code in src/bani/domain/project.py
MigrationPlan
dataclass
¶
A resolved plan ready for execution.
Created from a ProjectModel after schema introspection and dependency
resolution. Contains the ordered list of tables and their resolved
configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
project |
ProjectModel
|
The source project model. |
ordered_tables |
tuple[str, ...]
|
Tables in dependency-safe execution order. |
deferred_fk_tables |
tuple[str, ...]
|
Tables whose FK constraints are deferred. |
total_estimated_rows |
int | None
|
Sum of row count estimates across all tables. |
Source code in src/bani/domain/project.py
Schema Model¶
bani.domain.schema
¶
Schema introspection models (Section 11.1).
All dataclasses are frozen and use tuples (not lists) for collection fields, ensuring immutability and thread-safety as required by Section 11.2.
ConstraintType
¶
ColumnDefinition
dataclass
¶
A single column within a table.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Column name. |
data_type |
str
|
Raw source type string, e.g. |
nullable |
bool
|
Whether the column allows NULL values. |
default_value |
str | None
|
Default value expression, if any. |
is_auto_increment |
bool
|
Whether the column auto-increments. |
ordinal_position |
int
|
0-based position of the column in the table. |
arrow_type_str |
str | None
|
Canonical Arrow type string (e.g. |
Source code in src/bani/domain/schema.py
IndexDefinition
dataclass
¶
An index on a table.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Index name. |
columns |
tuple[str, ...]
|
Ordered tuple of column names in the index. |
is_unique |
bool
|
Whether the index enforces uniqueness. |
is_clustered |
bool
|
Whether the index is clustered. |
filter_expression |
str | None
|
Optional partial-index filter expression. |
Source code in src/bani/domain/schema.py
ForeignKeyDefinition
dataclass
¶
A foreign key relationship between two tables.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Constraint name. |
source_table |
str
|
Fully qualified name of the referencing table. |
source_columns |
tuple[str, ...]
|
Columns in the referencing table. |
referenced_table |
str
|
Fully qualified name of the referenced table. |
referenced_columns |
tuple[str, ...]
|
Columns in the referenced table. |
on_delete |
str
|
Referential action on delete. |
on_update |
str
|
Referential action on update. |
Source code in src/bani/domain/schema.py
TableDefinition
dataclass
¶
A table within a database schema.
Attributes:
| Name | Type | Description |
|---|---|---|
schema_name |
str
|
Database schema (namespace) the table belongs to. |
table_name |
str
|
Name of the table. |
columns |
tuple[ColumnDefinition, ...]
|
Ordered tuple of column definitions. |
primary_key |
tuple[str, ...]
|
Tuple of column names forming the primary key. |
indexes |
tuple[IndexDefinition, ...]
|
Tuple of index definitions on this table. |
foreign_keys |
tuple[ForeignKeyDefinition, ...]
|
Tuple of foreign key definitions on this table. |
check_constraints |
tuple[str, ...]
|
Tuple of CHECK constraint expressions. |
row_count_estimate |
int | None
|
Estimated row count from schema introspection,
or |
Source code in src/bani/domain/schema.py
fully_qualified_name
property
¶
Return schema_name.table_name.
DatabaseSchema
dataclass
¶
The full schema of a database as returned by introspection.
Attributes:
| Name | Type | Description |
|---|---|---|
tables |
tuple[TableDefinition, ...]
|
Tuple of table definitions. |
source_dialect |
str
|
Dialect identifier, e.g. |
Source code in src/bani/domain/schema.py
get_table(schema_name, table_name)
¶
Look up a table by schema and name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_name
|
str
|
The schema (namespace) to search in. |
required |
table_name
|
str
|
The table name to find. |
required |
Returns:
| Type | Description |
|---|---|
TableDefinition | None
|
The matching |
Source code in src/bani/domain/schema.py
Error Hierarchy¶
bani.domain.errors
¶
Domain-specific exception hierarchy for Bani.
All exceptions inherit from BaniError. Each exception carries structured
context so that callers can programmatically inspect the failure without
parsing message strings.
Hierarchy (Section 12.1)::
BaniError
├── ConfigurationError
│ ├── BDLValidationError
│ ├── ConnectionConfigError
│ └── TypeMappingError
├── ConnectionError
│ ├── SourceConnectionError
│ └── TargetConnectionError
├── SchemaError
│ ├── IntrospectionError
│ ├── SchemaTranslationError
│ └── DependencyResolutionError
├── DataTransferError
│ ├── ReadError
│ ├── WriteError
│ ├── BatchError
│ └── TransformError
├── HookExecutionError
└── SchedulerError
BaniError
¶
ConfigurationError
¶
BDLValidationError
¶
Bases: ConfigurationError
BDL document failed XSD or semantic validation.
Source code in src/bani/domain/errors.py
ConnectionConfigError
¶
Bases: ConfigurationError
Invalid or missing connection configuration.
Source code in src/bani/domain/errors.py
TypeMappingError
¶
Bases: ConfigurationError
A source type could not be mapped to a target type.
Source code in src/bani/domain/errors.py
BaniConnectionError
¶
Bases: BaniError
Base for connection-related failures.
Named BaniConnectionError to avoid shadowing the built-in
ConnectionError.
Source code in src/bani/domain/errors.py
SourceConnectionError
¶
Bases: BaniConnectionError
Failed to connect to the source database.
Source code in src/bani/domain/errors.py
TargetConnectionError
¶
Bases: BaniConnectionError
Failed to connect to the target database.
Source code in src/bani/domain/errors.py
SchemaError
¶
IntrospectionError
¶
Bases: SchemaError
Failed to introspect the source database schema.
Source code in src/bani/domain/errors.py
SchemaTranslationError
¶
Bases: SchemaError
Failed to translate schema between source and target dialects.
Source code in src/bani/domain/errors.py
DependencyResolutionError
¶
Bases: SchemaError
Failed to resolve table dependencies (e.g. circular FK chains).
Source code in src/bani/domain/errors.py
DataTransferError
¶
ReadError
¶
Bases: DataTransferError
Failed to read data from the source.
Source code in src/bani/domain/errors.py
WriteError
¶
Bases: DataTransferError
Failed to write data to the target.
Source code in src/bani/domain/errors.py
BatchError
¶
Bases: DataTransferError
A specific batch failed during transfer.
Carries the batch number and the offset of the first row in the batch so that the resumability protocol can pick up from the right place.
Source code in src/bani/domain/errors.py
TransformError
¶
Bases: DataTransferError
A transform step failed during the pipeline.