Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 0cfecec

Browse files
db schema update follow up
1 parent 8c8a25a commit 0cfecec

File tree

2 files changed

+68
-25
lines changed

2 files changed

+68
-25
lines changed

engine/database/models.cc

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ Models::Models() : db_(cortex::db::Database::GetInstance().db()) {
2222
"model_alias TEXT);");
2323
}
2424

25+
Models::Models(SQLite::Database& db) : db_(db) {
26+
db_.exec(
27+
"CREATE TABLE IF NOT EXISTS models ("
28+
"model_id TEXT PRIMARY KEY,"
29+
"model_format TEXT,"
30+
"model_source TEXT,"
31+
"status TEXT,"
32+
"engine TEXT,"
33+
"author_repo_id TEXT,"
34+
"branch_name TEXT,"
35+
"path_to_model_yaml TEXT,"
36+
"model_alias TEXT);");
37+
}
2538
Models::~Models() {}
2639

2740
cpp::result<std::vector<ModelEntry>, std::string> Models::LoadModelList()
@@ -51,16 +64,21 @@ cpp::result<std::vector<ModelEntry>, std::string> Models::LoadModelListNoLock()
5164
try {
5265
std::vector<ModelEntry> entries;
5366
SQLite::Statement query(db_,
54-
"SELECT model_id, author_repo_id, branch_name, "
67+
"SELECT model_id, model_format, model_source, "
68+
"status, engine, author_repo_id, branch_name, "
5569
"path_to_model_yaml, model_alias FROM models");
5670

5771
while (query.executeStep()) {
5872
ModelEntry entry;
5973
entry.model = query.getColumn(0).getString();
60-
entry.author_repo_id = query.getColumn(1).getString();
61-
entry.branch_name = query.getColumn(2).getString();
62-
entry.path_to_model_yaml = query.getColumn(3).getString();
63-
entry.model_alias = query.getColumn(4).getString();
74+
entry.model_format = query.getColumn(1).getString();
75+
entry.model_source = query.getColumn(2).getString();
76+
entry.status = query.getColumn(3).getString();
77+
entry.engine = query.getColumn(4).getString();
78+
entry.author_repo_id = query.getColumn(5).getString();
79+
entry.branch_name = query.getColumn(6).getString();
80+
entry.path_to_model_yaml = query.getColumn(7).getString();
81+
entry.model_alias = query.getColumn(8).getString();
6482
entries.push_back(entry);
6583
}
6684
return entries;
@@ -134,7 +152,8 @@ cpp::result<ModelEntry, std::string> Models::GetModelInfo(
134152
const std::string& identifier) const {
135153
try {
136154
SQLite::Statement query(db_,
137-
"SELECT model_id, author_repo_id, branch_name, "
155+
"SELECT model_id, model_format, model_source, "
156+
"status, engine, author_repo_id, branch_name, "
138157
"path_to_model_yaml, model_alias FROM models "
139158
"WHERE model_id = ? OR model_alias = ?");
140159

@@ -143,10 +162,14 @@ cpp::result<ModelEntry, std::string> Models::GetModelInfo(
143162
if (query.executeStep()) {
144163
ModelEntry entry;
145164
entry.model = query.getColumn(0).getString();
146-
entry.author_repo_id = query.getColumn(1).getString();
147-
entry.branch_name = query.getColumn(2).getString();
148-
entry.path_to_model_yaml = query.getColumn(3).getString();
149-
entry.model_alias = query.getColumn(4).getString();
165+
entry.model_format = query.getColumn(1).getString();
166+
entry.model_source = query.getColumn(2).getString();
167+
entry.status = query.getColumn(3).getString();
168+
entry.engine = query.getColumn(4).getString();
169+
entry.author_repo_id = query.getColumn(5).getString();
170+
entry.branch_name = query.getColumn(6).getString();
171+
entry.path_to_model_yaml = query.getColumn(7).getString();
172+
entry.model_alias = query.getColumn(8).getString();
150173
return entry;
151174
} else {
152175
return cpp::fail("Model not found: " + identifier);
@@ -158,6 +181,10 @@ cpp::result<ModelEntry, std::string> Models::GetModelInfo(
158181

159182
void Models::PrintModelInfo(const ModelEntry& entry) const {
160183
LOG_INFO << "Model ID: " << entry.model;
184+
LOG_INFO << "Model Format: " << entry.model_format;
185+
LOG_INFO << "Model Source: " << entry.model_source;
186+
LOG_INFO << "Status: " << entry.status;
187+
LOG_INFO << "Engine: " << entry.engine;
161188
LOG_INFO << "Author/Repo ID: " << entry.author_repo_id;
162189
LOG_INFO << "Branch Name: " << entry.branch_name;
163190
LOG_INFO << "Path to model.yaml: " << entry.path_to_model_yaml;
@@ -182,14 +209,18 @@ cpp::result<bool, std::string> Models::AddModelEntry(ModelEntry new_entry,
182209

183210
SQLite::Statement insert(
184211
db_,
185-
"INSERT INTO models (model_id, author_repo_id, "
186-
"branch_name, path_to_model_yaml, model_alias) VALUES (?, ?, "
187-
"?, ?, ?)");
212+
"INSERT INTO models (model_id, model_format, model_source, status, "
213+
"engine, author_repo_id, branch_name, path_to_model_yaml, model_alias) "
214+
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");
188215
insert.bind(1, new_entry.model);
189-
insert.bind(2, new_entry.author_repo_id);
190-
insert.bind(3, new_entry.branch_name);
191-
insert.bind(4, new_entry.path_to_model_yaml);
192-
insert.bind(5, new_entry.model_alias);
216+
insert.bind(2, new_entry.model_format);
217+
insert.bind(3, new_entry.model_source);
218+
insert.bind(4, new_entry.status);
219+
insert.bind(5, new_entry.engine);
220+
insert.bind(6, new_entry.author_repo_id);
221+
insert.bind(7, new_entry.branch_name);
222+
insert.bind(8, new_entry.path_to_model_yaml);
223+
insert.bind(9, new_entry.model_alias);
193224
insert.exec();
194225

195226
return true;
@@ -209,14 +240,19 @@ cpp::result<bool, std::string> Models::UpdateModelEntry(
209240
try {
210241
SQLite::Statement upd(db_,
211242
"UPDATE models "
212-
"SET author_repo_id = ?, branch_name = ?, "
243+
"SET model_format = ?, model_source = ?, status = ?, "
244+
"engine = ?, author_repo_id = ?, branch_name = ?, "
213245
"path_to_model_yaml = ? "
214246
"WHERE model_id = ? OR model_alias = ?");
215-
upd.bind(1, updated_entry.author_repo_id);
216-
upd.bind(2, updated_entry.branch_name);
217-
upd.bind(3, updated_entry.path_to_model_yaml);
218-
upd.bind(4, identifier);
219-
upd.bind(5, identifier);
247+
upd.bind(1, updated_entry.model_format);
248+
upd.bind(2, updated_entry.model_source);
249+
upd.bind(3, updated_entry.status);
250+
upd.bind(4, updated_entry.engine);
251+
upd.bind(5, updated_entry.author_repo_id);
252+
upd.bind(6, updated_entry.branch_name);
253+
upd.bind(7, updated_entry.path_to_model_yaml);
254+
upd.bind(8, identifier);
255+
upd.bind(9, identifier);
220256
return upd.exec() == 1;
221257
} catch (const std::exception& e) {
222258
return cpp::fail(e.what());
@@ -299,4 +335,5 @@ bool Models::HasModel(const std::string& identifier) const {
299335
return false;
300336
}
301337
}
302-
} // namespace cortex::db
338+
339+
} // namespace cortex::db

engine/database/models.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
#include "utils/result.hpp"
88

99
namespace cortex::db {
10+
1011
struct ModelEntry {
1112
std::string model;
13+
std::string model_format; // Ensure this is present
14+
std::string model_source;
15+
std::string status;
16+
std::string engine;
1217
std::string author_repo_id;
1318
std::string branch_name;
1419
std::string path_to_model_yaml;
@@ -50,4 +55,5 @@ class Models {
5055
const std::string& identifier) const;
5156
bool HasModel(const std::string& identifier) const;
5257
};
53-
} // namespace cortex::db
58+
59+
} // namespace cortex::db

0 commit comments

Comments
 (0)