Repository: mlrun/mlrun

Issue:
Add list_projects & list_artifact_tags(project)
The wevb API needs these

Discussion:
yaronha: @tebeka need to resolve conflicts
tebeka: Rebased to `development`

Patch:
diff --git a/mlrun/db/sqldb.py b/mlrun/db/sqldb.py
index 712b970d3..b87f24cf5 100644
--- a/mlrun/db/sqldb.py
+++ b/mlrun/db/sqldb.py
@@ -320,6 +320,14 @@ class SQLDB(RunDBInterface):
         )
         return funcs
 
+    def list_projects(self):
+        return [row[0] for row in self.session.query(Run.project).distinct()]
+
+    def list_artifact_tags(self, project):
+        query = self.session.query(Artifact.tag).filter(
+            Artifact.project == project).distinct()
+        return [row[0] for row in query]
+
     def _query(self, cls, **kw):
         kw = {k: v for k, v in kw.items() if v}
         return self.session.query(cls).filter_by(**kw)


Test patch:
diff --git a/tests/test_sqldb.py b/tests/test_sqldb.py
index e35ee8770..ff161f6bb 100644
--- a/tests/test_sqldb.py
+++ b/tests/test_sqldb.py
@@ -160,6 +160,23 @@ def test_artifacts(db: sqldb.SQLDB):
         db.read_artifact(k1)
 
 
+def test_list_artifact_tags(db: sqldb.SQLDB):
+    db.store_artifact('k1', {}, '1', 't1', 'p1')
+    db.store_artifact('k1', {}, '2', 't2', 'p1')
+    db.store_artifact('k1', {}, '2', 't2', 'p2')
+
+    tags = db.list_artifact_tags('p1')
+    assert {'t1', 't2'} == set(tags), 'bad tags'
+
+
+def test_list_projects(db: sqldb.SQLDB):
+    for i in range(10):
+        run = new_run('s1', ['l1', 'l2'], x=1)
+        db.store_run(run, 'u7', project=f'prj{i%3}', iter=i)
+
+    assert {'prj0', 'prj1', 'prj2'} == set(db.list_projects())
+
+
 def test_list_runs(db: sqldb.SQLDB):
     uid = 'u183'
     run = new_run('s1', ['l1', 'l2'], x=1)