graflo.architecture.schema.namespace¶
Physical graph namespace: the database, graph or space a schema deploys into.
Schema.metadata.name is a label. It is free-form on purpose: merges fold
two names into left+right, agents write prose into it, and it is excluded
from every content hash. It is not an identifier, and handing it verbatim to
CREATE DATABASE / CREATE GRAPH / CREATE SPACE fails on the first
character a backend does not accept.
The namespace a schema actually deploys into is resolved here, in one place, with one precedence:
- an explicit override (a call argument or connection config), validated;
db_profile.target_namespace, validated -- an explicit value is refused when the flavor would reject it, never silently rewritten;- :func:
sanitize_namespaceovermetadata.name-- a deterministic, idempotent projection into the flavor's identifier rules.
The derived name is deliberately not stored back onto the profile.
db_profile is part of the schema's content hash and metadata is not, so
a stored mirror would make renaming a schema move its content address, and
merging two schemas would have two auto-filled mirrors to reconcile.
Attributes¶
FALLBACK_NAMESPACE = 'graph'
module-attribute
¶
__all__ = ['FALLBACK_NAMESPACE', 'InvalidNamespaceError', 'namespace_problem', 'resolve_namespace', 'sanitize_namespace', 'validate_namespace']
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
InvalidNamespaceError
¶
Functions:¶
namespace_problem(name, flavor)
¶
Why flavor would reject name as a namespace, or None if it would not.
Source code in graflo/architecture/schema/namespace.py
resolve_namespace(schema, flavor=None, override=None)
¶
The namespace schema deploys into on flavor.
Precedence: override, then db_profile.target_namespace (both
validated), then the sanitized metadata.name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
The schema being deployed. |
required |
flavor
|
DBType | None
|
Target backend; defaults to |
None
|
override
|
str | None
|
An explicit namespace from the caller, e.g. a call argument. |
None
|
Raises:
| Type | Description |
|---|---|
InvalidNamespaceError
|
An explicit namespace flavor would reject. |
Source code in graflo/architecture/schema/namespace.py
sanitize_namespace(name, flavor)
¶
Project a free-form schema label onto a namespace flavor accepts.
Only what flavor would reject is rewritten: every run of disallowed
characters becomes one separator, a leading character the flavor refuses
gets a g_ prefix, and TigerGraph reserved words and forbidden prefixes
are escaped. Neo4j names are additionally lowercased, - separated and
padded to three characters. Over-long results keep a stable hash of the
full name as a suffix, so two long labels sharing a prefix do not collide.
Flavors without documented rules keep letters, digits, _ and -.
Deterministic and idempotent: sanitize_namespace(sanitize_namespace(x, f), f)
equals sanitize_namespace(x, f).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The schema label, typically |
required |
flavor
|
DBType
|
Target backend. |
required |
Returns:
| Type | Description |
|---|---|
str
|
A namespace that passes :func: |
Source code in graflo/architecture/schema/namespace.py
validate_namespace(name, flavor)
¶
Refuse an explicit namespace flavor would reject.
Raises:
| Type | Description |
|---|---|
InvalidNamespaceError
|
naming the problem and the sanitized spelling. |