🗄️ Database Design

Enterprise-grade PostgreSQL architecture with advanced indexing, relationships, and performance optimization

📊 View comprehensive ERD below showing all 23 tables and their relationships

🐘 PostgreSQL 15+
Modern relational database with JSON support, advanced indexing, full-text search, and enterprise reliability
🔗 Normalized Schema
Well-designed relational schema with proper normalization, foreign key constraints, and data integrity
⚡ Performance Optimized
Strategic indexing, query optimization, connection pooling, and efficient data access patterns
🔄 Migration Ready
Alembic-powered schema migrations with version control, rollback capabilities, and deployment automation

🏗️ Schema Architecture

SysManage implements a comprehensive relational schema designed for scalability, performance, and data integrity.

👥 User Management Schema

Authentication & Authorization: Complete user management system with secure password hashing, JWT tokens, role-based access control, user groups, and profile management including image uploads and account locking mechanisms.

🖥️ Host Management Schema

Infrastructure Tracking: Comprehensive host information including hardware specifications, operating system details, network interfaces, storage devices, certificate management, and real-time status monitoring.

📦 Package Management Schema

Software Inventory: Complete package tracking system including installed packages, available packages, update operations, dependency management, and package operation history with detailed execution logs.

📜 Script Management Schema

Automation Framework: Script repository with version control, execution tracking, parameter management, result storage, and comprehensive audit trails for all script operations.

📨 Message Queue Schema

Communication Infrastructure: Persistent message queuing system with delivery tracking, retry logic, expiration handling, and comprehensive message lifecycle management.

🏷️ Tagging & Organization Schema

Flexible Categorization: Dynamic tagging system for hosts and resources with hierarchical organization, color coding, and advanced filtering capabilities.

🗄️ Entity Relationship Diagram

The following diagram shows the complete database schema with all tables, relationships, and key constraints:

SysManage Database Entity Relationship Diagram

Click diagram to open full-size version

Key Diagram Features

🏗️ Core Entities
User, Host, BearerToken
🖥️ Hardware
StorageDevice, NetworkInterface
📦 Software
Packages, Updates, Operations
📡 Messaging
MessageQueue, QueueMetrics
🔐 Authentication
Users, Tokens, Groups

📊 Core Table Relationships

👤
users

Central user registry with authentication credentials, profile information, and account management features.

🖥️
hosts

Complete host inventory with hardware specs, OS information, network configuration, and status tracking.

📦
software_packages

Installed package inventory with version tracking, installation dates, and dependency relationships.

🛒
available_packages

Package repository information with available versions, descriptions, and OS compatibility.

🔄
package_operations

Package operation history including installs, updates, removals with execution status and logs.

📜
scripts

Script repository with content, parameters, execution history, and version management.

📨
message_queue

Persistent message storage with delivery tracking, retry logic, and expiration management.

🏷️
tags

Dynamic tagging system for flexible resource organization and advanced filtering.

🌐
network_interfaces

Network configuration tracking with IP addresses, MAC addresses, and interface status.

💾
storage_devices

Storage hardware inventory with capacity, usage, health status, and performance metrics.

👥
user_groups

Role-based access control with group memberships and permission inheritance.

🔒
issued_tokens

JWT token management with expiration tracking and revocation capabilities.

⚡ Indexing Strategy

Performance-Optimized Database Indexes

🔍
Primary Key Indexes
🔗
Foreign Key Indexes
Composite Indexes
🎯
Unique Constraints
📝
Full-Text Search
📊
JSON Path Indexes
Timestamp Indexes
🏷️
Status Indexes

🚀 Advanced Features

📄
JSON Columns

Native PostgreSQL JSON support for flexible schema evolution, metadata storage, and complex configuration data.

🔍
Full-Text Search

Built-in PostgreSQL text search capabilities for efficient content searching across multiple columns and tables.

🔗
Foreign Key Constraints

Strict referential integrity with CASCADE options ensuring data consistency across related tables.

Connection Pooling

SQLAlchemy connection pooling with configurable pool sizes and connection lifecycle management.

🕐
Timezone Awareness

Proper timezone handling with UTC storage and automatic timezone conversion for global deployments.

🛡️
ACID Compliance

Full ACID transaction support ensuring data integrity even during complex multi-table operations.

💻 Schema Examples

Host Table Structure

Core Host Information
CREATE TABLE hosts ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), fqdn VARCHAR(255) NOT NULL UNIQUE, platform VARCHAR(50), platform_version VARCHAR(100), architecture VARCHAR(50), cpu_count INTEGER, memory_gb NUMERIC(10,2), last_seen TIMESTAMP WITH TIME ZONE, active BOOLEAN DEFAULT true, approval_status VARCHAR(20) DEFAULT 'pending', enabled_shells JSONB, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP ); -- Indexes for performance CREATE INDEX idx_hosts_fqdn ON hosts(fqdn); CREATE INDEX idx_hosts_active ON hosts(active); CREATE INDEX idx_hosts_platform ON hosts(platform, platform_version); CREATE INDEX idx_hosts_last_seen ON hosts(last_seen);

Package Operation Tracking

Package Management History
CREATE TABLE package_operations ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), host_id UUID NOT NULL REFERENCES hosts(id) ON DELETE CASCADE, operation_type VARCHAR(20) NOT NULL, package_name VARCHAR(255) NOT NULL, package_version VARCHAR(100), status VARCHAR(20) DEFAULT 'pending', started_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, completed_at TIMESTAMP WITH TIME ZONE, execution_log TEXT, error_message TEXT ); -- Composite index for efficient queries CREATE INDEX idx_pkg_ops_host_status ON package_operations(host_id, status); CREATE INDEX idx_pkg_ops_package ON package_operations(package_name, operation_type);

Message Queue Implementation

Persistent Message Storage
CREATE TABLE message_queue ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), target_host_id UUID REFERENCES hosts(id) ON DELETE CASCADE, message_type VARCHAR(50) NOT NULL, message_content JSONB NOT NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, expires_at TIMESTAMP WITH TIME ZONE, delivered_at TIMESTAMP WITH TIME ZONE, status VARCHAR(20) DEFAULT 'pending', retry_count INTEGER DEFAULT 0, last_retry_at TIMESTAMP WITH TIME ZONE ); -- Indexes for message processing CREATE INDEX idx_msg_queue_target ON message_queue(target_host_id, status); CREATE INDEX idx_msg_queue_expires ON message_queue(expires_at); CREATE INDEX idx_msg_queue_type ON message_queue(message_type);

🔄 Migration Strategy

Alembic Migration Workflow

1
Schema Changes
Modify SQLAlchemy models with new fields, relationships, or constraints
2
Generate Migration
Use Alembic autogenerate to create migration script with review and customization
3
Test Migration
Validate migration on development database with rollback testing
4
Deploy Migration
Execute migration in production with backup and monitoring
5
Verify Integrity
Confirm data integrity and application functionality post-migration

📊 Performance Metrics

<10ms
Query Response Time
1M+
Records per Table
99.9%
Database Uptime
100+
Concurrent Connections

🔗 Related Documentation