Schema Tests¶
Overview¶
Schema tests cover:
- ✅ Type Creation - Vertex, edge, and document types
- ✅ 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
- ✅ Property Deletion - Removing properties
- ✅ Index Creation - LSM_TREE, HNSW, FULL_TEXT indexes
- ✅ Index Queries - Getting and listing indexes
- ✅ Index Deletion - Removing indexes
- ✅ Property Types - All ArcadeDB property types
- ✅ Vector Indexes - HNSW (JVector) configuration and operations
Test Classes¶
TestTypeCreation¶
Tests creating vertex, edge, and document types.
Tests:
test_create_vertex_type()- Basic vertex type creationtest_create_edge_type()- Basic edge type creationtest_create_document_type()- Basic document type creationtest_create_type_with_buckets()- Custom bucket count
Pattern:
with arcadedb.create_database("./test_db") as db:
# Basic type
db.schema.create_vertex_type("User")
# With buckets
db.schema.create_vertex_type("Product", buckets=10)
TestTypeQueries¶
Tests querying schema for types.
Tests:
test_get_type()- Get type by nametest_exists_type()- Check if type existstest_get_types()- List all typestest_get_types_has_no_duplicates_across_repeated_calls()- Repeated calls stay stable and duplicate-freetest_get_type_properties()- List type properties
Pattern:
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("User")
# Get type
user_type = db.schema.get_type("User")
# Check existence
if db.schema.exists_type("User"):
print("User type exists")
# List all types
for type_obj in db.schema.get_types():
print(type_obj.get_name())
TestTypeDeletion¶
Tests removing types from schema.
Tests:
test_delete_type()- Remove typetest_delete_type_with_data()- Remove type with records
Pattern:
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("Temp")
# Delete type
db.schema.delete_type("Temp")
assert not db.schema.exists_type("Temp")
TestPropertyCreation¶
Tests adding properties to types.
Tests:
test_create_property()- Basic propertytest_create_property_with_type()- Typed propertytest_create_list_property()- List propertytest_create_embedded_property()- Embedded propertytest_property_constraints()- Mandatory, not null, defaults
Pattern:
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("User")
user_type = db.schema.get_type("User")
# Basic property
user_type.create_property("name", "STRING")
# With constraints
name_prop = user_type.get("name")
name_prop.set_mandatory(True)
name_prop.set_not_null(True)
# List property
user_type.create_property("tags", "LIST", of_type="STRING")
TestPropertyDeletion¶
Tests removing properties from types.
Tests:
test_delete_property()- Remove propertytest_delete_property_with_data()- Remove property with data
Pattern:
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("User")
user_type = db.schema.get_type("User")
user_type.create_property("temp", "STRING")
# Delete property
user_type.drop_property("temp")
# Verify deletion
try:
user_type.get("temp")
assert False, "Property should have been deleted"
except (AttributeError, KeyError):
pass # Expected
TestIndexCreation¶
Tests creating indexes on types.
Tests:
test_create_lsm_index()- LSM_TREE indextest_create_unique_index()- Unique indextest_create_composite_index()- Multi-property indextest_create_fulltext_index()- Full-text search index
Pattern:
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("User")
user_type = db.schema.get_type("User")
user_type.create_property("username", "STRING")
user_type.create_property("email", "STRING")
# Unique index
db.schema.create_index("User", ["username"], unique=True)
# Composite index
db.schema.create_vertex_type("Event")
event_type = db.schema.get_type("Event")
event_type.create_property("userId", "STRING")
event_type.create_property("timestamp", "DATETIME")
db.schema.create_index("Event", ["userId", "timestamp"])
# Full-text index
db.schema.create_vertex_type("Article")
article_type = db.schema.get_type("Article")
article_type.create_property("content", "STRING")
db.schema.create_index("Article", ["content"], index_type="FULL_TEXT")
TestIndexQueries¶
Tests querying indexes.
Tests:
test_get_indexes()- List all indexestest_get_type_indexes()- Get indexes for typetest_get_index_properties()- Get indexed properties
Pattern:
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("User")
user_type = db.schema.get_type("User")
user_type.create_property("username", "STRING")
user_type.create_property("email", "STRING")
db.schema.create_index("User", ["username"], unique=True)
db.schema.create_index("User", ["email"], unique=True)
# Get all indexes
for index in db.schema.get_indexes():
print(index.get_name())
# Get indexes for type
indexes = user_type.get_indexes()
for index in indexes:
print(f"Index: {index.get_property_names()}")
TestIndexDeletion¶
Tests removing indexes.
Tests:
test_delete_index()- Remove indextest_delete_index_by_name()- Remove by index name
Pattern:
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("User")
user_type = db.schema.get_type("User")
user_type.create_property("email", "STRING")
# Create index
db.schema.create_index("User", ["email"], unique=True)
# Verify index exists
assert len(user_type.get_indexes()) > 0
# Delete index
db.schema.drop_index("User[email]")
# Verify deletion
assert len(user_type.get_indexes()) == 0
TestPropertyTypes¶
Tests all ArcadeDB property types.
Tests:
test_string_property()- STRING typetest_integer_property()- INTEGER typetest_long_property()- LONG typetest_float_property()- FLOAT typetest_double_property()- DOUBLE typetest_boolean_property()- BOOLEAN typetest_date_property()- DATE typetest_datetime_property()- DATETIME typetest_binary_property()- BINARY typetest_list_property()- LIST typetest_map_property()- MAP type
Pattern:
with arcadedb.create_database("./test_db") as db:
type_obj = db.schema.create_vertex_type("AllTypes")
# Create all property types
type_obj.create_property("name", "STRING")
type_obj.create_property("age", "INTEGER")
type_obj.create_property("score", "DOUBLE")
type_obj.create_property("active", "BOOLEAN")
type_obj.create_property("birthDate", "DATE")
type_obj.create_property("created", "DATETIME")
type_obj.create_property("tags", "LIST", of_type="STRING")
type_obj.create_property("metadata", "MAP")
TestIntegration¶
Tests complete schema workflows.
Tests:
test_complete_schema_setup()- Full schema creationtest_schema_migration()- Evolving schematest_schema_export_import()- Schema serialization
Pattern:
with arcadedb.create_database("./test_db") as db:
# Complete schema setup
# Create types
user_type = db.schema.create_vertex_type("User")
post_type = db.schema.create_vertex_type("Post")
likes_type = db.schema.create_edge_type("Likes")
# Add properties
user_type.create_property("username", "STRING")
user_type.create_property("email", "STRING")
post_type.create_property("title", "STRING")
post_type.create_property("content", "STRING")
# Create indexes
db.schema.create_index("User", ["username"], unique=True)
db.schema.create_index("User", ["email"], unique=True)
db.schema.create_index("Post", ["title"])
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¶
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("User")
user_type = db.schema.get_type("User")
# Add property
user_type.create_property("name", "STRING")
# Set constraints
prop = user_type.get("name")
prop.set_mandatory(True)
prop.set_not_null(True)
Index Creation¶
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("User")
db.schema.create_property("User", "username", "STRING")
# Unique index
db.schema.create_index("User", ["username"], unique=True)
Common Assertions¶
with arcadedb.create_database("./test_db") as db:
db.schema.create_vertex_type("User")
db.schema.create_property("User", "name", "STRING")
db.schema.create_property("User", "age", "INTEGER")
# Type exists
assert db.schema.exists_type("User")
# Type has property
user_type = db.schema.get_type("User")
assert user_type.get("name") is not None
# Index exists (after creating one)
db.schema.create_index("User", ["name"])
indexes = user_type.get_indexes()
assert len(indexes) > 0
# Property type
prop = user_type.get("age")
assert str(prop.get_type()) == "INTEGER"
Key Takeaways¶
- Schema ops are auto-transactional - No wrapper needed for type/property/index creation
- Check existence - Use
exists_type()before creating - Set constraints - Use
set_mandatory(),set_not_null() - Index frequently queried - Properties used in WHERE clauses
- Use appropriate types - Match property types to data
- Configure JVector - Tune
max_connections,beam_width,overquery_factor,dimensionsfor vectors
See Also¶
- Schema API - Full API reference
- Example 02: Social Network - Schema patterns
- Example 03: Vector Search - HNSW indexes
- Architecture Guide - Schema design principles