Enhance database schema with photo-tag linkage type and remove redundant migrations

This commit adds a new column, linkage_type, to the phototaglinkage table to distinguish between single and bulk tag additions. Additionally, the previous migration attempts to add date_taken and date_added columns to the photos table have been removed, streamlining the database initialization process. These changes improve the database structure for better tag management.
This commit is contained in:
tanyar09 2025-10-06 14:42:22 -04:00
parent 01404418f7
commit b9a0637035

View File

@ -114,11 +114,13 @@ class DatabaseManager:
''')
# Photo-Tag linkage table
# linkage_type: INTEGER enum → 0 = single (per-photo add), 1 = bulk (folder-wide add)
cursor.execute('''
CREATE TABLE IF NOT EXISTS phototaglinkage (
linkage_id INTEGER PRIMARY KEY AUTOINCREMENT,
photo_id INTEGER NOT NULL,
tag_id INTEGER NOT NULL,
linkage_type INTEGER NOT NULL DEFAULT 0 CHECK(linkage_type IN (0,1)),
created_date DATETIME DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (photo_id) REFERENCES photos (id),
FOREIGN KEY (tag_id) REFERENCES tags (id),
@ -136,23 +138,7 @@ class DatabaseManager:
cursor.execute('CREATE INDEX IF NOT EXISTS idx_photos_date_taken ON photos(date_taken)')
cursor.execute('CREATE INDEX IF NOT EXISTS idx_photos_date_added ON photos(date_added)')
# Migration: Add date_taken column to existing photos table if it doesn't exist
try:
cursor.execute('ALTER TABLE photos ADD COLUMN date_taken DATE')
if self.verbose >= 1:
print("✅ Added date_taken column to photos table")
except Exception:
# Column already exists, ignore
pass
# Migration: Add date_added column to existing photos table if it doesn't exist
try:
cursor.execute('ALTER TABLE photos ADD COLUMN date_added DATETIME DEFAULT CURRENT_TIMESTAMP')
if self.verbose >= 1:
print("✅ Added date_added column to photos table")
except Exception:
# Column already exists, ignore
pass
if self.verbose >= 1:
print(f"✅ Database initialized: {self.db_path}")