MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / init_db

Function init_db

skills/storage-helper/scripts/db_ops.py:172–251  ·  view source on GitHub ↗

Initialize database, create all tables

()

Source from the content-addressed store, hash-verified

170 for list_key in ("categories", "keywords", "topics"):
171 paper[list_key] = _deserialize_json_list(paper.get(list_key))
172
173 return paper
174
175
176def _derive_push_metadata_from_papers(papers: List[Dict[str, Any]]) -> Dict[str, Any]:
177 """Lift push-level metadata duplicated on pushed paper rows."""
178 if not papers:
179 return {}
180 metadata = papers[0].get("metadata") or {}
181 push_metadata: Dict[str, Any] = {}
182 for key in (
183 "fallback_used",
184 "fallback_days",
185 "fallback_total_fetched",
186 "fallback_filtered_already_handled",
187 "fallback_kept_candidates",
188 "fallback_relaxed",
189 "fallback_source_scope",
190 "paper_count",
191 "total_fetched",
192 "daily_limit",
193 "push_target_count",
194 "push_max_count",
195 "limit_per_source",
196 "fetch_days",
197 "relevance_threshold",
198 "arxiv_categories",
199 "conferences",
200 "journals",
201 "enable_semantic_scholar",
202 "enable_custom_rss",
203 "custom_rss_urls",
204 ):
205 if key in metadata:
206 push_metadata[key] = metadata[key]
207 if push_metadata and "paper_count" not in push_metadata:
208 push_metadata["paper_count"] = len(papers)
209 return push_metadata
210
211
212def _create_chat_tables(cursor: sqlite3.Cursor) -> None:
213 """Create persistent GUI chat history tables."""
214 cursor.execute("""
215 CREATE TABLE IF NOT EXISTS chat_sessions (
216 id INTEGER PRIMARY KEY AUTOINCREMENT,
217 session_id TEXT UNIQUE NOT NULL,
218 user_id TEXT NOT NULL,
219 title TEXT NOT NULL,
220 created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
221 updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
222 message_count INTEGER DEFAULT 0
223 )
224 """)
225 cursor.execute("""
226 CREATE TABLE IF NOT EXISTS chat_messages (
227 id INTEGER PRIMARY KEY AUTOINCREMENT,
228 session_id TEXT NOT NULL,
229 user_id TEXT NOT NULL,

Callers 3

mainFunction · 0.90
mainFunction · 0.90
db_ops.pyFile · 0.70

Calls 5

_create_chat_tablesFunction · 0.85
cursorMethod · 0.80
get_connectionFunction · 0.70
executeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected