Schema Tests¶
Overview¶
Schema tests cover:
- ✅ Type Creation - Document, vertex, and edge types, plus
get_or_create_*variants - ✅ IndexType enum - Includes current Java index values (
GEOSPATIAL,HASH) - ✅ Type Queries - Getting types and checking existence
- ✅ Type Query Stability - Repeated
get_types()calls stay duplicate-free - ✅ Type Deletion - Removing types from schema
- ✅ Property Creation - Adding properties to types, plus
get_or_create_property - ✅ Property Deletion - Removing properties
- ✅ Index Creation - LSM_TREE, unique, composite, FULL_TEXT indexes
- ✅ Index Queries - Getting and listing indexes
- ✅ Index Deletion - Removing indexes
- ✅ Property Types - All ArcadeDB property types, including LIST/MAP
- ✅ Vector Indexes - Retrieval/listing via Schema API and LSM vector index operations
Test Classes¶
TestTypeCreation¶
Tests creating document, vertex, and edge types, plus the get_or_create_* variants.
Tests:
test_create_document_type()- Basic document type creationtest_create_vertex_type()- Basic vertex type creationtest_create_edge_type()- Basic edge type creationtest_create_type_with_buckets()- Custom bucket count (buckets=5)test_duplicate_type_creation_fails()- Re-creating a type raisesArcadeDBErrortest_get_or_create_document_type_new()-get_or_createfor a new document typetest_get_or_create_document_type_existing()-get_or_createfor an existing document typetest_get_or_create_vertex_type_new()-get_or_createfor a new vertex typetest_get_or_create_vertex_type_existing()-get_or_createfor an existing vertex typetest_get_or_create_edge_type_new()-get_or_createfor a new edge typetest_get_or_create_edge_type_existing()-get_or_createfor an existing edge type
Pattern:
with arcadedb.create_database("./test_db") as db:
schema = db.schema
# Basic types
schema.create_vertex_type("Person")
schema.create_edge_type("Knows")
# With buckets
schema.create_document_type("DocWithBuckets", buckets=5)
# Idempotent variant
schema.get_or_create_vertex_type("NewVertex")
IndexType enum (module-level)¶
Test:
test_index_type_enum_includes_new_java_index_types()- Asserts the PythonIndexTypeenum exposes current Java values:IndexType.GEOSPATIAL.value == "GEOSPATIAL"andIndexType.HASH.value == "HASH"
TestTypeQueries¶
Tests querying schema for types.
Tests:
test_exists_type_true()-exists_typereturnsTruefor an existing typetest_exists_type_false()-exists_typereturnsFalsefor a non-existent typetest_get_type_existing()-get_typereturns the type object for an existing typetest_get_type_non_existent()-get_typereturnsNonefor a non-existent typetest_get_types()-get_typeslists all typestest_get_types_has_no_duplicates_across_repeated_calls()- Repeated calls stay stable and duplicate-free
Pattern:
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_vertex_type("User")
# Get type
user_type = schema.get_type("User")
# Check existence
if schema.exists_type("User"):
print("User type exists")
# List all types
for type_obj in schema.get_types():
print(type_obj.getName())
TestTypeDeletion¶
Tests removing types from schema.
Tests:
test_drop_type()-drop_typeremoves a typetest_drop_non_existent_type_fails()- Dropping a non-existent type raisesArcadeDBError
Pattern:
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_document_type("TempType")
# Drop type
schema.drop_type("TempType")
assert not schema.exists_type("TempType")
TestPropertyCreation¶
Tests adding properties to types.
Tests:
test_create_simple_property()- Basic STRING propertytest_create_integer_property()- INTEGER propertytest_create_list_property()- LIST property usingof_type=PropertyType.STRINGtest_create_multiple_properties()- Several properties on the same typetest_create_property_on_non_existent_type_fails()- RaisesArcadeDBErrortest_get_or_create_property_new()-get_or_create_propertyfor a new propertytest_get_or_create_property_existing()-get_or_create_propertyfor an existing property
Pattern:
from arcadedb_embedded import PropertyType
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_vertex_type("User")
# Basic property
schema.create_property("User", "name", PropertyType.STRING)
# Typed property
schema.create_property("User", "age", PropertyType.INTEGER)
# List property
schema.create_property(
"User", "tags", PropertyType.LIST, of_type=PropertyType.STRING
)
# Idempotent variant
schema.get_or_create_property("User", "email", PropertyType.STRING)
TestPropertyDeletion¶
Tests removing properties from types.
Tests:
test_drop_property()-drop_propertyremoves a property (verified by re-creating it)test_drop_property_from_non_existent_type_fails()- RaisesArcadeDBError
Pattern:
from arcadedb_embedded import PropertyType
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_vertex_type("User")
schema.create_property("User", "temp", PropertyType.STRING)
# Drop property
schema.drop_property("User", "temp")
# Property no longer exists; it can be created again
schema.create_property("User", "temp", PropertyType.STRING)
TestIndexCreation¶
Tests creating indexes on types.
Tests:
test_create_simple_index()- Single-property indextest_create_unique_index()- Unique index (unique=True)test_create_composite_index()- Multi-property indextest_create_full_text_index()-IndexType.FULL_TEXTindextest_create_lsm_tree_index()- ExplicitIndexType.LSM_TREEindextest_get_or_create_index_new()-get_or_create_indexfor a new indextest_get_or_create_index_existing()-get_or_create_indexfor an existing index
Pattern:
from arcadedb_embedded import IndexType, PropertyType
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_vertex_type("User")
schema.create_property("User", "username", PropertyType.STRING)
# Unique index
schema.create_index("User", ["username"], unique=True)
# Composite index
schema.create_vertex_type("Person")
schema.create_property("Person", "firstName", PropertyType.STRING)
schema.create_property("Person", "lastName", PropertyType.STRING)
schema.create_index("Person", ["firstName", "lastName"])
# Full-text index
schema.create_document_type("Article")
schema.create_property("Article", "content", PropertyType.STRING)
schema.create_index("Article", ["content"], index_type=IndexType.FULL_TEXT)
TestIndexQueries¶
Tests querying indexes.
Tests:
test_exists_index_true()-exists_indexreturnsTruefor an existing indextest_exists_index_false()-exists_indexreturnsFalsefor a non-existent indextest_get_indexes()-get_indexeslists all indexes
Pattern:
from arcadedb_embedded import PropertyType
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_vertex_type("User")
schema.create_property("User", "email", PropertyType.STRING)
schema.create_index("User", ["email"], unique=True)
# Get all indexes
for index in schema.get_indexes():
print(index.getName(), index.getTypeName())
# Check existence by index name (format: Type[property])
name = schema.get_indexes()[0].getName()
assert schema.exists_index(name)
TestIndexDeletion¶
Tests removing indexes.
Tests:
test_drop_index()-drop_indexremoves an index by its nametest_drop_non_existent_index_fails()- Dropping a non-existent index raisesArcadeDBError
Pattern:
from arcadedb_embedded import PropertyType
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_vertex_type("User")
schema.create_property("User", "temp", PropertyType.STRING)
schema.create_index("User", ["temp"])
# Look up the generated index name, then drop it
index_name = next(
idx.getName()
for idx in schema.get_indexes()
if "User" in idx.getTypeName() and "temp" in idx.getName()
)
schema.drop_index(index_name)
assert schema.exists_index(index_name) is False
TestPropertyTypes¶
Tests all ArcadeDB property types.
Tests:
test_all_property_types()- Creates one property for each scalarPropertyType: BOOLEAN, BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE, DECIMAL, STRING, BINARY, DATE, DATETIMEtest_complex_property_types()- Creates LIST properties (withof_type) and a MAP property
Pattern:
from arcadedb_embedded import PropertyType
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_document_type("AllTypes")
# Scalar types
schema.create_property("AllTypes", "intProp", PropertyType.INTEGER)
schema.create_property("AllTypes", "stringProp", PropertyType.STRING)
schema.create_property("AllTypes", "dateProp", PropertyType.DATE)
# Complex types
schema.create_property(
"AllTypes", "tags", PropertyType.LIST, of_type=PropertyType.STRING
)
schema.create_property("AllTypes", "metadata", PropertyType.MAP)
TestVectorIndexSchemaOps¶
Tests vector-index retrieval and listing via the Schema API.
Tests:
test_get_index_by_name_existing()-get_index_by_namereturns an existing indextest_get_index_by_name_non_existent()-get_index_by_namereturnsNonefor a missing indextest_list_vector_indexes_empty()-list_vector_indexesreturns an empty list when no vector indexes existtest_get_vector_index_non_existent()-get_vector_indexreturnsNonewhen no index exists on the propertytest_get_vector_index_wrong_type()-get_vector_indexreturnsNonefor a non-vector index
TestIntegration¶
Tests complete schema workflows.
Tests:
test_create_complete_graph_schema()- Creates vertex/edge types with properties and indexes (including aFULL_TEXTindex onPost.content)test_schema_modification_workflow()- Adds properties and indexes to an existing typetest_get_or_create_idempotent_schema_creation()-get_or_create_*methods are idempotent across repeated calls
Pattern:
from arcadedb_embedded import IndexType, PropertyType
with arcadedb.create_database("./test_db") as db:
schema = db.schema
# Create types
schema.create_vertex_type("User")
schema.create_vertex_type("Post")
schema.create_edge_type("Follows")
schema.create_edge_type("Wrote")
# Add properties
schema.create_property("User", "username", PropertyType.STRING)
schema.create_property("User", "email", PropertyType.STRING)
schema.create_property("Post", "content", PropertyType.STRING)
# Create indexes
schema.create_index("User", ["username"], unique=True)
schema.create_index("User", ["email"], unique=True)
schema.create_index("Post", ["content"], index_type=IndexType.FULL_TEXT)
TestLSMVectorIndexSchemaOps¶
Tests LSM vector index schema operations created via db.create_vector_index(...).
Tests:
test_list_lsm_vector_indexes()- Aftercreate_vector_index("Doc", "embedding", dimensions=3),list_vector_indexes()includes the new indextest_get_lsm_vector_index_existing()-get_vector_index("Doc", "embedding")returns aVectorIndexinstancetest_get_lsm_vector_index_persistence()-get_vector_indexcan load a persisted LSM index;get_size()reflects inserted vectors
Test Patterns¶
Type Creation¶
with arcadedb.create_database("./test_db") as db:
# Schema operations are auto-transactional (no wrapper needed)
db.schema.create_vertex_type("User")
db.schema.create_edge_type("Follows")
Property Definition¶
from arcadedb_embedded import PropertyType
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_vertex_type("User")
# Add properties
schema.create_property("User", "name", PropertyType.STRING)
schema.create_property(
"User", "tags", PropertyType.LIST, of_type=PropertyType.STRING
)
Index Creation¶
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_vertex_type("User")
schema.create_property("User", "username", PropertyType.STRING)
# Unique index
schema.create_index("User", ["username"], unique=True)
Common Assertions¶
from arcadedb_embedded import PropertyType
with arcadedb.create_database("./test_db") as db:
schema = db.schema
schema.create_vertex_type("User")
schema.create_property("User", "name", PropertyType.STRING)
# Type exists
assert schema.exists_type("User")
# Type object is retrievable
assert schema.get_type("User") is not None
# Index exists (after creating one)
schema.create_index("User", ["name"])
assert len(schema.get_indexes()) > 0
Key Takeaways¶
- Schema ops are auto-transactional - No wrapper needed for type/property/index creation
- Check existence - Use
exists_type()/exists_index()before creating - Use
get_or_create_*- Idempotent type/property/index creation - Index frequently queried - Properties used in WHERE clauses
- Use
PropertyType/IndexTypeenums - Match property and index types to your data - Vector indexes via the Schema API - Use
create_vector_index(), thenlist_vector_indexes()andget_vector_index()to retrieve them
See Also¶
- Schema API - Full API reference
- Example 02: Social Network - Schema patterns
- Example 03: Vector Search - Vector indexes
- Architecture Guide - Schema design principles