| name | data-model-designer |
| description | Design data models for construction projects. Create entity-relationship diagrams, define schemas, and generate database structures. |
| homepage | https://datadrivenconstruction.io |
| metadata | {"openclaw":{"emoji":"📐","os":["darwin","linux","win32"],"homepage":"https://datadrivenconstruction.io","requires":{"bins":"[Truncated]"}}} |
Data Model Designer
Business Case
Problem Statement
Construction data management challenges:
- Fragmented data across systems
- Inconsistent data structures
- Missing relationships between entities
- Difficult data integration
Solution
Systematic data model design for construction projects, defining entities, relationships, and schemas for effective data management.
Technical Implementation
from typing import Dict, Any, List, Optional
from dataclasses import dataclass, field
from enum import Enum
import json
class ():
STRING =
INTEGER =
FLOAT =
BOOLEAN =
DATE =
DATETIME =
TEXT =
JSON =
():
ONE_TO_ONE =
ONE_TO_MANY =
MANY_TO_MANY =
():
PRIMARY_KEY =
FOREIGN_KEY =
UNIQUE =
NOT_NULL =
:
name:
data_type: DataType
nullable: =
default: =
description: =
constraints: [ConstraintType] = field(default_factory=)
:
name:
description:
fields: [Field] = field(default_factory=)
primary_key: =
:
name:
from_entity:
to_entity:
relation_type: RelationType
from_field:
to_field:
:
():
.project_name = project_name
.entities: [, Entity] = {}
.relationships: [Relationship] = []
():
.entities[entity.name] = entity
():
.relationships.append(relationship)
() -> Entity:
entity_fields = [
Field(
name=f[],
data_type=DataType(f.get(, )),
nullable=f.get(, ),
default=f.get(),
description=f.get(, ),
constraints=[ConstraintType(c) c f.get(, [])]
)
f fields
]
entity = Entity(name=name, description=description, fields=entity_fields)
.add_entity(entity)
entity
() -> Relationship:
rel = Relationship(
name=,
from_entity=from_entity,
to_entity=to_entity,
relation_type=RelationType(relation_type),
from_field=from_field ,
to_field=
)
.add_relationship(rel)
rel
() -> :
sql = []
type_map = {
DataType.STRING: ,
DataType.INTEGER: ,
DataType.FLOAT: ,
DataType.BOOLEAN: ,
DataType.DATE: ,
DataType.DATETIME: ,
DataType.TEXT: ,
DataType.JSON: dialect ==
}
name, entity .entities.items():
columns = []
fld entity.fields:
col =
fld.nullable:
col +=
ConstraintType.PRIMARY_KEY fld.constraints:
col +=
columns.append(col)
sql.append( + .join(columns) + )
rel .relationships:
sql.append()
.join(sql)
() -> [, ]:
schemas = {}
name, entity .entities.items():
properties = {}
required = []
fld entity.fields:
prop = {: fld.description}
fld.data_type == DataType.STRING:
prop[] =
fld.data_type == DataType.INTEGER:
prop[] =
fld.data_type == DataType.FLOAT:
prop[] =
fld.data_type == DataType.BOOLEAN:
prop[] =
:
prop[] =
properties[fld.name] = prop
fld.nullable:
required.append(fld.name)
schemas[name] = {
: ,
: entity.description,
: properties,
: required
}
schemas
() -> :
lines = []
name, entity .entities.items():
fld entity.fields[:]:
lines.append()
lines.append()
lines.append()
rel .relationships:
rel_symbol = {
RelationType.ONE_TO_ONE: ,
RelationType.ONE_TO_MANY: ,
RelationType.MANY_TO_MANY:
}.get(rel.relation_type, )
lines.append()
.join(lines)
() -> []:
issues = []
rel .relationships:
rel.from_entity .entities:
issues.append()
rel.to_entity .entities:
issues.append()
name, entity .entities.items():
has_pk = (ConstraintType.PRIMARY_KEY f.constraints f entity.fields)
has_pk:
issues.append()
issues
:
() -> Entity:
Entity(
name=,
description=,
fields=[
Field(, DataType.INTEGER, , constraints=[ConstraintType.PRIMARY_KEY]),
Field(, DataType.STRING, , constraints=[ConstraintType.UNIQUE]),
Field(, DataType.STRING, ),
Field(, DataType.STRING),
Field(, DataType.DATE),
Field(, DataType.DATE),
Field(, DataType.FLOAT)
]
)
() -> Entity:
Entity(
name=,
description=,
fields=[
Field(, DataType.INTEGER, , constraints=[ConstraintType.PRIMARY_KEY]),
Field(, DataType.INTEGER, ),
Field(, DataType.STRING),
Field(, DataType.STRING, ),
Field(, DataType.DATE),
Field(, DataType.DATE),
Field(, DataType.FLOAT)
]
)
() -> Entity:
Entity(
name=,
description=,
fields=[
Field(, DataType.INTEGER, , constraints=[ConstraintType.PRIMARY_KEY]),
Field(, DataType.INTEGER, ),
Field(, DataType.STRING),
Field(, DataType.STRING),
Field(, DataType.FLOAT),
Field(, DataType.FLOAT)
]
)