diff --git a/app/main.py b/app/main.py index 4096926..3181775 100644 --- a/app/main.py +++ b/app/main.py @@ -49,7 +49,7 @@ class DiskReorganizer: """ if db_config is None: db_config = { - 'host': os.getenv('DB_HOST', 'localhost'), + 'host': os.getenv('DB_HOST', '192.168.1.159'), 'port': int(os.getenv('DB_PORT', 5432)), 'database': os.getenv('DB_NAME', 'disk_reorganizer_db'), 'user': os.getenv('DB_USER', 'disk_reorg_user'), @@ -120,7 +120,7 @@ class DiskReorganizer: stat = file_path.stat() size = stat.st_size - mtime = stat.st_mtime + mtime = datetime.fromtimestamp(stat.st_mtime) # Calculate relative path for portability rel_path = str(file_path.relative_to(disk_path)) @@ -156,6 +156,7 @@ class DiskReorganizer: conn.commit() except Exception as e: + conn.rollback() logger.warning(f"\nSkipping {file_path}: {e}") continue @@ -182,8 +183,8 @@ class DiskReorganizer: usage = {} for row in cursor.fetchall(): disk = row[0] - size = row[1] or 0 - count = row[2] + size = int(row[1] or 0) + count = int(row[2]) usage[disk] = { 'size': size, 'count': count, @@ -266,7 +267,7 @@ class DiskReorganizer: 'source_path': rel_path, 'dest_disk': dest_disk, 'target_path': rel_path, # Keep same relative path - 'size': size + 'size': int(size) } plan['operations'].append(op) diff --git a/sql/setup_database.sql b/sql/setup_database.sql index 8eee7b5..0745998 100644 --- a/sql/setup_database.sql +++ b/sql/setup_database.sql @@ -54,9 +54,15 @@ CREATE INDEX IF NOT EXISTS idx_operations_source ON operations(source_path); -- Grant privileges to disk_reorg_user GRANT CONNECT ON DATABASE disk_reorganizer_db TO disk_reorg_user; GRANT USAGE ON SCHEMA public TO disk_reorg_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE files TO disk_reorg_user; -GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE operations TO disk_reorg_user; -GRANT USAGE, SELECT ON SEQUENCE operations_id_seq TO disk_reorg_user; +GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO disk_reorg_user; +GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO disk_reorg_user; + +-- future tables/sequences created by your owner role (pick the role that creates them) +ALTER DEFAULT PRIVILEGES FOR ROLE auction IN SCHEMA public + GRANT ALL PRIVILEGES ON TABLES TO disk_reorg_user; + +ALTER DEFAULT PRIVILEGES FOR ROLE auction IN SCHEMA public + GRANT ALL PRIVILEGES ON SEQUENCES TO disk_reorg_user; -- Create function to update updated_at timestamp CREATE OR REPLACE FUNCTION update_updated_at_column()