Problem
The skill-server currently uses CREATE TABLE IF NOT EXISTS / CREATE VIRTUAL TABLE IF NOT EXISTS for schema setup in DatabaseInitializer.cs. This works for initial creation but cannot handle schema changes to existing tables (e.g., altering FTS5 tokenizer settings, adding columns, changing constraints).
As the server evolves, we need a way to apply incremental schema changes safely.
Proposal
Add a simple numbered-migration system, following the pattern used in Memorizer's SchemaMigrator:
1. Schema version table
CREATE TABLE IF NOT EXISTS schema_version (
version INT PRIMARY KEY,
name TEXT NOT NULL,
applied_at TEXT NOT NULL
);
2. Migration files
Numbered SQL files in a migrations/ directory (embedded or on disk):
migrations/
001_initial_schema.sql
002_fts5_porter_stemmer.sql
...
3. Migrator behavior (on startup)
- Create
schema_version table if it doesn't exist
- Read which migrations have already been applied
- Apply any new migrations in order
- Record each applied migration with timestamp
4. Retrofit existing schema
Move the current CREATE TABLE IF NOT EXISTS block from DatabaseInitializer.cs into 001_initial_schema.sql. Existing databases with no schema_version table get migration 001 applied (idempotent due to IF NOT EXISTS), then future migrations run normally.
Why
This is a prerequisite for #43 (FTS5 Porter stemmer) and any future schema changes. Without it, changes to existing tables require manual intervention or risky drop/recreate logic.
Reference
- Memorizer's implementation:
SchemaMigrator.cs
- SQLite-compatible (uses
TEXT for timestamps instead of TIMESTAMPTZ)
Problem
The skill-server currently uses
CREATE TABLE IF NOT EXISTS/CREATE VIRTUAL TABLE IF NOT EXISTSfor schema setup inDatabaseInitializer.cs. This works for initial creation but cannot handle schema changes to existing tables (e.g., altering FTS5 tokenizer settings, adding columns, changing constraints).As the server evolves, we need a way to apply incremental schema changes safely.
Proposal
Add a simple numbered-migration system, following the pattern used in Memorizer's SchemaMigrator:
1. Schema version table
2. Migration files
Numbered SQL files in a
migrations/directory (embedded or on disk):3. Migrator behavior (on startup)
schema_versiontable if it doesn't exist4. Retrofit existing schema
Move the current
CREATE TABLE IF NOT EXISTSblock fromDatabaseInitializer.csinto001_initial_schema.sql. Existing databases with noschema_versiontable get migration 001 applied (idempotent due toIF NOT EXISTS), then future migrations run normally.Why
This is a prerequisite for #43 (FTS5 Porter stemmer) and any future schema changes. Without it, changes to existing tables require manual intervention or risky drop/recreate logic.
Reference
SchemaMigrator.csTEXTfor timestamps instead ofTIMESTAMPTZ)