diff --git a/conda-store-server/alembic/versions/8d63a091aff8_add_environment_description.py b/conda-store-server/alembic/versions/8d63a091aff8_add_environment_description.py new file mode 100644 index 000000000..f54766105 --- /dev/null +++ b/conda-store-server/alembic/versions/8d63a091aff8_add_environment_description.py @@ -0,0 +1,28 @@ +"""Add Environment.description + +Revision ID: 8d63a091aff8 +Revises: 48be4072fe58 +Create Date: 2022-07-15 14:22:00.351131 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = '8d63a091aff8' +down_revision = '48be4072fe58' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('environment', sa.Column('description', sa.UnicodeText(), nullable=True)) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('environment', 'description') + # ### end Alembic commands ### diff --git a/conda-store-server/conda_store_server/app.py b/conda-store-server/conda_store_server/app.py index 7580d81a0..dd5200f0b 100644 --- a/conda-store-server/conda_store_server/app.py +++ b/conda-store-server/conda_store_server/app.py @@ -446,9 +446,13 @@ def register_environment( environment = orm.Environment( name=specification.name, namespace_id=namespace.id, + description=specification.spec["description"], ) self.db.add(environment) self.db.commit() + else: + environment.description = specification.description + self.db.commit() build = self.create_build(environment.id, specification.sha256) @@ -518,6 +522,17 @@ def update_environment_build(self, namespace, name, build_id): tasks.task_update_environment_build.si(environment.id).apply_async() + def update_environment_description(self, namespace, name, description): + + environment = api.get_environment(self.db, namespace=namespace, name=name) + if environment is None: + raise utils.CondaStoreError( + f"environment namespace={namespace} name={name} does not exist" + ) + + environment.description = description + self.db.commit() + def delete_namespace(self, namespace): namespace = api.get_namespace(self.db, name=namespace) if namespace is None: diff --git a/conda-store-server/conda_store_server/orm.py b/conda-store-server/conda_store_server/orm.py index e6f4ac962..8b126e4b9 100644 --- a/conda-store-server/conda_store_server/orm.py +++ b/conda-store-server/conda_store_server/orm.py @@ -16,6 +16,7 @@ DateTime, UniqueConstraint, ForeignKey, + UnicodeText, ) from sqlalchemy.orm import sessionmaker, relationship, scoped_session, backref from sqlalchemy.ext.declarative import declarative_base @@ -276,6 +277,8 @@ class Environment(Base): deleted_on = Column(DateTime, default=None) + description = Column(UnicodeText, default=None) + class CondaChannel(Base): __tablename__ = "conda_channel" diff --git a/conda-store-server/conda_store_server/schema.py b/conda-store-server/conda_store_server/schema.py index fd7d3826d..3786c45e5 100644 --- a/conda-store-server/conda_store_server/schema.py +++ b/conda-store-server/conda_store_server/schema.py @@ -179,6 +179,7 @@ class CondaSpecification(BaseModel): channels: List[str] = [] dependencies: List[Union[str, CondaSpecificationPip]] = [] prefix: Optional[str] + description: Optional[str] = "" @validator("dependencies", each_item=True) def check_dependencies(cls, v): diff --git a/conda-store-server/conda_store_server/server/views/api.py b/conda-store-server/conda_store_server/server/views/api.py index eb1d807f9..2bc62fbcb 100644 --- a/conda-store-server/conda_store_server/server/views/api.py +++ b/conda-store-server/conda_store_server/server/views/api.py @@ -396,14 +396,20 @@ def api_update_environment_build( request: Request, conda_store=Depends(dependencies.get_conda_store), auth=Depends(dependencies.get_auth), - build_id: int = Body(..., embed=True), + build_id: int = Body(None, embed=True), + description: str = Body(None, embed=True), ): auth.authorize_request( request, f"{namespace}/{name}", {Permissions.ENVIRONMENT_UPDATE}, require=True ) try: - conda_store.update_environment_build(namespace, name, build_id) + if build_id is not None: + conda_store.update_environment_build(namespace, name, build_id) + + if description is not None: + conda_store.update_environment_description(namespace, name, description) + except utils.CondaStoreError as e: raise HTTPException(status_code=400, detail=e.message)