-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
42 lines (26 loc) · 1.1 KB
/
model.py
File metadata and controls
42 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import enum
from geoalchemy2 import Geometry
from sqlalchemy import ForeignKey, Identity, Index, String
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
class Base(DeclarativeBase):
pass
class Structure(Base):
__tablename__ = "structure"
id: Mapped[int] = mapped_column(Identity(), primary_key=True)
name: Mapped[str] = mapped_column(nullable=False)
type: Mapped[str] = mapped_column(nullable=False)
layers: Mapped[list["StructureLayer"]] = relationship()
class LayerType(enum.StrEnum):
Cover = "cover"
Guys = "guys"
Structure = "structure"
class StructureLayer(Base):
__tablename__ = "structure_layer"
id: Mapped[int] = mapped_column(Identity(), primary_key=True)
structure_id: Mapped[int] = mapped_column(
ForeignKey("structure.id"), nullable=False
)
structure: Mapped[Structure] = relationship(back_populates="layers")
layer_type: Mapped[LayerType] = mapped_column(String, nullable=False)
geom: Mapped[Geometry] = mapped_column(Geometry())
Index("structure_layer_structure_id", StructureLayer.structure_id)