Skip to content

πŸ”¬ [P2] Add schema versioning to SQLite migrationsΒ #138

Closed

Description

@ajianaz

Problem

Schema migrations in store.rs are ad-hoc β€” checking column existence with SELECT * FROM memories LIMIT 0 and running ALTER TABLE. No version tracking, no ordered migration sequence, no rollback.

This worked for 5 versions but will break at scale:

  • Can't track which migrations have run
  • Can't roll back
  • Adding new columns requires careful ordering
  • Race conditions possible (multiple processes)

Proposed Solution

Add a schema_version table:

CREATE TABLE IF NOT EXISTS schema_version (
  version INTEGER NOT NULL,
  applied_at TEXT NOT NULL,
  description TEXT
);

Wrap all migrations in versioned functions:

const SCHEMA_VERSIONS: &[Migration] = &[
  (1, "initial schema"),
  (2, "add namespace column"),
  (3, "add access_count and last_accessed"),
  (4, "add memory_type, valid_from, valid_until, deprecated"),
  (5, "add memory_tags junction table"),  // after #120
];

Acceptance Criteria

  • schema_version table created on fresh install
  • Existing databases auto-detect current version and apply pending migrations
  • Migration order enforced (sequential)
  • Migration atomic (wrapped in transaction)
  • No data loss on migration
  • Tests: fresh install, upgrade from each version

Effort: ~1-2 days (depends on #120 tag storage refactor)

Activity

  1. added
    enhancement
    and removed on Jun 9, 2026
  2. ajianaz commented on Jun 10, 2026

    @ajianaz
    CollaboratorAuthor

    Already implemented in PR #263 (schema migration v1β†’v2 with integer version counter).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpriority:mediumscope:core

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions