Renaming Occular to Ocular

This commit is contained in:
Ian Roddis committed 2026-08-17 16:55:57 -03:00
1 parent ce2bdc43a8
commit a35d064e32
2 files changed
+14 -36

No files matched your search

+10 -26
View File
@@ -17,7 +17,7 @@ Phase 2 – create entries for new ImportedParts
• Type ← first PartType whose name is a substring of the description • Type ← first PartType whose name is a substring of the description
(longest name wins; skipped if no match) (longest name wins; skipped if no match)
• SubType ← null • SubType ← null
• Attachment point ← always named "Occular"; one of: • Attachment point ← always named "Ocular"; one of:
- ISO/UNC thread parsed from TBXThreadAttribute (using the - ISO/UNC thread parsed from TBXThreadAttribute (using the
matching ProductMaxThreadDepth mm/in if populated), or matching ProductMaxThreadDepth mm/in if populated), or
- StaticConnection from ProductODmm/ProductODin (whichever - StaticConnection from ProductODmm/ProductODin (whichever
@@ -46,7 +46,7 @@ from app.models.part_type import PartType
from app.models.unc_thread import UncSeries from app.models.unc_thread import UncSeries
from app.schemas.augmented_part import AugmentedPartSyncResult from app.schemas.augmented_part import AugmentedPartSyncResult
ATTACHMENT_POINT_NAME = "Occular" ATTACHMENT_POINT_NAME = "Ocular"
MM_PER_INCH = 25.4 MM_PER_INCH = 25.4
# e.g. # e.g.
@@ -111,9 +111,7 @@ async def _get_or_create_attachment_point_name(db: AsyncSession, name: str):
return apn return apn
async def _add_attachment_point( async def _add_attachment_point(db: AsyncSession, ap: AugmentedPart, ip: ImportedPart) -> None:
db: AsyncSession, ap: AugmentedPart, ip: ImportedPart
) -> None:
"""Infer and create an attachment point for a newly-synced AugmentedPart. """Infer and create an attachment point for a newly-synced AugmentedPart.
Preference order: TBXThreadAttribute (ISO/UNC thread) then ProductODmm/in Preference order: TBXThreadAttribute (ISO/UNC thread) then ProductODmm/in
@@ -133,9 +131,7 @@ async def _add_attachment_point(
if kind == "iso": if kind == "iso":
depth_mm = _parse_float(ip.ProductMaxThreadDepthmm) depth_mm = _parse_float(ip.ProductMaxThreadDepthmm)
thread = await iso_thread_crud.get_by_values( thread = await iso_thread_crud.get_by_values(db, depth_mm=depth_mm, **fields)
db, depth_mm=depth_mm, **fields
)
if thread is None: if thread is None:
thread = await iso_thread_crud.create(db, depth_mm=depth_mm, **fields) thread = await iso_thread_crud.create(db, depth_mm=depth_mm, **fields)
await attachment_point_crud.create( await attachment_point_crud.create(
@@ -146,9 +142,7 @@ async def _add_attachment_point(
) )
elif kind == "unc": elif kind == "unc":
depth_in = _parse_float(ip.ProductMaxThreadDepthin) depth_in = _parse_float(ip.ProductMaxThreadDepthin)
thread = await unc_thread_crud.get_by_values( thread = await unc_thread_crud.get_by_values(db, depth_in=depth_in, **fields)
db, depth_in=depth_in, **fields
)
if thread is None: if thread is None:
thread = await unc_thread_crud.create(db, depth_in=depth_in, **fields) thread = await unc_thread_crud.create(db, depth_in=depth_in, **fields)
await attachment_point_crud.create( await attachment_point_crud.create(
@@ -246,9 +240,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
# ------------------------------------------------------------------ phase 1 # ------------------------------------------------------------------ phase 1
# IDs referenced in existing associations # IDs referenced in existing associations
result = await db.execute( result = await db.execute(select(augmented_part_imported_parts.c.imported_part_id).distinct())
select(augmented_part_imported_parts.c.imported_part_id).distinct()
)
all_linked_ids: set[str] = {row[0] for row in result.all()} all_linked_ids: set[str] = {row[0] for row in result.all()}
# IDs that still exist in imported_parts # IDs that still exist in imported_parts
@@ -262,9 +254,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
# Which AugmentedParts are affected? # Which AugmentedParts are affected?
result = await db.execute( result = await db.execute(
select(augmented_part_imported_parts.c.augmented_part_id).where( select(augmented_part_imported_parts.c.augmented_part_id).where(
augmented_part_imported_parts.c.imported_part_id.in_( augmented_part_imported_parts.c.imported_part_id.in_(orphaned_import_ids)
orphaned_import_ids
)
) )
) )
orphaned_ap_ids: set[int] = {row[0] for row in result.all()} orphaned_ap_ids: set[int] = {row[0] for row in result.all()}
@@ -272,9 +262,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
# Remove the stale association rows # Remove the stale association rows
await db.execute( await db.execute(
augmented_part_imported_parts.delete().where( augmented_part_imported_parts.delete().where(
augmented_part_imported_parts.c.imported_part_id.in_( augmented_part_imported_parts.c.imported_part_id.in_(orphaned_import_ids)
orphaned_import_ids
)
) )
) )
await db.flush() await db.flush()
@@ -297,9 +285,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
# ------------------------------------------------------------------ phase 2 # ------------------------------------------------------------------ phase 2
# Re-query linked IDs after phase 1 cleanup # Re-query linked IDs after phase 1 cleanup
result = await db.execute( result = await db.execute(select(augmented_part_imported_parts.c.imported_part_id).distinct())
select(augmented_part_imported_parts.c.imported_part_id).distinct()
)
now_linked_ids: set[str] = {row[0] for row in result.all()} now_linked_ids: set[str] = {row[0] for row in result.all()}
unlinked_ids = current_ids - now_linked_ids unlinked_ids = current_ids - now_linked_ids
@@ -307,9 +293,7 @@ async def sync(db: AsyncSession) -> AugmentedPartSyncResult:
skipped = 0 skipped = 0
if not unlinked_ids: if not unlinked_ids:
return AugmentedPartSyncResult( return AugmentedPartSyncResult(created=created, deleted=deleted, skipped=skipped)
created=created, deleted=deleted, skipped=skipped
)
result = await db.execute( result = await db.execute(
select(ImportedPart).where(ImportedPart.InventoryID.in_(unlinked_ids)) select(ImportedPart).where(ImportedPart.InventoryID.in_(unlinked_ids))
+4 -10
View File
@@ -17,7 +17,7 @@ from app.crud import role as role_crud
from app.crud import sub_part_type as sub_part_type_crud from app.crud import sub_part_type as sub_part_type_crud
from app.crud import user as user_crud from app.crud import user as user_crud
ATTACHMENT_POINT_NAMES = ["Objective", "Occular"] ATTACHMENT_POINT_NAMES = ["Objective", "Ocular", "Rail"]
PART_TYPES = ["Flip Cover", "ARD", "Polarizer", "Adapter Ring", "Scope"] PART_TYPES = ["Flip Cover", "ARD", "Polarizer", "Adapter Ring", "Scope"]
@@ -113,9 +113,7 @@ async def seed() -> None:
for name, description in PERMISSIONS: for name, description in PERMISSIONS:
perm = await role_crud.get_permission_by_name(db, name) perm = await role_crud.get_permission_by_name(db, name)
if perm is None: if perm is None:
perm = await role_crud.create_permission( perm = await role_crud.create_permission(db, name=name, description=description)
db, name=name, description=description
)
perms[name] = perm perms[name] = perm
# Roles # Roles
@@ -153,14 +151,10 @@ async def seed() -> None:
if pt is not None: if pt is not None:
for spt_name in spt_names: for spt_name in spt_names:
if ( if (
await sub_part_type_crud.get_by_name_and_part_type( await sub_part_type_crud.get_by_name_and_part_type(db, spt_name, pt.id)
db, spt_name, pt.id
)
is None is None
): ):
await sub_part_type_crud.create( await sub_part_type_crud.create(db, name=spt_name, part_type_id=pt.id)
db, name=spt_name, part_type_id=pt.id
)
# Superuser # Superuser
existing = await user_crud.get_by_email(db, settings.first_superuser_email) existing = await user_crud.get_by_email(db, settings.first_superuser_email)