Fixing imports
This commit is contained in:
1 parent
8d37b2ad67
commit
3ebe9a0894
6 files changed
+316
No files matched your search
@@ -0,0 +1,57 @@
|
||||
"""Irreversible bulk-delete of all domain (parts/taxonomy/fit) data.
|
||||
|
||||
Leaves users, roles/permissions, refresh tokens, the audit log, and the
|
||||
ImportedPartConfig (OData connection settings) untouched.
|
||||
"""
|
||||
|
||||
from sqlalchemy import delete
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.models.associations import augmented_part_imported_parts
|
||||
from app.models.attachment_point import AttachmentPoint
|
||||
from app.models.attachment_point_name import AttachmentPointName
|
||||
from app.models.augmented_part import AugmentedPart, AugmentedPartNote
|
||||
from app.models.clamp_connection import ClampConnection
|
||||
from app.models.fit import Fit, FitNote
|
||||
from app.models.imported_part import ImportedPart
|
||||
from app.models.iso_thread import IsoThread
|
||||
from app.models.manufacturer import Manufacturer
|
||||
from app.models.part_colour import PartColour
|
||||
from app.models.part_type import PartType
|
||||
from app.models.scope_info import ScopeInfo
|
||||
from app.models.scope_model import ScopeModel
|
||||
from app.models.static_connection import StaticConnection
|
||||
from app.models.sub_part_type import SubPartType
|
||||
from app.models.unc_thread import UncThread
|
||||
|
||||
# Children before the RESTRICT-protected reference tables they point to.
|
||||
_TARGETS = [
|
||||
("Fit notes", FitNote),
|
||||
("Fits", Fit),
|
||||
("Augmented part notes", AugmentedPartNote),
|
||||
("Scope info", ScopeInfo),
|
||||
("Attachment points", AttachmentPoint),
|
||||
("Augmented part / imported part links", augmented_part_imported_parts),
|
||||
("Augmented parts", AugmentedPart),
|
||||
("Imported parts", ImportedPart),
|
||||
("Scope models", ScopeModel),
|
||||
("Attachment point names", AttachmentPointName),
|
||||
("ISO threads", IsoThread),
|
||||
("UNC threads", UncThread),
|
||||
("Clamp connections", ClampConnection),
|
||||
("Static connections", StaticConnection),
|
||||
("Manufacturers", Manufacturer),
|
||||
]
|
||||
|
||||
|
||||
async def purge_domain_data(db: AsyncSession) -> dict[str, int]:
|
||||
"""Delete every row from every domain table, in FK-safe order.
|
||||
|
||||
Returns a label -> rows-deleted map for reporting/audit purposes.
|
||||
"""
|
||||
counts: dict[str, int] = {}
|
||||
for label, target in _TARGETS:
|
||||
result = await db.execute(delete(target))
|
||||
counts[label] = result.rowcount or 0
|
||||
await db.commit()
|
||||
return counts
|
||||
Reference in new issue
Block a user