Skip to content

SQLite engine and schema definition - #59

Merged
ZFordDev merged 1 commit into
42-logic-layer-overhaul-json-database-migration-uiagnostic-storage-architecturefrom
53-database-schema-dbpy-sqlite-engine
Jun 7, 2026
Merged

SQLite engine and schema definition#59
ZFordDev merged 1 commit into
42-logic-layer-overhaul-json-database-migration-uiagnostic-storage-architecturefrom
53-database-schema-dbpy-sqlite-engine

Conversation

@ZFordDev

@ZFordDev ZFordDev commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

This PR implements the SQLite engine, connection manager, and schema creation for the new database‑backed logic layer defined in Issue #42.

It introduces a lazy‑loaded SQLite connection, enforces foreign key support, and creates all required tables on first use.
This module is fully UI‑agnostic and forms the foundation for the upcoming repository API, migration system, and scheduler integration.

No wiring or integration is included in this PR.


Type of Change

  • New feature
  • Workflow improvement
  • UI/UX improvement
  • Documentation update
  • Refactor / cleanup

Details

What this PR adds

  • New module: storage/db.py
  • Lazy‑loaded SQLite connection via get_connection
  • Automatic schema creation on first connect
  • Foreign key enforcement (PRAGMA foreign_keys = ON)
  • sqlite3.Row row factory for dict‑like access
  • ISO 8601 timestamp fields for all date/time columns
  • Idempotent table creation for:
    • entries
    • comments
    • tags
    • entry_tags (many‑to‑many)
    • recurrence_rules
    • metadata (migration/versioning)
  • init_db() helper for future startup integration

Design decisions

  • Single long‑lived connection (best practice for desktop apps)
  • No UI imports or dependencies
  • No repository logic included yet (handled in #42C)
  • No JSON migration logic included yet (handled in #42D)
  • Schema is normalized and future‑proof for recurrence, tagging, and RAW mode

Side effects

  • Creates the SQLite database file on first use
  • Does not modify scheduler or UI behavior
  • Does not read or write JSON
  • No changes to existing logic

Testing

A small temporary test harness (not included in this PR) was used to validate:

  • Runs successfully
  • Tested on Linux (WSL)
  • Tested on Windows
  • DB file is created
  • Schema is created correctly
  • Foreign keys are enforced
  • Row factory works as expected
  • No regressions found

Related Issues

Fixes #42B
Part of #42 — Logic Layer Overhaul (JSON → SQLite)


Additional Notes (optional)


@ZFordDev
ZFordDev merged commit 06426f5 into 42-logic-layer-overhaul-json-database-migration-uiagnostic-storage-architecture Jun 7, 2026
1 check failed
@ZFordDev
ZFordDev deleted the 53-database-schema-dbpy-sqlite-engine branch June 7, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant