Skip to content

Support sqllite to store model information#32

Merged
InftyAI-Agent merged 3 commits intoInftyAI:mainfrom
kerthcet:feat/sqllite-support
Apr 25, 2026
Merged

Support sqllite to store model information#32
InftyAI-Agent merged 3 commits intoInftyAI:mainfrom
kerthcet:feat/sqllite-support

Conversation

@kerthcet
Copy link
Copy Markdown
Member

What this PR does / why we need it

Which issue(s) this PR fixes

Fixes #

Special notes for your reviewer

Does this PR introduce a user-facing change?


Signed-off-by: kerthcet <kerthcet@gmail.com>
Copilot AI review requested due to automatic review settings April 25, 2026 08:57
@InftyAI-Agent InftyAI-Agent added needs-triage Indicates an issue or PR lacks a label and requires one. needs-priority Indicates a PR lacks a label and requires one. do-not-merge/needs-kind Indicates a PR lacks a label and requires one. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 25, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a SQLite-backed storage layer for model registry data, replacing the prior JSON-file registry approach.

Changes:

  • Introduces a ModelStorage trait and a SqliteStorage implementation with migrations and CRUD operations.
  • Refactors ModelRegistry to use SQLite storage and updates CLI/downloader code to the new ModelInfo/metadata structure.
  • Adds rusqlite/rusqlite_migration dependencies and unit tests for the new storage.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/storage/storage_trait.rs Defines the storage backend trait used by the registry.
src/storage/sqlite.rs Implements SQLite persistence, schema migrations, and tests.
src/storage/mod.rs Exposes storage modules and re-exports the public API.
src/registry/model_registry.rs Switches registry persistence from JSON to SQLite and updates model structures.
src/downloader/huggingface.rs Populates the new ModelInfo/ModelMetadata fields when registering downloads.
src/cli/commands.rs Updates ls/inspect output to read from the new metadata layout and updates tests.
src/main.rs Registers the new storage module in the binary crate.
Cargo.toml / Cargo.lock Adds SQLite-related dependencies and lockfile updates.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/storage/sqlite.rs Outdated
Comment on lines +97 to +105
// Check if model exists to preserve created_at
let existing_created_at: Option<String> = conn
.query_row(
"SELECT created_at FROM models WHERE name = ?1",
params![&model.name],
|row| row.get(0),
)
.ok();

Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

query_row(...).ok() will convert any SQL error into None, not just “no rows”. That can silently mask unexpected failures (schema issues, IO/corruption, etc.) and change behavior. Prefer matching on the error and only treating QueryReturnedNoRows as None, while propagating other errors.

Copilot uses AI. Check for mistakes.
Comment thread src/storage/sqlite.rs
Comment thread src/cli/commands.rs
Comment on lines 47 to 56
pub fn new(home_dir: Option<PathBuf>) -> Self {
Self {
home_dir: home_dir.unwrap_or_else(file::root_home),
}
}
let home_dir = home_dir.unwrap_or_else(file::root_home);
fs::create_dir_all(&home_dir).ok();

fn registry_file(&self) -> PathBuf {
self.home_dir.join("models.json")
}

pub fn load_models(&self) -> Result<Vec<ModelInfo>, std::io::Error> {
let registry_file = self.registry_file();
let db_path = home_dir.join("models.db");
let storage = SqliteStorage::new(db_path).expect("Failed to initialize storage");

if !registry_file.exists() {
return Ok(Vec::new());
Self {
storage: Box::new(storage),
}
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ModelRegistry::new ignores errors from create_dir_all and panics on SQLite init (expect). This makes failures (e.g., permission issues, unwritable home dir) crash the CLI instead of being reported/handled. Consider changing new to return Result<Self, io::Error> (or adding a try_new) and propagate both directory-creation and SqliteStorage::new errors.

Copilot uses AI. Check for mistakes.
Comment thread src/registry/model_registry.rs
Comment thread src/storage/sqlite.rs Outdated
Signed-off-by: kerthcet <kerthcet@gmail.com>
@kerthcet
Copy link
Copy Markdown
Member Author

/lgtm

@InftyAI-Agent InftyAI-Agent added the lgtm Looks good to me, indicates that a PR is ready to be merged. label Apr 25, 2026
Signed-off-by: kerthcet <kerthcet@gmail.com>
Copilot AI review requested due to automatic review settings April 25, 2026 09:10
@InftyAI-Agent InftyAI-Agent removed the lgtm Looks good to me, indicates that a PR is ready to be merged. label Apr 25, 2026
@kerthcet
Copy link
Copy Markdown
Member Author

/lgtm

@kerthcet
Copy link
Copy Markdown
Member Author

/kind feature

@InftyAI-Agent InftyAI-Agent added lgtm Looks good to me, indicates that a PR is ready to be merged. feature Categorizes issue or PR as related to a new feature. and removed do-not-merge/needs-kind Indicates a PR lacks a label and requires one. labels Apr 25, 2026
@InftyAI-Agent InftyAI-Agent merged commit 1e6282b into InftyAI:main Apr 25, 2026
29 checks passed
@kerthcet kerthcet deleted the feat/sqllite-support branch April 25, 2026 09:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/storage/sqlite.rs
Comment on lines +72 to +73
let metadata: ModelMetadata = serde_json::from_str(&metadata_json)
.map_err(|e| rusqlite::Error::ToSqlConversionFailure(Box::new(e)))?;
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON deserialization errors while reading metadata are being converted into rusqlite::Error::ToSqlConversionFailure, which is a misleading error variant for a FROM-SQL conversion. Prefer rusqlite::Error::FromSqlConversionFailure (or map the serde error directly into an io::Error/custom error) so failures are classified correctly.

Suggested change
let metadata: ModelMetadata = serde_json::from_str(&metadata_json)
.map_err(|e| rusqlite::Error::ToSqlConversionFailure(Box::new(e)))?;
let metadata: ModelMetadata = serde_json::from_str(&metadata_json).map_err(
|e| {
rusqlite::Error::FromSqlConversionFailure(
7,
rusqlite::types::Type::Text,
Box::new(e),
)
},
)?;

Copilot uses AI. Check for mistakes.
Comment thread src/storage/sqlite.rs
Comment on lines +152 to +153
let metadata: ModelMetadata = serde_json::from_str(&metadata_json)
.map_err(|e| rusqlite::Error::ToSqlConversionFailure(Box::new(e)))?;
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as load_models: JSON deserialization errors for the metadata column are mapped to rusqlite::Error::ToSqlConversionFailure, which is misleading for a read/FromSql path. Use FromSqlConversionFailure (or map to an io::Error) so error reporting is accurate.

Suggested change
let metadata: ModelMetadata = serde_json::from_str(&metadata_json)
.map_err(|e| rusqlite::Error::ToSqlConversionFailure(Box::new(e)))?;
let metadata: ModelMetadata = serde_json::from_str(&metadata_json).map_err(
|e| {
rusqlite::Error::FromSqlConversionFailure(
7,
rusqlite::types::Type::Text,
Box::new(e),
)
},
)?;

Copilot uses AI. Check for mistakes.
Comment thread src/storage/sqlite.rs
updated_at: "2025-01-01T00:00:00Z".to_string(),
metadata: ModelMetadata {
artifact: ArtifactInfo {
revision: "abc123".to_string(),
Copy link

Copilot AI Apr 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the SQLite tests, create_test_model takes a uuid parameter but hard-codes metadata.artifact.revision to "abc123". This makes the fixture internally inconsistent and can mask bugs where UUID/revision are expected to align; consider using the passed-in value for the artifact revision too (or rename the parameter to clarify intent).

Suggested change
revision: "abc123".to_string(),
revision: uuid.to_string(),

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. feature Categorizes issue or PR as related to a new feature. lgtm Looks good to me, indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a label and requires one. needs-triage Indicates an issue or PR lacks a label and requires one.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants