a working product with ugly ui
This commit is contained in:
46
app/models/map_item.py
Normal file
46
app/models/map_item.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from sqlalchemy import Column, String, DateTime, ForeignKey
|
||||
from sqlalchemy.dialects.postgresql import UUID, JSONB
|
||||
from sqlalchemy.sql import func
|
||||
from geoalchemy2 import Geography
|
||||
import uuid
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class MapItem(Base):
|
||||
"""
|
||||
Map item model for storing cables, switches, APs, and wireless mesh.
|
||||
|
||||
Types:
|
||||
- cable: Fiber, Cat6, Cat6 PoE
|
||||
- wireless_mesh: Wireless connections between APs
|
||||
- switch: Network switch
|
||||
- indoor_ap: Indoor access point
|
||||
- outdoor_ap: Outdoor access point
|
||||
|
||||
Geometry:
|
||||
- Point for devices (switches, APs)
|
||||
- LineString for cables and wireless mesh
|
||||
|
||||
Properties (JSONB):
|
||||
- For cables: cable_type, name, notes, length_meters, start_device_id, end_device_id
|
||||
- For devices: name, notes, port_count, connections (array of {cable_id, port_number})
|
||||
- For wireless_mesh: name, notes, start_ap_id, end_ap_id
|
||||
"""
|
||||
|
||||
__tablename__ = "map_items"
|
||||
|
||||
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
||||
map_id = Column(UUID(as_uuid=True), ForeignKey("maps.id", ondelete="CASCADE"), nullable=False, index=True)
|
||||
type = Column(String(50), nullable=False, index=True)
|
||||
|
||||
# PostGIS geography column for spatial data
|
||||
# Using GeometryCollection to support both Point and LineString geometries
|
||||
geometry = Column(Geography(geometry_type='GEOMETRY', srid=4326), nullable=False)
|
||||
|
||||
# JSONB column for flexible properties based on item type
|
||||
properties = Column(JSONB, nullable=False, server_default='{}')
|
||||
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now(), nullable=False)
|
||||
created_by = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
|
||||
updated_by = Column(UUID(as_uuid=True), ForeignKey("users.id"), nullable=True)
|
||||
Reference in New Issue
Block a user