aboutsummaryrefslogtreecommitdiffstats
path: root/thallium-backend
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2024-08-25 04:00:55 +0100
committerGravatar Joe Banks <[email protected]>2024-08-25 04:00:55 +0100
commit1f00ab65906ea93d5d2a7c887456b66767500838 (patch)
tree2244a203498bcd2a88d0c5ba89c0e8c1925a2727 /thallium-backend
parentCorrect permission in seed script (diff)
Add support for nullable colour and colour_code2
Diffstat (limited to 'thallium-backend')
-rw-r--r--thallium-backend/migrations/versions/1724550124-d74a6956b012_colour_updates.py34
-rw-r--r--thallium-backend/src/dto/templates.py5
-rw-r--r--thallium-backend/src/orm/templates.py5
-rw-r--r--thallium-backend/src/routes/admin.py2
4 files changed, 42 insertions, 4 deletions
diff --git a/thallium-backend/migrations/versions/1724550124-d74a6956b012_colour_updates.py b/thallium-backend/migrations/versions/1724550124-d74a6956b012_colour_updates.py
new file mode 100644
index 0000000..09aac51
--- /dev/null
+++ b/thallium-backend/migrations/versions/1724550124-d74a6956b012_colour_updates.py
@@ -0,0 +1,34 @@
+"""
+Make colours nullable and add colour_code2.
+
+Revision ID: d74a6956b012
+Revises: 8c35ad6bab78
+Create Date: 2024-08-25 01:42:04.001456+00:00
+"""
+
+import sqlalchemy as sa
+from alembic import op
+
+# revision identifiers, used by Alembic.
+revision = "d74a6956b012"
+down_revision = "8c35ad6bab78"
+branch_labels = None
+depends_on = None
+
+
+def upgrade() -> None:
+ """Apply this migration."""
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.add_column("variants", sa.Column("colour_code2", sa.String(), nullable=True))
+ op.alter_column("variants", "colour", existing_type=sa.VARCHAR(), nullable=True)
+ op.alter_column("variants", "colour_code", existing_type=sa.VARCHAR(), nullable=True)
+ # ### end Alembic commands ###
+
+
+def downgrade() -> None:
+ """Revert this migration."""
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.alter_column("variants", "colour_code", existing_type=sa.VARCHAR(), nullable=False)
+ op.alter_column("variants", "colour", existing_type=sa.VARCHAR(), nullable=False)
+ op.drop_column("variants", "colour_code2")
+ # ### end Alembic commands ###
diff --git a/thallium-backend/src/dto/templates.py b/thallium-backend/src/dto/templates.py
index 48ab685..8f3b382 100644
--- a/thallium-backend/src/dto/templates.py
+++ b/thallium-backend/src/dto/templates.py
@@ -20,8 +20,9 @@ class Variant(BaseModel):
variant_id: int
name: str
size: str
- colour: str
- colour_code: str
+ colour: str | None
+ colour_code: str | None
+ colour_code2: str | None
price: Decimal
last_synced: datetime
diff --git a/thallium-backend/src/orm/templates.py b/thallium-backend/src/orm/templates.py
index cffd5ca..e46d015 100644
--- a/thallium-backend/src/orm/templates.py
+++ b/thallium-backend/src/orm/templates.py
@@ -45,8 +45,9 @@ class Variant(AuditBase, Base):
variant_id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
size: Mapped[str]
- colour: Mapped[str]
- colour_code: Mapped[str]
+ colour: Mapped[str] = mapped_column(nullable=True)
+ colour_code: Mapped[str] = mapped_column(nullable=True)
+ colour_code2: Mapped[str] = mapped_column(nullable=True)
price: Mapped[Decimal]
last_synced: Mapped[datetime] = mapped_column(DateTime(timezone=True))
diff --git a/thallium-backend/src/routes/admin.py b/thallium-backend/src/routes/admin.py
index c2e0228..9eb146d 100644
--- a/thallium-backend/src/routes/admin.py
+++ b/thallium-backend/src/routes/admin.py
@@ -43,6 +43,7 @@ async def sync_variants(variant_ids: list[int], db: DBSession, client: PrintfulC
"size": variant["size"],
"colour": variant["color"],
"colour_code": variant["color_code"],
+ "colour_code2": variant["color_code2"],
"price": variant["price"],
"last_synced": datetime.now(tz=UTC),
}
@@ -55,6 +56,7 @@ async def sync_variants(variant_ids: list[int], db: DBSession, client: PrintfulC
"size": stmt.excluded.size,
"colour": stmt.excluded.colour,
"colour_code": stmt.excluded.colour_code,
+ "colour_code2": stmt.excluded.colour_code2,
"price": stmt.excluded.price,
"last_synced": stmt.excluded.last_synced,
},