base
This commit is contained in:
11
app/main.py
11
app/main.py
@@ -49,7 +49,7 @@ class DiskReorganizer:
|
|||||||
"""
|
"""
|
||||||
if db_config is None:
|
if db_config is None:
|
||||||
db_config = {
|
db_config = {
|
||||||
'host': os.getenv('DB_HOST', 'localhost'),
|
'host': os.getenv('DB_HOST', '192.168.1.159'),
|
||||||
'port': int(os.getenv('DB_PORT', 5432)),
|
'port': int(os.getenv('DB_PORT', 5432)),
|
||||||
'database': os.getenv('DB_NAME', 'disk_reorganizer_db'),
|
'database': os.getenv('DB_NAME', 'disk_reorganizer_db'),
|
||||||
'user': os.getenv('DB_USER', 'disk_reorg_user'),
|
'user': os.getenv('DB_USER', 'disk_reorg_user'),
|
||||||
@@ -120,7 +120,7 @@ class DiskReorganizer:
|
|||||||
|
|
||||||
stat = file_path.stat()
|
stat = file_path.stat()
|
||||||
size = stat.st_size
|
size = stat.st_size
|
||||||
mtime = stat.st_mtime
|
mtime = datetime.fromtimestamp(stat.st_mtime)
|
||||||
|
|
||||||
# Calculate relative path for portability
|
# Calculate relative path for portability
|
||||||
rel_path = str(file_path.relative_to(disk_path))
|
rel_path = str(file_path.relative_to(disk_path))
|
||||||
@@ -156,6 +156,7 @@ class DiskReorganizer:
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
conn.rollback()
|
||||||
logger.warning(f"\nSkipping {file_path}: {e}")
|
logger.warning(f"\nSkipping {file_path}: {e}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@@ -182,8 +183,8 @@ class DiskReorganizer:
|
|||||||
usage = {}
|
usage = {}
|
||||||
for row in cursor.fetchall():
|
for row in cursor.fetchall():
|
||||||
disk = row[0]
|
disk = row[0]
|
||||||
size = row[1] or 0
|
size = int(row[1] or 0)
|
||||||
count = row[2]
|
count = int(row[2])
|
||||||
usage[disk] = {
|
usage[disk] = {
|
||||||
'size': size,
|
'size': size,
|
||||||
'count': count,
|
'count': count,
|
||||||
@@ -266,7 +267,7 @@ class DiskReorganizer:
|
|||||||
'source_path': rel_path,
|
'source_path': rel_path,
|
||||||
'dest_disk': dest_disk,
|
'dest_disk': dest_disk,
|
||||||
'target_path': rel_path, # Keep same relative path
|
'target_path': rel_path, # Keep same relative path
|
||||||
'size': size
|
'size': int(size)
|
||||||
}
|
}
|
||||||
plan['operations'].append(op)
|
plan['operations'].append(op)
|
||||||
|
|
||||||
|
|||||||
@@ -54,9 +54,15 @@ CREATE INDEX IF NOT EXISTS idx_operations_source ON operations(source_path);
|
|||||||
-- Grant privileges to disk_reorg_user
|
-- Grant privileges to disk_reorg_user
|
||||||
GRANT CONNECT ON DATABASE disk_reorganizer_db 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 USAGE ON SCHEMA public TO disk_reorg_user;
|
||||||
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE files TO disk_reorg_user;
|
GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO disk_reorg_user;
|
||||||
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE operations TO disk_reorg_user;
|
GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO disk_reorg_user;
|
||||||
GRANT USAGE, SELECT ON SEQUENCE operations_id_seq 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 function to update updated_at timestamp
|
||||||
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
CREATE OR REPLACE FUNCTION update_updated_at_column()
|
||||||
|
|||||||
Reference in New Issue
Block a user