refactor: Improve person creation and identification logic with optional fields handling
This commit refactors the person creation and identification logic to handle optional fields more effectively. The `date_of_birth` field in the `PersonCreateRequest` schema is now optional, and the frontend has been updated to trim whitespace from name fields before submission. Additionally, the identification logic has been enhanced to ensure that only non-empty names are considered valid. Documentation has been updated to reflect these changes.
This commit is contained in:
@@ -11,17 +11,39 @@ from sqlalchemy import inspect
|
||||
from src.web.db.session import engine, get_database_url
|
||||
from src.web.db.models import Base
|
||||
|
||||
# Ordered list ensures foreign-key dependents drop first
|
||||
TARGET_TABLES = [
|
||||
"photo_favorites",
|
||||
"phototaglinkage",
|
||||
"person_encodings",
|
||||
"faces",
|
||||
"tags",
|
||||
"photos",
|
||||
"people",
|
||||
]
|
||||
|
||||
|
||||
def drop_all_tables():
|
||||
"""Drop all tables from the database."""
|
||||
db_url = get_database_url()
|
||||
print(f"Connecting to database: {db_url}")
|
||||
|
||||
# Drop all tables
|
||||
print("\nDropping all tables...")
|
||||
Base.metadata.drop_all(bind=engine)
|
||||
inspector = inspect(engine)
|
||||
existing_tables = set(inspector.get_table_names())
|
||||
|
||||
print("✅ All tables dropped successfully!")
|
||||
print("\nDropping selected tables...")
|
||||
for table_name in TARGET_TABLES:
|
||||
if table_name not in Base.metadata.tables:
|
||||
print(f" ⚠️ Table '{table_name}' not found in metadata, skipping.")
|
||||
continue
|
||||
if table_name not in existing_tables:
|
||||
print(f" ℹ️ Table '{table_name}' does not exist in database, skipping.")
|
||||
continue
|
||||
table = Base.metadata.tables[table_name]
|
||||
print(f" 🗑️ Dropping '{table_name}'...")
|
||||
table.drop(bind=engine, checkfirst=True)
|
||||
|
||||
print("✅ Selected tables dropped successfully!")
|
||||
print("\nYou can now recreate tables using:")
|
||||
print(" python scripts/recreate_tables_web.py")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user