Skip to main content

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,no_run
17//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
18//! use kasl::db::{db::Db, tasks::Tasks, workdays::Workdays};
19//! use kasl::libs::task::Task;
20//!
21//! let db = Db::new()?;
22//! let mut tasks = Tasks::new()?;
23//! let task = Task::new("Review code", "Check PR #123", Some(75));
24//! tasks.insert(&task)?;
25//! # Ok(())
26//! # }
27//! ```
28//!
29//! ```rust,no_run
30//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
31//! use kasl::db::{tags::{Tags, Tag}, templates::{Templates, TaskTemplate}};
32//!
33//! // Create and manage tags
34//! let mut tags = Tags::new()?;
35//! let tag_id = tags.create(&Tag::new("urgent".to_string(), Some("red".to_string())))?;
36//!
37//! // Work with task templates
38//! let mut templates = Templates::new()?;
39//! let template = TaskTemplate::new(
40//!     "daily-standup".to_string(),
41//!     "Attend daily standup meeting".to_string(),
42//!     "Team sync and planning".to_string(),
43//!     100
44//! );
45//! templates.create(&template)?;
46//! # Ok(())
47//! # }
48//! ```
49//!
50//! ## Performance Considerations
51//!
52//! ### Indexing Strategy
53//! - **Temporal Queries**: Optimized indexes on timestamp columns
54//! - **Relationship Lookups**: Efficient foreign key index coverage
55//! - **Search Operations**: Selective indexes for common query patterns
56//!
57//! ### Connection Management
58//! - **Connection Reuse**: Long-lived connections for better performance
59//! - **Transaction Batching**: Grouped operations for improved throughput
60//! - **Statement Preparation**: Cached prepared statements for repeated queries
61//!
62//! ### Data Volume Handling
63//! - **Pagination Support**: Efficient handling of large result sets
64//! - **Selective Loading**: Fetch only required fields for large tables
65//! - **Archive Strategy**: Data retention policies for long-term usage
66//!
67//! ## Migration Best Practices
68//!
69//! ### Schema Evolution
70//! ```text
71//! // Adding a new column (backward compatible)
72//! tx.execute("ALTER TABLE tasks ADD COLUMN priority INTEGER DEFAULT 1", [])?;
73//!
74//! // Creating new indexes for performance
75//! tx.execute("CREATE INDEX idx_tasks_priority ON tasks(priority)", [])?;
76//!
77//! // Adding new tables with proper foreign keys
78//! tx.execute("CREATE TABLE task_dependencies (
79//!     id INTEGER PRIMARY KEY,
80//!     task_id INTEGER NOT NULL,
81//!     depends_on INTEGER NOT NULL,
82//!     FOREIGN KEY (task_id) REFERENCES tasks(id) ON DELETE CASCADE,
83//!     FOREIGN KEY (depends_on) REFERENCES tasks(id) ON DELETE CASCADE
84//! )", [])?;
85//! ```
86//!
87//! ### Version Control Integration
88//! - **Sequential Versioning**: Each migration increments the version number
89//! - **Descriptive Names**: Clear migration names describing the change
90//! - **Testing Requirements**: All migrations must be tested before deployment
91//! - **Rollback Planning**: Consider rollback implications for schema changes
92//!
93//! ## Platform-Specific Considerations
94//!
95//! ### File System Integration
96//! - **Windows**: Handles path length limitations and permission requirements
97//! - **macOS**: Integrates with application sandbox restrictions
98//! - **Linux**: Follows XDG base directory specifications
99//!
100//! ### Backup and Recovery
101//! - **Export Functionality**: Complete data export in multiple formats
102//! - **Import Validation**: Schema validation during data import
103//! - **Corruption Recovery**: Database integrity checks and repair options
104//!
105//! ## Development and Debugging
106//!
107//! ### Debug Features
108//! - **Migration Inspection**: View current schema version and history
109//! - **Query Logging**: Optional SQL query logging for performance analysis
110//! - **Connection Monitoring**: Track active connections and lock contention
111//!
112//! ### Testing Support
113//! - **In-Memory Databases**: Fast test execution with temporary databases
114//! - **Fixture Management**: Consistent test data setup and teardown
115//! - **Migration Testing**: Automated testing of schema changes
116
117/// Core database connection and initialization module.
118///
119/// Provides the fundamental `Db` struct that manages SQLite connections,
120/// applies migrations, and ensures proper database configuration.
121#[allow(clippy::module_inception)] // kasl::db::db::Db is the established public path
122pub mod db;
123
124/// Database schema migration system.
125///
126/// Handles versioned schema changes, tracks migration history, and provides
127/// development-time migration management commands.
128pub mod migrations;
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;