From b9a06370359d9795f69dd2c9cbbe8c64c192c2ca Mon Sep 17 00:00:00 2001 From: tanyar09 Date: Mon, 6 Oct 2025 14:42:22 -0400 Subject: [PATCH] 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. --- database.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/database.py b/database.py index c6ed79e..f58cc71 100644 --- a/database.py +++ b/database.py @@ -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}")