mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-13 16:14:57 +00:00
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.
This commit is contained in:
1 parent
0e28a48885
commit
08b51adaf1
1 file changed
+12
-4
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user