Added external ID fields to filaments and vendors

This commit is contained in:
Donkie
2024-05-12 19:31:12 +02:00
parent 36945f449d
commit 1e4c73138c
7 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
"""Added external ID.
Revision ID: 395d560284b3
Revises: 5f069e51bd89
Create Date: 2024-05-12 19:30:17.261396
"""
import sqlalchemy as sa
from alembic import op
# revision identifiers, used by Alembic.
revision = "395d560284b3"
down_revision = "5f069e51bd89"
branch_labels = None
depends_on = None
def upgrade() -> None:
"""Perform the upgrade."""
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("filament", sa.Column("external_id", sa.String(length=256), nullable=True))
op.add_column("vendor", sa.Column("external_id", sa.String(length=256), nullable=True))
# ### end Alembic commands ###
def downgrade() -> None:
"""Perform the downgrade."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("vendor", "external_id")
op.drop_column("filament", "external_id")
# ### end Alembic commands ###

View File

@@ -82,6 +82,13 @@ class FilamentParameters(BaseModel):
description="Hexadecimal color code of the filament, e.g. FF0000 for red. Supports alpha channel at the end.",
example="FF0000",
)
external_id: Optional[str] = Field(
max_length=256,
description=(
"Set if this filament comes from an external database. This contains the ID in the external database."
),
example="polymaker_pla_polysonicblack_1000_175",
)
extra: Optional[dict[str, str]] = Field(
None,
description="Extra fields for this filament.",
@@ -357,6 +364,7 @@ async def create( # noqa: ANN201
settings_extruder_temp=body.settings_extruder_temp,
settings_bed_temp=body.settings_bed_temp,
color_hex=body.color_hex,
external_id=body.external_id,
extra=body.extra,
)

View File

@@ -61,6 +61,13 @@ class Vendor(BaseModel):
name: str = Field(max_length=64, description="Vendor name.", example="Polymaker")
comment: Optional[str] = Field(max_length=1024, description="Free text comment about this vendor.", example="")
empty_spool_weight: Optional[float] = Field(gt=0, description="The empty spool weight, in grams.", example=140)
external_id: Optional[str] = Field(
max_length=256,
description=(
"Set if this vendor comes from an external database. This contains the ID in the external database."
),
example="eSun",
)
extra: dict[str, str] = Field(
description=(
"Extra fields for this vendor. All values are JSON-encoded data. "
@@ -77,6 +84,7 @@ class Vendor(BaseModel):
name=item.name,
comment=item.comment,
empty_spool_weight=item.empty_spool_weight,
external_id=item.external_id,
extra={field.key: field.value for field in item.extra},
)
@@ -137,6 +145,13 @@ class Filament(BaseModel):
description="Hexadecimal color code of the filament, e.g. FF0000 for red. Supports alpha channel at the end.",
example="FF0000",
)
external_id: Optional[str] = Field(
max_length=256,
description=(
"Set if this filament comes from an external database. This contains the ID in the external database."
),
example="polymaker_pla_polysonicblack_1000_175",
)
extra: dict[str, str] = Field(
description=(
"Extra fields for this filament. All values are JSON-encoded data. "
@@ -163,6 +178,7 @@ class Filament(BaseModel):
settings_extruder_temp=item.settings_extruder_temp,
settings_bed_temp=item.settings_bed_temp,
color_hex=item.color_hex,
external_id=item.external_id,
extra={field.key: field.value for field in item.extra},
)

View File

@@ -38,6 +38,13 @@ class VendorParameters(BaseModel):
description="The weight of an empty spool, in grams.",
example=200,
)
external_id: Optional[str] = Field(
max_length=256,
description=(
"Set if this vendor comes from an external database. This contains the ID in the external database."
),
example="eSun",
)
extra: Optional[dict[str, str]] = Field(
None,
description="Extra fields for this vendor.",
@@ -191,6 +198,7 @@ async def create( # noqa: ANN201
name=body.name,
comment=body.comment,
empty_spool_weight=body.empty_spool_weight,
external_id=body.external_id,
extra=body.extra,
)

View File

@@ -42,6 +42,7 @@ async def create(
settings_extruder_temp: Optional[int] = None,
settings_bed_temp: Optional[int] = None,
color_hex: Optional[str] = None,
external_id: Optional[str] = None,
extra: Optional[dict[str, str]] = None,
) -> models.Filament:
"""Add a new filament to the database."""
@@ -67,6 +68,7 @@ async def create(
settings_extruder_temp=settings_extruder_temp,
settings_bed_temp=settings_bed_temp,
color_hex=color_hex,
external_id=external_id,
extra=[models.FilamentField(key=k, value=v) for k, v in (extra or {}).items()],
)
db.add(filament)

View File

@@ -21,6 +21,7 @@ class Vendor(Base):
empty_spool_weight: Mapped[Optional[float]] = mapped_column(comment="The weight of an empty spool.")
comment: Mapped[Optional[str]] = mapped_column(String(1024))
filaments: Mapped[list["Filament"]] = relationship(back_populates="vendor")
external_id: Mapped[Optional[str]] = mapped_column(String(256))
extra: Mapped[list["VendorField"]] = relationship(
back_populates="vendor",
cascade="save-update, merge, delete, delete-orphan",
@@ -48,6 +49,7 @@ class Filament(Base):
settings_extruder_temp: Mapped[Optional[int]] = mapped_column(comment="Overridden extruder temperature.")
settings_bed_temp: Mapped[Optional[int]] = mapped_column(comment="Overridden bed temperature.")
color_hex: Mapped[Optional[str]] = mapped_column(String(8))
external_id: Mapped[Optional[str]] = mapped_column(String(256))
extra: Mapped[list["FilamentField"]] = relationship(
back_populates="filament",
cascade="save-update, merge, delete, delete-orphan",

View File

@@ -20,6 +20,7 @@ async def create(
name: Optional[str] = None,
comment: Optional[str] = None,
empty_spool_weight: Optional[float] = None,
external_id: Optional[str] = None,
extra: Optional[dict[str, str]] = None,
) -> models.Vendor:
"""Add a new vendor to the database."""
@@ -28,6 +29,7 @@ async def create(
registered=datetime.utcnow().replace(microsecond=0),
comment=comment,
empty_spool_weight=empty_spool_weight,
external_id=external_id,
extra=[models.VendorField(key=k, value=v) for k, v in (extra or {}).items()],
)
db.add(vendor)