Skip to content

Commit 33cc673

Browse files
Merge remote-tracking branch 'origin/main' into improve_filter_query
* origin/main: Add synaptome assets label (#176) Make EModel read_one/read_many schemas consistent (#177)
2 parents 3902c62 + 0d79b13 commit 33cc673

File tree

5 files changed

+83
-15
lines changed

5 files changed

+83
-15
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""Default migration message
2+
3+
Revision ID: 4da94988fa4f
4+
Revises: 19e6c28114fa
5+
Create Date: 2025-05-19 13:36:45.039741
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
from alembic import op
12+
import sqlalchemy as sa
13+
from alembic_postgresql_enum import TableReference
14+
15+
from sqlalchemy import Text
16+
import app.db.types
17+
18+
# revision identifiers, used by Alembic.
19+
revision: str = "4da94988fa4f"
20+
down_revision: Union[str, None] = "19e6c28114fa"
21+
branch_labels: Union[str, Sequence[str], None] = None
22+
depends_on: Union[str, Sequence[str], None] = None
23+
24+
25+
def upgrade() -> None:
26+
# ### commands auto generated by Alembic - please adjust! ###
27+
op.sync_enum_values(
28+
enum_schema="public",
29+
enum_name="assetlabel",
30+
new_values=[
31+
"neurolucida",
32+
"swc",
33+
"hdf5",
34+
"cell_composition_summary",
35+
"cell_composition_volumes",
36+
"single_neuron_synaptome_config",
37+
"single_neuron_synaptome_simulation_io_result",
38+
],
39+
affected_columns=[
40+
TableReference(table_schema="public", table_name="asset", column_name="label")
41+
],
42+
enum_values_to_rename=[],
43+
)
44+
# ### end Alembic commands ###
45+
46+
47+
def downgrade() -> None:
48+
# ### commands auto generated by Alembic - please adjust! ###
49+
op.sync_enum_values(
50+
enum_schema="public",
51+
enum_name="assetlabel",
52+
new_values=[
53+
"neurolucida",
54+
"swc",
55+
"hdf5",
56+
"cell_composition_summary",
57+
"cell_composition_volumes",
58+
],
59+
affected_columns=[
60+
TableReference(table_schema="public", table_name="asset", column_name="label")
61+
],
62+
enum_values_to_rename=[],
63+
)
64+
# ### end Alembic commands ###

app/db/types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ class AssetLabel(StrEnum):
187187
hdf5 = auto()
188188
cell_composition_summary = auto()
189189
cell_composition_volumes = auto()
190+
single_neuron_synaptome_config = auto()
191+
single_neuron_synaptome_simulation_io_result = auto()
190192

191193

192194
ALLOWED_ASSET_LABELS_PER_ENTITY = {
@@ -199,4 +201,8 @@ class AssetLabel(StrEnum):
199201
AssetLabel.cell_composition_summary,
200202
AssetLabel.cell_composition_volumes,
201203
},
204+
EntityType.single_neuron_synaptome: {AssetLabel.single_neuron_synaptome_config},
205+
EntityType.single_neuron_synaptome_simulation: {
206+
AssetLabel.single_neuron_synaptome_simulation_io_result
207+
},
202208
}

app/schemas/ion_channel_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
AuthorizationOptionalPublicMixin,
99
BrainRegionRead,
1010
CreationMixin,
11+
EntityTypeMixin,
1112
IdentifiableMixin,
1213
SpeciesRead,
1314
StrainRead,
@@ -49,7 +50,7 @@ class IonChannelModelCreate(IonChannelModelBase, AuthorizationOptionalPublicMixi
4950

5051

5152
class IonChannelModelRead(
52-
IonChannelModelBase, CreationMixin, IdentifiableMixin, AuthorizationMixin
53+
IonChannelModelBase, CreationMixin, IdentifiableMixin, AuthorizationMixin, EntityTypeMixin
5354
):
5455
species: SpeciesRead
5556
strain: StrainRead | None

app/service/emodel.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ def _load(select: sa.Select[tuple[EModel]]):
4646
selectinload(EModel.contributions).joinedload(Contribution.role),
4747
joinedload(EModel.mtypes),
4848
joinedload(EModel.etypes),
49+
selectinload(EModel.assets),
50+
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.species),
51+
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.strain),
52+
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.brain_region),
53+
selectinload(EModel.ion_channel_models).selectinload(IonChannelModel.assets),
4954
raiseload("*"),
5055
)
5156

@@ -55,23 +60,13 @@ def read_one(
5560
db: SessionDep,
5661
id_: uuid.UUID,
5762
) -> EModelReadExpanded:
58-
def _load_expanded(select: sa.Select[tuple[EModel]]):
59-
return _load(select).options(
60-
selectinload(EModel.assets),
61-
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.species),
62-
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.strain),
63-
selectinload(EModel.ion_channel_models).joinedload(IonChannelModel.brain_region),
64-
selectinload(EModel.ion_channel_models).selectinload(IonChannelModel.assets),
65-
raiseload("*"),
66-
)
67-
6863
return router_read_one(
6964
id_=id_,
7065
db=db,
7166
db_model_class=EModel,
7267
authorized_project_id=user_context.project_id,
7368
response_schema_class=EModelReadExpanded,
74-
apply_operations=_load_expanded,
69+
apply_operations=_load,
7570
)
7671

7772

@@ -99,10 +94,12 @@ def read_many(
9994
with_search: SearchDep,
10095
facets: FacetsDep,
10196
in_brain_region: InBrainRegionDep,
102-
) -> ListResponse[EModelRead]:
97+
) -> ListResponse[EModelReadExpanded]:
10398
morphology_alias = aliased(ReconstructionMorphology, flat=True)
99+
ion_channel_model_alias = aliased(IonChannelModel, flat=True)
104100
aliases: Aliases = {
105101
ReconstructionMorphology: morphology_alias,
102+
IonChannelModel: ion_channel_model_alias,
106103
}
107104

108105
name_to_facet_query_params: dict[str, FacetQueryParams] = {
@@ -149,7 +146,7 @@ def read_many(
149146
apply_filter_query_operations=None,
150147
apply_data_query_operations=_load,
151148
pagination_request=pagination_request,
152-
response_schema_class=EModelRead,
149+
response_schema_class=EModelReadExpanded,
153150
name_to_facet_query_params=name_to_facet_query_params,
154151
filter_model=emodel_filter,
155152
filter_joins=filter_joins,

tests/test_emodel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def test_query_emodel(client: TestClient, create_emodel_ids: CreateIds):
7878
assert len(data) == 11
7979

8080
assert "assets" in data[0]
81-
assert "ion_channel_models" not in data[0]
81+
assert "ion_channel_models" in data[0]
8282

8383

8484
def test_emodels_sorted(client: TestClient, create_emodel_ids: CreateIds):

0 commit comments

Comments
 (0)