This commit is contained in:
mike
2025-12-12 19:25:16 +01:00
parent 5e0db89d45
commit 56b2db82fc
34 changed files with 117 additions and 6556 deletions

View File

@@ -37,7 +37,7 @@ CREATE TABLE IF NOT EXISTS operations (
status VARCHAR(20) NOT NULL,
-- File reference
file_id UUID REFERENCES files(id) ON DELETE SET NULL,
file_id UUID REFERENCES files_bak(id) ON DELETE SET NULL,
-- Performance metrics
duration_ms INTEGER,
@@ -89,14 +89,14 @@ CREATE TABLE IF NOT EXISTS migration_plans (
);
-- Indexes for performance
CREATE INDEX IF NOT EXISTS idx_files_path ON files(path);
CREATE INDEX IF NOT EXISTS idx_files_hash ON files(file_hash);
CREATE INDEX IF NOT EXISTS idx_files_disk ON files(disk_label);
CREATE INDEX IF NOT EXISTS idx_files_category ON files(category);
CREATE INDEX IF NOT EXISTS idx_files_path ON files_bak(path);
CREATE INDEX IF NOT EXISTS idx_files_hash ON files_bak(file_hash);
CREATE INDEX IF NOT EXISTS idx_files_disk ON files_bak(disk_label);
CREATE INDEX IF NOT EXISTS idx_files_category ON files_bak(category);
CREATE INDEX IF NOT EXISTS idx_operations_status ON operations(status);
CREATE INDEX IF NOT EXISTS idx_operations_created ON operations(created_at);
CREATE INDEX IF NOT EXISTS idx_operations_file_id ON operations(file_id);
CREATE INDEX IF NOT EXISTS idx_operations_status ON operations_bak(status);
CREATE INDEX IF NOT EXISTS idx_operations_created ON operations_bak(created_at);
CREATE INDEX IF NOT EXISTS idx_operations_file_id ON operations_bak(file_id);
CREATE INDEX IF NOT EXISTS idx_dedup_canonical ON deduplication_store(canonical_path);
@@ -110,7 +110,7 @@ END;
$$ language 'plpgsql';
-- Triggers for automatic updated_at
CREATE TRIGGER update_files_updated_at BEFORE UPDATE ON files
CREATE TRIGGER update_files_updated_at BEFORE UPDATE ON files_bak
FOR EACH ROW EXECUTE FUNCTION update_updated_at_column();
-- View for operational dashboard
@@ -122,7 +122,7 @@ SELECT
AVG(o.duration_ms) as avg_duration_ms,
MIN(o.started_at) as earliest_operation,
MAX(o.completed_at) as latest_operation
FROM operations o
FROM operations_bak o
WHERE o.started_at > CURRENT_TIMESTAMP - INTERVAL '24 hours'
GROUP BY o.status;
@@ -135,7 +135,7 @@ SELECT
AVG(size) as avg_file_size,
MIN(created_time) as oldest_file,
MAX(modified_time) as newest_file
FROM files
FROM files_bak
GROUP BY disk_label;
-- Insert default configuration

View File

@@ -1,6 +1,8 @@
-- PostgreSQL Database Setup Script for Disk Reorganizer
-- Database: disk_reorganizer_db
-- User: disk_reorg_user
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
-- Create the database (run as superuser: auction)
CREATE DATABASE disk_reorganizer_db