kasl/db/mod.rs
1//! Database layer for the kasl application.
2//!
3//! Provides a complete data persistence layer built on SQLite, offering type-safe
4//! database operations for all application entities. Implements a migration system
5//! for schema evolution and provides specialized modules for different data types.
6//!
7//! ## Features
8//!
9//! - **Core Infrastructure**: Connection management and migrations
10//! - **Time Tracking**: Workdays and pause records for activity monitoring
11//! - **Task Management**: Tasks, templates, and organizational features
12//! - **Productivity Analytics**: Data aggregation and reporting support
13//!
14//! ## Usage
15//!
16//! ```rust
17//! use kasl::db::{db::Db, tasks::Tasks, workdays::Workdays};
18//! use kasl::libs::task::Task;
19//!
20//! let db = Db::new()?;
21//! let mut tasks = Tasks::new()?;
22//! let task = Task::new("Review code", "Check PR #123", Some(75));
23//! tasks.insert(&task)?;
24//! ```
25//!
26//! ```rust
27//! use kasl::db::{tags::Tags, templates::Templates};
28//!
29//! // Create and manage tags
30//! let mut tags = Tags::new()?;
31//! let tag_id = tags.create(&Tag::new("urgent".to_string(), Some("red".to_string())))?;
32//!
33//! // Work with task templates
34//! let mut templates = Templates::new()?;
35//! let template = TaskTemplate::new(
36//! "daily-standup".to_string(),
37//! "Attend daily standup meeting".to_string(),
38//! "Team sync and planning".to_string(),
39//! 100
40//! );
41//! templates.create(&template)?;
42//! ```
43//!
44//! ## Performance Considerations
45//!
46//! ### Indexing Strategy
47//! - **Temporal Queries**: Optimized indexes on timestamp columns
48//! - **Relationship Lookups**: Efficient foreign key index coverage
49//! - **Search Operations**: Selective indexes for common query patterns
50//!
51//! ### Connection Management
52//! - **Connection Reuse**: Long-lived connections for better performance
53//! - **Transaction Batching**: Grouped operations for improved throughput
54//! - **Statement Preparation**: Cached prepared statements for repeated queries
55//!
56//! ### Data Volume Handling
57//! - **Pagination Support**: Efficient handling of large result sets
58//! - **Selective Loading**: Fetch only required fields for large tables
59//! - **Archive Strategy**: Data retention policies for long-term usage
60//!
61//! ## Migration Best Practices
62//!
63//! ### Schema Evolution
64//! ```rust
65//! // Adding a new column (backward compatible)
66//! tx.execute("ALTER TABLE tasks ADD COLUMN priority INTEGER DEFAULT 1", [])?;
67//!
68//! // Creating new indexes for performance
69//! tx.execute("CREATE INDEX idx_tasks_priority ON tasks(priority)", [])?;
70//!
71//! // Adding new tables with proper foreign keys
72//! tx.execute("CREATE TABLE task_dependencies (
73//! id INTEGER PRIMARY KEY,
74//! task_id INTEGER NOT NULL,
75//! depends_on INTEGER NOT NULL,
76//! FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE,
77//! FOREIGN KEY (depends_on) REFERENCES tasks(id) ON DELETE CASCADE
78//! )", [])?;
79//! ```
80//!
81//! ### Version Control Integration
82//! - **Sequential Versioning**: Each migration increments the version number
83//! - **Descriptive Names**: Clear migration names describing the change
84//! - **Testing Requirements**: All migrations must be tested before deployment
85//! - **Rollback Planning**: Consider rollback implications for schema changes
86//!
87//! ## Platform-Specific Considerations
88//!
89//! ### File System Integration
90//! - **Windows**: Handles path length limitations and permission requirements
91//! - **macOS**: Integrates with application sandbox restrictions
92//! - **Linux**: Follows XDG base directory specifications
93//!
94//! ### Backup and Recovery
95//! - **Export Functionality**: Complete data export in multiple formats
96//! - **Import Validation**: Schema validation during data import
97//! - **Corruption Recovery**: Database integrity checks and repair options
98//!
99//! ## Development and Debugging
100//!
101//! ### Debug Features
102//! - **Migration Inspection**: View current schema version and history
103//! - **Query Logging**: Optional SQL query logging for performance analysis
104//! - **Connection Monitoring**: Track active connections and lock contention
105//!
106//! ### Testing Support
107//! - **In-Memory Databases**: Fast test execution with temporary databases
108//! - **Fixture Management**: Consistent test data setup and teardown
109//! - **Migration Testing**: Automated testing of schema changes
110
111/// Core database connection and initialization module.
112///
113/// Provides the fundamental `Db` struct that manages SQLite connections,
114/// applies migrations, and ensures proper database configuration.
115#[allow(clippy::module_inception)] // kasl::db::db::Db is the established public path
116pub mod db;
117
118/// Database schema migration system.
119///
120/// Handles versioned schema changes, tracks migration history, and provides
121/// development-time migration management commands.
122pub mod migrations;
123
124/// Manual break period management.
125///
126/// Handles user-defined break periods for productivity optimization, allowing
127/// manual addition of intentional breaks to improve productivity calculations.
128pub mod breaks;
129
130/// Local inbox of assigned open Jira issues.
131///
132/// Persists issues discovered by the background poller for toast notifications
133/// and CLI selection / import into tasks.
134pub mod jira_inbox;
135
136/// Catalog of Jira status id → name pairs synced from issues.
137pub mod jira_statuses;
138
139/// Break and pause tracking operations.
140///
141/// Manages records of user inactivity periods, break times, and interruptions
142/// during work sessions for productivity analysis.
143pub mod pauses;
144
145/// Task categorization and organization system.
146///
147/// Provides tag-based organization for tasks, including many-to-many
148/// relationships and color-coded categorization.
149pub mod tags;
150
151/// Core task management operations.
152///
153/// Handles CRUD operations for user tasks, including creation, updates,
154/// completion tracking, and various filtering and search capabilities.
155pub mod tasks;
156
157/// Reusable task template system.
158///
159/// Manages pre-defined task templates for common activities, enabling
160/// quick task creation from standardized patterns.
161pub mod templates;
162
163/// Daily work session tracking.
164///
165/// Records work session start/end times, manages workday lifecycle, and
166/// provides the foundation for time tracking and productivity reporting.
167pub mod workdays;