Skip to content

Commit 5f6f274

Browse files
committed
Merge branch 'is5646/use-project-nodes-table-instead-of-workbench' of github.com:giancarloromeo/osparc-simcore into pr/giancarloromeo/8141
2 parents 791e8b3 + 54028fb commit 5f6f274

File tree

4 files changed

+52
-43
lines changed

4 files changed

+52
-43
lines changed

packages/postgres-database/src/simcore_postgres_database/utils_projects.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sqlalchemy.ext.asyncio import AsyncConnection
88

99
from .models.projects import projects
10-
from .utils_repos import transaction_context
10+
from .utils_repos import pass_or_acquire_connection, transaction_context
1111

1212

1313
class DBBaseProjectError(OsparcErrorMixin, Exception):
@@ -22,6 +22,23 @@ class ProjectsRepo:
2222
def __init__(self, engine):
2323
self.engine = engine
2424

25+
async def exists(
26+
self,
27+
project_uuid: uuid.UUID,
28+
*,
29+
connection: AsyncConnection | None = None,
30+
) -> bool:
31+
async with pass_or_acquire_connection(self.engine, connection) as conn:
32+
return (
33+
await conn.scalar(
34+
sa.select(1)
35+
.select_from(projects)
36+
.where(projects.c.uuid == project_uuid)
37+
.limit(1)
38+
)
39+
is not None
40+
)
41+
2542
async def get_project_last_change_date(
2643
self,
2744
project_uuid: uuid.UUID,

packages/pytest-simcore/src/pytest_simcore/simcore_storage_data_models.py

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from models_library.users import UserID
1515
from pydantic import TypeAdapter
1616
from simcore_postgres_database.models.project_to_groups import project_to_groups
17+
from simcore_postgres_database.models.projects_nodes import projects_nodes
1718
from simcore_postgres_database.storage_models import projects, users
1819
from sqlalchemy.dialects.postgresql import insert as pg_insert
1920
from sqlalchemy.ext.asyncio import AsyncConnection, AsyncEngine
@@ -219,26 +220,19 @@ async def _creator(
219220
project_id: ProjectID, node_id: NodeID | None = None, **kwargs
220221
) -> NodeID:
221222
async with sqlalchemy_async_engine.begin() as conn:
222-
result = await conn.execute(
223-
sa.select(projects.c.workbench).where(
224-
projects.c.uuid == f"{project_id}"
225-
)
226-
)
227-
row = result.fetchone()
228-
assert row
229-
project_workbench: dict[str, Any] = row.workbench
230-
new_node_id = node_id or NodeID(f"{faker.uuid4()}")
231-
node_data = {
223+
new_node_id = node_id or NodeID(faker.uuid4())
224+
node_values = {
232225
"key": "simcore/services/frontend/file-picker",
233226
"version": "1.0.0",
234227
"label": "pytest_fake_node",
235228
}
236-
node_data.update(**kwargs)
237-
project_workbench.update({f"{new_node_id}": node_data})
229+
node_values.update(**kwargs)
238230
await conn.execute(
239-
projects.update()
240-
.where(projects.c.uuid == f"{project_id}")
241-
.values(workbench=project_workbench)
231+
projects_nodes.insert().values(
232+
node_id=f"{new_node_id}",
233+
project_uuid=f"{project_id}",
234+
**node_values,
235+
)
242236
)
243237
return new_node_id
244238

services/storage/src/simcore_service_storage/modules/db/projects.py

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from models_library.projects import ProjectAtDB, ProjectID, ProjectIDStr
66
from models_library.projects_nodes_io import NodeIDStr
77
from pydantic import ValidationError
8+
from simcore_postgres_database.models.projects_nodes import projects_nodes
89
from simcore_postgres_database.storage_models import projects
910
from simcore_postgres_database.utils_repos import pass_or_acquire_connection
1011
from sqlalchemy.ext.asyncio import AsyncConnection
@@ -32,38 +33,34 @@ async def list_valid_projects_in(
3233
with suppress(ValidationError):
3334
yield ProjectAtDB.model_validate(row)
3435

35-
async def project_exists(
36-
self,
37-
*,
38-
connection: AsyncConnection | None = None,
39-
project_uuid: ProjectID,
40-
) -> bool:
41-
async with pass_or_acquire_connection(self.db_engine, connection) as conn:
42-
return bool(
43-
await conn.scalar(
44-
sa.select(sa.func.count())
45-
.select_from(projects)
46-
.where(projects.c.uuid == f"{project_uuid}")
47-
)
48-
== 1
49-
)
50-
5136
async def get_project_id_and_node_id_to_names_map(
5237
self,
5338
*,
5439
connection: AsyncConnection | None = None,
5540
project_uuids: list[ProjectID],
5641
) -> dict[ProjectID, dict[ProjectIDStr | NodeIDStr, str]]:
57-
mapping = {}
42+
names_map = {}
5843
async with pass_or_acquire_connection(self.db_engine, connection) as conn:
5944
async for row in await conn.stream(
60-
sa.select(projects.c.uuid, projects.c.name, projects.c.workbench).where(
61-
projects.c.uuid.in_(f"{pid}" for pid in project_uuids)
45+
sa.select(projects.c.uuid, projects.c.name).where(
46+
projects.c.uuid.in_(
47+
[f"{project_uuid}" for project_uuid in project_uuids]
48+
)
49+
)
50+
):
51+
names_map[ProjectID(row.uuid)] = {f"{row.uuid}": row.name}
52+
53+
async for row in await conn.stream(
54+
sa.select(
55+
projects_nodes.c.node_id,
56+
projects_nodes.c.project_uuid,
57+
projects_nodes.c.label,
58+
).where(
59+
projects_nodes.c.project_uuid.in_(
60+
[f"{project_uuid}" for project_uuid in project_uuids]
61+
)
6262
)
6363
):
64-
mapping[ProjectID(f"{row.uuid}")] = {f"{row.uuid}": row.name} | {
65-
f"{node_id}": node["label"]
66-
for node_id, node in row.workbench.items()
67-
}
64+
names_map[ProjectID(row.project_uuid)] |= {f"{row.node_id}": row.label}
6865

69-
return mapping
66+
return names_map

services/storage/src/simcore_service_storage/simcore_s3_dsm.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from servicelib.logging_utils import log_context
4242
from servicelib.progress_bar import ProgressBarData
4343
from servicelib.utils import ensure_ends_with, limited_gather
44+
from simcore_postgres_database.utils_projects import ProjectsRepo
4445
from simcore_postgres_database.utils_repos import transaction_context
4546
from sqlalchemy.ext.asyncio import AsyncEngine
4647

@@ -792,9 +793,9 @@ async def deep_copy_project_simcore_s3(
792793
task_progress.description = "Checking study access rights..."
793794

794795
for prj_uuid in [src_project_uuid, dst_project_uuid]:
795-
if not await ProjectRepository.instance(
796-
get_db_engine(self.app)
797-
).project_exists(project_uuid=prj_uuid):
796+
if not await ProjectsRepo(get_db_engine(self.app)).exists(
797+
project_uuid=prj_uuid
798+
):
798799
raise ProjectNotFoundError(project_id=prj_uuid)
799800
source_access_rights = await AccessLayerRepository.instance(
800801
get_db_engine(self.app)

0 commit comments

Comments
 (0)