build ocr

This commit is contained in:
2026-03-28 01:59:13 -05:00
parent e1145b9448
commit 0e03cec842
14 changed files with 379 additions and 22 deletions

View File

@@ -34,6 +34,7 @@ db.exec(`
height INTEGER NOT NULL,
parent_id TEXT REFERENCES memes(id) ON DELETE CASCADE,
collection_id INTEGER REFERENCES collections(id) ON DELETE SET NULL,
ocr_text TEXT,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
);
@@ -54,15 +55,22 @@ db.exec(`
CREATE INDEX IF NOT EXISTS idx_meme_tags_tag_id ON meme_tags(tag_id);
`);
// Migration: add collection_id column if upgrading from earlier schema
// Must run BEFORE creating the index on that column
// Migrations — run after CREATE TABLE IF NOT EXISTS so they only apply to existing DBs
const memesCols = db.prepare('PRAGMA table_info(memes)').all() as { name: string }[];
if (!memesCols.find((c) => c.name === 'collection_id')) {
db.exec('ALTER TABLE memes ADD COLUMN collection_id INTEGER REFERENCES collections(id) ON DELETE SET NULL');
}
// Create index after the column is guaranteed to exist (handles both fresh and migrated DBs)
db.exec('CREATE INDEX IF NOT EXISTS idx_memes_collection_id ON memes(collection_id)');
if (!memesCols.find((c) => c.name === 'ocr_text')) {
db.exec('ALTER TABLE memes ADD COLUMN ocr_text TEXT');
}
// Indexes that depend on migrated columns — created after columns are guaranteed to exist
db.exec(`
CREATE INDEX IF NOT EXISTS idx_memes_collection_id ON memes(collection_id);
CREATE INDEX IF NOT EXISTS idx_memes_ocr ON memes(ocr_text) WHERE ocr_text IS NOT NULL;
`);
// Seed the default UNSORTED collection
const defaultCollection = db