|
3 | 3 | :up |
4 | 4 | ["PRAGMA foreign_keys = ON" |
5 | 5 |
|
| 6 | + ;; Skills table |
6 | 7 | "CREATE TABLE IF NOT EXISTS skills ( |
7 | 8 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
8 | 9 | path TEXT NOT NULL UNIQUE, |
|
22 | 23 | "CREATE INDEX IF NOT EXISTS idx_skills_name ON skills(name)" |
23 | 24 | "CREATE INDEX IF NOT EXISTS idx_skills_hash ON skills(file_hash)" |
24 | 25 |
|
| 26 | + ;; Prompts table (includes fragment_refs column from migration 006) |
25 | 27 | "CREATE TABLE IF NOT EXISTS prompts ( |
26 | 28 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
27 | 29 | path TEXT NOT NULL UNIQUE, |
|
33 | 35 | file_hash TEXT NOT NULL, |
34 | 36 | size_bytes INTEGER NOT NULL, |
35 | 37 | token_count INTEGER, |
| 38 | + fragment_refs TEXT, |
36 | 39 | created_at TEXT NOT NULL DEFAULT (datetime('now')), |
37 | 40 | updated_at TEXT NOT NULL DEFAULT (datetime('now')) |
38 | 41 | )" |
39 | 42 |
|
40 | | - "CREATE INDEX IF NOT EXISTS idx_prompts_name ON prompts(name)" |
41 | 43 | "CREATE INDEX IF NOT EXISTS idx_prompts_hash ON prompts(file_hash)" |
| 44 | + ;; Unique index on name (from migration 008) |
| 45 | + "CREATE UNIQUE INDEX IF NOT EXISTS idx_prompts_name ON prompts(name)" |
42 | 46 |
|
43 | | - "CREATE TABLE IF NOT EXISTS prompt_skills ( |
44 | | - prompt_id INTEGER NOT NULL, |
| 47 | + ;; Prompt fragments table (from migration 006) |
| 48 | + "CREATE TABLE IF NOT EXISTS prompt_fragments ( |
| 49 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 50 | + name TEXT NOT NULL UNIQUE, |
| 51 | + title TEXT, |
| 52 | + description TEXT, |
| 53 | + created_at TEXT NOT NULL DEFAULT (datetime('now')), |
| 54 | + updated_at TEXT NOT NULL DEFAULT (datetime('now')) |
| 55 | + )" |
| 56 | + |
| 57 | + "CREATE INDEX IF NOT EXISTS idx_prompt_fragments_name ON prompt_fragments(name)" |
| 58 | + |
| 59 | + ;; Prompt fragment skills join table (from migration 006) |
| 60 | + "CREATE TABLE IF NOT EXISTS prompt_fragment_skills ( |
| 61 | + fragment_id INTEGER NOT NULL, |
45 | 62 | skill_id INTEGER NOT NULL, |
46 | 63 | position INTEGER NOT NULL, |
47 | | - PRIMARY KEY (prompt_id, skill_id), |
48 | | - FOREIGN KEY (prompt_id) REFERENCES prompts(id) ON DELETE CASCADE, |
| 64 | + created_at TEXT NOT NULL DEFAULT (datetime('now')), |
| 65 | + PRIMARY KEY (fragment_id, skill_id), |
| 66 | + FOREIGN KEY (fragment_id) REFERENCES prompt_fragments(id) ON DELETE CASCADE, |
49 | 67 | FOREIGN KEY (skill_id) REFERENCES skills(id) ON DELETE CASCADE |
50 | 68 | )" |
51 | 69 |
|
52 | | - "CREATE INDEX IF NOT EXISTS idx_prompt_skills_prompt ON prompt_skills(prompt_id)" |
53 | | - "CREATE INDEX IF NOT EXISTS idx_prompt_skills_skill ON prompt_skills(skill_id)" |
| 70 | + "CREATE INDEX IF NOT EXISTS idx_prompt_fragment_skills_fragment ON prompt_fragment_skills(fragment_id)" |
| 71 | + "CREATE INDEX IF NOT EXISTS idx_prompt_fragment_skills_skill ON prompt_fragment_skills(skill_id)" |
54 | 72 |
|
| 73 | + ;; Prompt references table (from migration 006, with FIXED nullable target_prompt_id) |
| 74 | + "CREATE TABLE IF NOT EXISTS prompt_references ( |
| 75 | + id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 76 | + source_prompt_id INTEGER NOT NULL, |
| 77 | + target_prompt_id INTEGER, |
| 78 | + target_fragment_id INTEGER, |
| 79 | + reference_type TEXT NOT NULL CHECK(reference_type IN ('prompt', 'fragment')), |
| 80 | + position INTEGER NOT NULL, |
| 81 | + created_at TEXT NOT NULL DEFAULT (datetime('now')), |
| 82 | + FOREIGN KEY (source_prompt_id) REFERENCES prompts(id) ON DELETE CASCADE, |
| 83 | + FOREIGN KEY (target_prompt_id) REFERENCES prompts(id) ON DELETE CASCADE, |
| 84 | + FOREIGN KEY (target_fragment_id) REFERENCES prompt_fragments(id) ON DELETE CASCADE, |
| 85 | + CONSTRAINT chk_target_reference CHECK ( |
| 86 | + (target_prompt_id IS NOT NULL AND target_fragment_id IS NULL) OR |
| 87 | + (target_prompt_id IS NULL AND target_fragment_id IS NOT NULL) |
| 88 | + ) |
| 89 | + )" |
| 90 | + |
| 91 | + "CREATE INDEX IF NOT EXISTS idx_prompt_references_source ON prompt_references(source_prompt_id)" |
| 92 | + "CREATE INDEX IF NOT EXISTS idx_prompt_references_target_prompt ON prompt_references(target_prompt_id)" |
| 93 | + "CREATE INDEX IF NOT EXISTS idx_prompt_references_target_fragment ON prompt_references(target_fragment_id)" |
| 94 | + "CREATE INDEX IF NOT EXISTS idx_prompt_references_type ON prompt_references(reference_type)" |
| 95 | + |
| 96 | + ;; Skills FTS table |
55 | 97 | "CREATE VIRTUAL TABLE IF NOT EXISTS skills_fts USING fts5( |
56 | 98 | path, |
57 | 99 | category, |
|
63 | 105 | content_rowid='id' |
64 | 106 | )" |
65 | 107 |
|
| 108 | + ;; Skills FTS triggers |
66 | 109 | "CREATE TRIGGER IF NOT EXISTS skills_ai AFTER INSERT ON skills BEGIN |
67 | 110 | INSERT INTO skills_fts(rowid, path, category, name, title, description, content) |
68 | 111 | VALUES (new.id, new.path, new.category, new.name, new.title, new.description, new.content); |
|
80 | 123 | VALUES (new.id, new.path, new.category, new.name, new.title, new.description, new.content); |
81 | 124 | END" |
82 | 125 |
|
| 126 | + ;; Prompts FTS table |
83 | 127 | "CREATE VIRTUAL TABLE IF NOT EXISTS prompts_fts USING fts5( |
84 | 128 | path, |
85 | 129 | name, |
|
91 | 135 | content_rowid='id' |
92 | 136 | )" |
93 | 137 |
|
| 138 | + ;; Prompts FTS triggers |
94 | 139 | "CREATE TRIGGER IF NOT EXISTS prompts_ai AFTER INSERT ON prompts BEGIN |
95 | 140 | INSERT INTO prompts_fts(rowid, path, name, title, author, description, content) |
96 | 141 | VALUES (new.id, new.path, new.name, new.title, new.author, new.description, new.content); |
|
117 | 162 | "DROP TRIGGER IF EXISTS skills_ad" |
118 | 163 | "DROP TRIGGER IF EXISTS skills_ai" |
119 | 164 | "DROP TABLE IF EXISTS skills_fts" |
120 | | - "DROP INDEX IF EXISTS idx_prompt_skills_skill" |
121 | | - "DROP INDEX IF EXISTS idx_prompt_skills_prompt" |
122 | | - "DROP TABLE IF EXISTS prompt_skills" |
123 | | - "DROP INDEX IF EXISTS idx_prompts_hash" |
| 165 | + "DROP INDEX IF EXISTS idx_prompt_references_type" |
| 166 | + "DROP INDEX IF EXISTS idx_prompt_references_target_fragment" |
| 167 | + "DROP INDEX IF EXISTS idx_prompt_references_target_prompt" |
| 168 | + "DROP INDEX IF EXISTS idx_prompt_references_source" |
| 169 | + "DROP TABLE IF EXISTS prompt_references" |
| 170 | + "DROP INDEX IF EXISTS idx_prompt_fragment_skills_skill" |
| 171 | + "DROP INDEX IF EXISTS idx_prompt_fragment_skills_fragment" |
| 172 | + "DROP TABLE IF EXISTS prompt_fragment_skills" |
| 173 | + "DROP INDEX IF EXISTS idx_prompt_fragments_name" |
| 174 | + "DROP TABLE IF EXISTS prompt_fragments" |
124 | 175 | "DROP INDEX IF EXISTS idx_prompts_name" |
| 176 | + "DROP INDEX IF EXISTS idx_prompts_hash" |
125 | 177 | "DROP TABLE IF EXISTS prompts" |
126 | 178 | "DROP INDEX IF EXISTS idx_skills_hash" |
127 | 179 | "DROP INDEX IF EXISTS idx_skills_name" |
|
0 commit comments