From 08b51adaf14f06b191c8bc7efe54e460c4d0cea0 Mon Sep 17 00:00:00 2001 From: viettranx Date: Sun, 12 Apr 2026 17:32:34 +0700 Subject: [PATCH] fix(sqlitestore): add tenant_id filter to GetSkillHashBySlug and GetNextVersion SQLite implementations were missing tenant_id WHERE clauses that the PostgreSQL equivalents have. While Lite edition is single-tenant in practice, this maintains dual-DB parity and prevents potential issues if the codebase evolves. Follows the same pattern as other methods in the file (GetSkillFilePath, CreateSkillManaged, etc.) that use store.TenantIDFromContext with MasterTenantID fallback. --- internal/store/sqlitestore/skills_crud.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/internal/store/sqlitestore/skills_crud.go b/internal/store/sqlitestore/skills_crud.go index 9d550465..b8a60872 100644 --- a/internal/store/sqlitestore/skills_crud.go +++ b/internal/store/sqlitestore/skills_crud.go @@ -188,23 +188,31 @@ func (s *SQLiteSkillStore) GetSkillFilePath(ctx context.Context, id uuid.UUID) ( } // GetSkillHashBySlug returns the file_hash and version of the latest non-deleted skill -// version for the given slug. +// version for the given slug, scoped to the current tenant. // Returns ok=false when no matching row exists. func (s *SQLiteSkillStore) GetSkillHashBySlug(ctx context.Context, slug string) (string, int, bool) { + tid := store.TenantIDFromContext(ctx) + if tid == uuid.Nil { + tid = store.MasterTenantID + } var hash string var version int err := s.db.QueryRowContext(ctx, `SELECT COALESCE(file_hash, ''), version FROM skills - WHERE slug = ? AND status != 'deleted' + WHERE slug = ? AND tenant_id = ? AND status != 'deleted' ORDER BY version DESC LIMIT 1`, - slug, + slug, tid, ).Scan(&hash, &version) return hash, version, err == nil } func (s *SQLiteSkillStore) GetNextVersion(ctx context.Context, slug string) int { + tid := store.TenantIDFromContext(ctx) + if tid == uuid.Nil { + tid = store.MasterTenantID + } var maxVersion int - s.db.QueryRowContext(ctx, "SELECT COALESCE(MAX(version), 0) FROM skills WHERE slug = ?", slug).Scan(&maxVersion) + s.db.QueryRowContext(ctx, "SELECT COALESCE(MAX(version), 0) FROM skills WHERE slug = ? AND tenant_id = ?", slug, tid).Scan(&maxVersion) return maxVersion + 1 }