69 lines
No EOL
1.9 KiB
Markdown
69 lines
No EOL
1.9 KiB
Markdown
# SQLite Storage Adapter Schema Documentation
|
|
|
|
## Tables Overview
|
|
|
|
### 1. `storage` (Primary Data Storage)
|
|
- `key_hash` (TEXT, PRIMARY KEY): SHA-256 hash of the storage key
|
|
- `encrypted_value` (BLOB): AES-256 encrypted data value
|
|
- `created_at` (TIMESTAMP): When record was first created
|
|
- `updated_at` (TIMESTAMP): When record was last modified
|
|
- `created_by` (TEXT): User ID who created the record
|
|
|
|
### 2. `access_log` (Audit Trail)
|
|
- `id` (INTEGER, PRIMARY KEY): Auto-incrementing log ID
|
|
- `key_hash` (TEXT): Reference to storage.key_hash
|
|
- `operation` (TEXT): CRUD operation performed
|
|
- `user_id` (TEXT): Who performed the operation
|
|
- `timestamp` (TIMESTAMP): When operation occurred
|
|
|
|
### 3. `performance_metrics` (New in v1.2)
|
|
- `id` (INTEGER, PRIMARY KEY): Auto-incrementing metric ID
|
|
- `operation` (TEXT): CRUD operation type
|
|
- `execution_time_ms` (INTEGER): Operation duration in milliseconds
|
|
- `timestamp` (TIMESTAMP): When operation occurred
|
|
- `user_id` (TEXT): Who performed the operation
|
|
- `key_hash` (TEXT): Optional reference to storage.key_hash
|
|
|
|
## Relationships
|
|
|
|
```mermaid
|
|
erDiagram
|
|
storage ||--o{ access_log : "1:N"
|
|
storage ||--o{ performance_metrics : "1:N"
|
|
```
|
|
|
|
## Example Queries
|
|
|
|
### Get Slow Operations (>500ms)
|
|
```sql
|
|
SELECT operation, execution_time_ms, user_id
|
|
FROM performance_metrics
|
|
WHERE execution_time_ms > 500
|
|
ORDER BY execution_time_ms DESC;
|
|
```
|
|
|
|
### Average Operation Times by Type
|
|
```sql
|
|
SELECT
|
|
operation,
|
|
AVG(execution_time_ms) as avg_time,
|
|
COUNT(*) as operation_count
|
|
FROM performance_metrics
|
|
GROUP BY operation;
|
|
```
|
|
|
|
### Performance Metrics with Storage Metadata
|
|
```sql
|
|
SELECT
|
|
pm.operation,
|
|
pm.execution_time_ms,
|
|
s.created_at,
|
|
s.updated_at
|
|
FROM performance_metrics pm
|
|
LEFT JOIN storage s ON pm.key_hash = s.key_hash;
|
|
```
|
|
|
|
## Version History
|
|
- v1.0: Initial schema (storage + access_log)
|
|
- v1.1: Added RBAC constraints
|
|
- v1.2: Added performance_metrics table |