build ocr
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user