type_bridge.migration.schema_manager¶
schema_manager
¶
Schema manager for TypeDB schema operations.
SchemaManager
¶
Manager for database schema operations.
Initialize schema manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db
|
Database
|
Database connection |
required |
Source code in type_bridge/migration/schema_manager.py
register
¶
Register model classes for schema management.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
models
|
type[Entity | Relation]
|
Model classes to register |
()
|
Source code in type_bridge/migration/schema_manager.py
collect_schema_info
¶
Collect schema information from registered models.
Returns:
| Type | Description |
|---|---|
SchemaInfo
|
SchemaInfo with entities, relations, and attributes |
Source code in type_bridge/migration/schema_manager.py
generate_schema
¶
Generate complete TypeQL schema definition.
Returns:
| Type | Description |
|---|---|
str
|
TypeQL schema definition string |
Source code in type_bridge/migration/schema_manager.py
has_existing_schema
¶
Check if database has existing schema defined.
Returns:
| Type | Description |
|---|---|
bool
|
True if database exists and has custom schema beyond built-in types |
Source code in type_bridge/migration/schema_manager.py
introspect_current_schema_info
¶
Introspect current database schema and build SchemaInfo.
Note: This is a best-effort attempt. It cannot perfectly reconstruct Python class hierarchies from TypeDB schema.
Returns:
| Type | Description |
|---|---|
SchemaInfo | None
|
SchemaInfo with current schema, or None if database doesn't exist |
Source code in type_bridge/migration/schema_manager.py
verify_compatibility
¶
Verify that new schema is compatible with old schema.
Checks for breaking changes (removed or modified types/attributes) and raises SchemaConflictError if found.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_schema_info
|
SchemaInfo
|
The previous schema to compare against |
required |
Raises:
| Type | Description |
|---|---|
SchemaConflictError
|
If breaking changes are detected |
Source code in type_bridge/migration/schema_manager.py
sync_schema
¶
Synchronize database schema with registered models.
Automatically checks for existing schema in the database and raises SchemaConflictError if schema already exists and might conflict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
force
|
bool
|
If True, recreate database from scratch, ignoring conflicts |
False
|
skip_if_exists
|
bool
|
If True, skip conflict checks when types already exist. Use this for idempotent deployments where you want to ensure the schema is in place without recreating the database. TypeDB 3.x's define statement is idempotent for identical definitions. |
False
|
Raises:
| Type | Description |
|---|---|
SchemaConflictError
|
If database has existing schema and force=False and skip_if_exists=False |
Source code in type_bridge/migration/schema_manager.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
drop_schema
¶
Drop all schema definitions.
Source code in type_bridge/migration/schema_manager.py
introspect_schema
¶
Introspect current database schema.
Returns:
| Type | Description |
|---|---|
dict[str, list[str]]
|
Dictionary of schema information |