fix: convert active flag to archived

to better mirror farmOS
This commit is contained in:
Lance Edgar 2026-02-14 18:52:49 -06:00
parent 98be276bd1
commit 4ed61380de
13 changed files with 292 additions and 36 deletions

View file

@ -0,0 +1,250 @@
"""convert active to archived
Revision ID: 8898184c5c75
Revises: 3e2ef02bf264
Create Date: 2026-02-14 18:41:23.042951
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import wuttjamaican.db.util
# revision identifiers, used by Alembic.
revision: str = "8898184c5c75"
down_revision: Union[str, None] = "3e2ef02bf264"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
# animal
op.alter_column("animal", "active", new_column_name="archived")
animal = sa.sql.table(
"animal",
sa.sql.column("uuid"),
sa.sql.column("archived"),
)
cursor = op.get_bind().execute(animal.select())
for row in cursor.fetchall():
op.get_bind().execute(
animal.update()
.where(animal.c.uuid == row.uuid)
.values({"archived": not row.archived})
)
op.alter_column("animal_version", "active", new_column_name="archived")
animal_version = sa.sql.table(
"animal_version",
sa.sql.column("uuid"),
sa.sql.column("archived"),
)
cursor = op.get_bind().execute(animal_version.select())
for row in cursor.fetchall():
op.get_bind().execute(
animal_version.update()
.where(animal_version.c.uuid == row.uuid)
.values({"archived": not row.archived})
)
# group
op.alter_column("group", "active", new_column_name="archived")
group = sa.sql.table(
"group",
sa.sql.column("uuid"),
sa.sql.column("archived"),
)
cursor = op.get_bind().execute(group.select())
for row in cursor.fetchall():
op.get_bind().execute(
group.update()
.where(group.c.uuid == row.uuid)
.values({"archived": not row.archived})
)
op.alter_column("group_version", "active", new_column_name="archived")
group_version = sa.sql.table(
"group_version",
sa.sql.column("uuid"),
sa.sql.column("archived"),
)
cursor = op.get_bind().execute(group_version.select())
for row in cursor.fetchall():
op.get_bind().execute(
group_version.update()
.where(group_version.c.uuid == row.uuid)
.values({"archived": not row.archived})
)
# land_asset
op.alter_column("land_asset", "active", new_column_name="archived")
land_asset = sa.sql.table(
"land_asset",
sa.sql.column("uuid"),
sa.sql.column("archived"),
)
cursor = op.get_bind().execute(land_asset.select())
for row in cursor.fetchall():
op.get_bind().execute(
land_asset.update()
.where(land_asset.c.uuid == row.uuid)
.values({"archived": not row.archived})
)
op.alter_column("land_asset_version", "active", new_column_name="archived")
land_asset_version = sa.sql.table(
"land_asset_version",
sa.sql.column("uuid"),
sa.sql.column("archived"),
)
cursor = op.get_bind().execute(land_asset_version.select())
for row in cursor.fetchall():
op.get_bind().execute(
land_asset_version.update()
.where(land_asset_version.c.uuid == row.uuid)
.values({"archived": not row.archived})
)
# structure
op.alter_column("structure", "active", new_column_name="archived")
structure = sa.sql.table(
"structure",
sa.sql.column("uuid"),
sa.sql.column("archived"),
)
cursor = op.get_bind().execute(structure.select())
for row in cursor.fetchall():
op.get_bind().execute(
structure.update()
.where(structure.c.uuid == row.uuid)
.values({"archived": not row.archived})
)
op.alter_column("structure_version", "active", new_column_name="archived")
structure_version = sa.sql.table(
"structure_version",
sa.sql.column("uuid"),
sa.sql.column("archived"),
)
cursor = op.get_bind().execute(structure_version.select())
for row in cursor.fetchall():
op.get_bind().execute(
structure_version.update()
.where(structure_version.c.uuid == row.uuid)
.values({"archived": not row.archived})
)
def downgrade() -> None:
# structure
op.alter_column("structure", "archived", new_column_name="active")
structure = sa.sql.table(
"structure",
sa.sql.column("uuid"),
sa.sql.column("active"),
)
cursor = op.get_bind().execute(structure.select())
for row in cursor.fetchall():
op.get_bind().execute(
structure.update()
.where(structure.c.uuid == row.uuid)
.values({"active": not row.active})
)
op.alter_column("structure_version", "archived", new_column_name="active")
structure_version = sa.sql.table(
"structure_version",
sa.sql.column("uuid"),
sa.sql.column("active"),
)
cursor = op.get_bind().execute(structure_version.select())
for row in cursor.fetchall():
op.get_bind().execute(
structure_version.update()
.where(structure_version.c.uuid == row.uuid)
.values({"active": not row.active})
)
# land_asset
op.alter_column("land_asset", "archived", new_column_name="active")
land_asset = sa.sql.table(
"land_asset",
sa.sql.column("uuid"),
sa.sql.column("active"),
)
cursor = op.get_bind().execute(land_asset.select())
for row in cursor.fetchall():
op.get_bind().execute(
land_asset.update()
.where(land_asset.c.uuid == row.uuid)
.values({"active": not row.active})
)
op.alter_column("land_asset_version", "archived", new_column_name="active")
land_asset_version = sa.sql.table(
"land_asset_version",
sa.sql.column("uuid"),
sa.sql.column("active"),
)
cursor = op.get_bind().execute(land_asset_version.select())
for row in cursor.fetchall():
op.get_bind().execute(
land_asset_version.update()
.where(land_asset_version.c.uuid == row.uuid)
.values({"active": not row.active})
)
# group
op.alter_column("group", "archived", new_column_name="active")
group = sa.sql.table(
"group",
sa.sql.column("uuid"),
sa.sql.column("active"),
)
cursor = op.get_bind().execute(group.select())
for row in cursor.fetchall():
op.get_bind().execute(
group.update()
.where(group.c.uuid == row.uuid)
.values({"active": not row.active})
)
op.alter_column("group_version", "archived", new_column_name="active")
group_version = sa.sql.table(
"group_version",
sa.sql.column("uuid"),
sa.sql.column("active"),
)
cursor = op.get_bind().execute(group_version.select())
for row in cursor.fetchall():
op.get_bind().execute(
group_version.update()
.where(group_version.c.uuid == row.uuid)
.values({"active": not row.active})
)
# animal
op.alter_column("animal", "archived", new_column_name="active")
animal = sa.sql.table(
"animal",
sa.sql.column("uuid"),
sa.sql.column("active"),
)
cursor = op.get_bind().execute(animal.select())
for row in cursor.fetchall():
op.get_bind().execute(
animal.update()
.where(animal.c.uuid == row.uuid)
.values({"active": not row.active})
)
op.alter_column("animal_version", "archived", new_column_name="active")
animal_version = sa.sql.table(
"animal_version",
sa.sql.column("uuid"),
sa.sql.column("active"),
)
cursor = op.get_bind().execute(animal_version.select())
for row in cursor.fetchall():
op.get_bind().execute(
animal_version.update()
.where(animal_version.c.uuid == row.uuid)
.values({"active": not row.active})
)

View file

@ -148,11 +148,12 @@ class Animal(model.Base):
""",
)
active = sa.Column(
archived = sa.Column(
sa.Boolean(),
nullable=False,
default=False,
doc="""
Whether the animal is currently active.
Whether the animal is archived.
""",
)

View file

@ -68,11 +68,12 @@ class Group(model.Base):
""",
)
active = sa.Column(
archived = sa.Column(
sa.Boolean(),
nullable=False,
default=False,
doc="""
Whether the group is active.
Whether the group is archived.
""",
)

View file

@ -126,11 +126,12 @@ class LandAsset(model.Base):
""",
)
active = sa.Column(
archived = sa.Column(
sa.Boolean(),
nullable=False,
default=False,
doc="""
Whether the land asset is currently active.
Whether the land asset is archived.
""",
)

View file

@ -97,11 +97,12 @@ class Structure(model.Base):
""",
)
active = sa.Column(
archived = sa.Column(
sa.Boolean(),
nullable=False,
default=False,
doc="""
Whether the structure is currently active.
Whether the structure is archived.
""",
)

View file

@ -192,7 +192,7 @@ class AnimalImporter(FromFarmOS, ToWutta):
"is_sterile",
"birthdate",
"notes",
"active",
"archived",
"image_url",
]
@ -252,9 +252,9 @@ class AnimalImporter(FromFarmOS, ToWutta):
notes = notes["value"]
if self.farmos_4x:
active = not animal["attributes"]["archived"]
archived = animal["attributes"]["archived"]
else:
active = animal["attributes"]["status"] == "active"
archived = animal["attributes"]["status"] == "archived"
return {
"farmos_uuid": UUID(animal["id"]),
@ -264,7 +264,7 @@ class AnimalImporter(FromFarmOS, ToWutta):
"sex": animal["attributes"]["sex"],
"is_sterile": sterile,
"birthdate": birthdate,
"active": active,
"archived": archived,
"notes": notes,
"image_url": image_url,
}
@ -344,7 +344,7 @@ class GroupImporter(FromFarmOS, ToWutta):
"is_location",
"is_fixed",
"notes",
"active",
"archived",
]
def get_source_objects(self):
@ -358,9 +358,9 @@ class GroupImporter(FromFarmOS, ToWutta):
notes = notes["value"]
if self.farmos_4x:
active = not group["attributes"]["archived"]
archived = group["attributes"]["archived"]
else:
active = group["attributes"]["status"] == "active"
archived = group["attributes"]["status"] == "archived"
return {
"farmos_uuid": UUID(group["id"]),
@ -368,7 +368,7 @@ class GroupImporter(FromFarmOS, ToWutta):
"name": group["attributes"]["name"],
"is_location": group["attributes"]["is_location"],
"is_fixed": group["attributes"]["is_fixed"],
"active": active,
"archived": archived,
"notes": notes,
}
@ -388,7 +388,7 @@ class LandAssetImporter(FromFarmOS, ToWutta):
"is_location",
"is_fixed",
"notes",
"active",
"archived",
]
def setup(self):
@ -418,9 +418,9 @@ class LandAssetImporter(FromFarmOS, ToWutta):
notes = notes["value"]
if self.farmos_4x:
active = not land["attributes"]["archived"]
archived = land["attributes"]["archived"]
else:
active = land["attributes"]["status"] == "active"
archived = land["attributes"]["status"] == "archived"
return {
"farmos_uuid": UUID(land["id"]),
@ -429,7 +429,7 @@ class LandAssetImporter(FromFarmOS, ToWutta):
"land_type_uuid": land_type.uuid,
"is_location": land["attributes"]["is_location"],
"is_fixed": land["attributes"]["is_fixed"],
"active": active,
"archived": archived,
"notes": notes,
}
@ -505,7 +505,7 @@ class StructureImporter(FromFarmOS, ToWutta):
"is_location",
"is_fixed",
"notes",
"active",
"archived",
"image_url",
]
@ -550,9 +550,9 @@ class StructureImporter(FromFarmOS, ToWutta):
image_url = image_style["large"]
if self.farmos_4x:
active = not structure["attributes"]["archived"]
archived = structure["attributes"]["archived"]
else:
active = structure["attributes"]["status"] == "active"
archived = structure["attributes"]["status"] == "archived"
return {
"farmos_uuid": UUID(structure["id"]),
@ -561,7 +561,7 @@ class StructureImporter(FromFarmOS, ToWutta):
"structure_type_uuid": structure_type.uuid,
"is_location": structure["attributes"]["is_location"],
"is_fixed": structure["attributes"]["is_fixed"],
"active": active,
"archived": archived,
"notes": notes,
"image_url": image_url,
}

View file

@ -67,7 +67,7 @@ class AnimalTypeView(WuttaFarmMasterView):
"sex",
"is_sterile",
"birthdate",
"active",
"archived",
]
rows_sort_defaults = "name"

View file

@ -46,7 +46,7 @@ class AnimalView(WuttaFarmMasterView):
"sex",
"is_sterile",
"birthdate",
"active",
"archived",
]
sort_defaults = "name"
@ -61,7 +61,7 @@ class AnimalView(WuttaFarmMasterView):
"birthdate",
"sex",
"is_sterile",
"active",
"archived",
"notes",
"farmos_uuid",
"drupal_id",
@ -94,7 +94,9 @@ class AnimalView(WuttaFarmMasterView):
f.set_widget("notes", "notes")
# image
if animal.image_url:
if self.creating:
f.remove("image")
elif animal.image_url:
f.set_widget("image", ImageWidget("animal image"))
f.set_default("image", animal.image_url)

View file

@ -42,7 +42,7 @@ class GroupView(WuttaFarmMasterView):
"name",
"is_location",
"is_fixed",
"active",
"archived",
]
sort_defaults = "name"
@ -55,7 +55,7 @@ class GroupView(WuttaFarmMasterView):
"name",
"is_location",
"is_fixed",
"active",
"archived",
"notes",
"farmos_uuid",
"drupal_id",

View file

@ -45,7 +45,7 @@ class LandAssetView(WuttaFarmMasterView):
"is_location",
"is_fixed",
"notes",
"active",
"archived",
]
sort_defaults = "name"
@ -60,7 +60,7 @@ class LandAssetView(WuttaFarmMasterView):
"is_location",
"is_fixed",
"notes",
"active",
"archived",
"farmos_uuid",
"drupal_id",
]

View file

@ -60,7 +60,7 @@ class LandTypeView(WuttaFarmMasterView):
"name",
"is_location",
"is_fixed",
"active",
"archived",
]
rows_sort_defaults = "name"

View file

@ -60,7 +60,7 @@ class StructureTypeView(WuttaFarmMasterView):
"name",
"is_location",
"is_fixed",
"active",
"archived",
]
rows_sort_defaults = "name"

View file

@ -45,7 +45,7 @@ class StructureView(WuttaFarmMasterView):
"structure_type",
"is_location",
"is_fixed",
"active",
"archived",
]
sort_defaults = "name"
@ -60,7 +60,7 @@ class StructureView(WuttaFarmMasterView):
"is_location",
"is_fixed",
"notes",
"active",
"archived",
"farmos_uuid",
"drupal_id",
"image_url",