-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ adding migration of projects_nodes + connect pricing-unit with proj…
…ect_nodes endpoint ( 🗃️) (#4834)
- Loading branch information
1 parent
2cda9fd
commit 7b16e96
Showing
17 changed files
with
769 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" Helper script to automatically generate OAS | ||
This OAS are the source of truth | ||
""" | ||
|
||
# pylint: disable=redefined-outer-name | ||
# pylint: disable=unused-argument | ||
# pylint: disable=unused-variable | ||
# pylint: disable=too-many-arguments | ||
|
||
|
||
from _common import assert_handler_signature_against_model | ||
from fastapi import APIRouter, status | ||
from models_library.api_schemas_webserver.resource_usage import PricingUnitGet | ||
from models_library.generics import Envelope | ||
from models_library.projects import ProjectID | ||
from models_library.projects_nodes_io import NodeID | ||
from models_library.resource_tracker import PricingPlanId, PricingUnitId | ||
from simcore_service_webserver._meta import API_VTAG | ||
from simcore_service_webserver.projects._nodes_handlers import NodePathParams | ||
|
||
# from simcore_service_webserver.projects._common_models import ProjectPathParams | ||
from simcore_service_webserver.projects._project_nodes_pricing_unit_handlers import ( | ||
_ProjectNodePricingUnitPathParams, | ||
) | ||
|
||
router = APIRouter( | ||
prefix=f"/{API_VTAG}", | ||
tags=[ | ||
"projects", | ||
], | ||
) | ||
|
||
|
||
@router.get( | ||
"/projects/{project_id}/nodes/{node_id}/pricing-unit", | ||
response_model=Envelope[PricingUnitGet | None], | ||
summary="Get currently connected pricing unit to the project node.", | ||
) | ||
async def get_project_node_pricing_unit(project_id: ProjectID, node_id: NodeID): | ||
... | ||
|
||
|
||
assert_handler_signature_against_model(get_project_node_pricing_unit, NodePathParams) | ||
|
||
|
||
@router.put( | ||
"/projects/{project_id}/nodes/{node_id}/pricing-plan/{pricing_plan_id}/pricing-unit/{pricing_unit_id}", | ||
summary="Connect pricing unit to the project node (Project node can have only one pricing unit)", | ||
status_code=status.HTTP_204_NO_CONTENT, | ||
) | ||
async def connect_pricing_unit_to_project_node( | ||
project_id: ProjectID, | ||
node_id: NodeID, | ||
pricing_plan_id: PricingPlanId, | ||
pricing_unit_id: PricingUnitId, | ||
): | ||
... | ||
|
||
|
||
assert_handler_signature_against_model( | ||
connect_pricing_unit_to_project_node, _ProjectNodePricingUnitPathParams | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...postgres_database/migration/versions/57ab8c419ca6_project_nodes_modification_creation_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
"""project_nodes modification + creation projects_node_to_pricing_unit | ||
Revision ID: 57ab8c419ca6 | ||
Revises: b102946c8134 | ||
Create Date: 2023-10-05 18:26:26.018893+00:00 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "57ab8c419ca6" | ||
down_revision = "b102946c8134" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.execute("ALTER TABLE projects_nodes DROP CONSTRAINT projects_nodes_pkey") | ||
op.execute( | ||
"ALTER TABLE projects_nodes ADD COLUMN project_node_id SERIAL PRIMARY KEY" | ||
) | ||
op.execute( | ||
"ALTER TABLE projects_nodes ADD CONSTRAINT projects_nodes__node_project UNIQUE (node_id, project_uuid)" | ||
) | ||
|
||
op.create_index( | ||
op.f("ix_projects_nodes_node_id"), "projects_nodes", ["node_id"], unique=False | ||
) | ||
op.create_index( | ||
op.f("ix_projects_nodes_project_uuid"), | ||
"projects_nodes", | ||
["project_uuid"], | ||
unique=False, | ||
) | ||
|
||
op.create_table( | ||
"projects_node_to_pricing_unit", | ||
sa.Column("project_node_id", sa.BigInteger(), nullable=False), | ||
sa.Column("pricing_plan_id", sa.BigInteger(), nullable=False), | ||
sa.Column("pricing_unit_id", sa.BigInteger(), nullable=False), | ||
sa.Column( | ||
"created", | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
sa.Column( | ||
"modified", | ||
sa.DateTime(timezone=True), | ||
server_default=sa.text("now()"), | ||
nullable=False, | ||
), | ||
sa.ForeignKeyConstraint( | ||
["project_node_id"], | ||
["projects_nodes.project_node_id"], | ||
name="fk_projects_nodes__project_node_to_pricing_unit__uuid", | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
), | ||
sa.UniqueConstraint("project_node_id"), | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table("projects_node_to_pricing_unit") | ||
|
||
op.drop_index(op.f("ix_projects_nodes_project_uuid"), table_name="projects_nodes") | ||
op.drop_index(op.f("ix_projects_nodes_node_id"), table_name="projects_nodes") | ||
|
||
op.execute("ALTER TABLE projects_nodes DROP CONSTRAINT projects_nodes_pkey") | ||
op.execute( | ||
"ALTER TABLE projects_nodes DROP CONSTRAINT projects_nodes__node_project" | ||
) | ||
op.execute("ALTER TABLE projects_nodes ADD PRIMARY KEY (node_id, project_uuid)") |
51 changes: 51 additions & 0 deletions
51
...s/postgres-database/src/simcore_postgres_database/models/projects_node_to_pricing_unit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" Groups table | ||
- List of groups in the framework | ||
- Groups have a ID, name and a list of users that belong to the group | ||
""" | ||
|
||
import sqlalchemy as sa | ||
|
||
from ._common import ( | ||
column_created_datetime, | ||
column_modified_datetime, | ||
register_modified_datetime_auto_update_trigger, | ||
) | ||
from .base import metadata | ||
from .projects_nodes import projects_nodes | ||
|
||
projects_node_to_pricing_unit = sa.Table( | ||
"projects_node_to_pricing_unit", | ||
metadata, | ||
sa.Column( | ||
"project_node_id", | ||
sa.Integer, | ||
sa.ForeignKey( | ||
projects_nodes.c.project_node_id, | ||
onupdate="CASCADE", | ||
ondelete="CASCADE", | ||
name="fk_projects_nodes__project_node_to_pricing_unit__uuid", | ||
), | ||
nullable=False, | ||
doc="The project node unique identifier", | ||
), | ||
sa.Column( | ||
"pricing_plan_id", | ||
sa.BigInteger, | ||
nullable=False, | ||
doc="The pricing plan unique identifier", | ||
), | ||
sa.Column( | ||
"pricing_unit_id", | ||
sa.BigInteger, | ||
nullable=False, | ||
doc="The pricing unit unique identifier", | ||
), | ||
# TIME STAMPS ---- | ||
column_created_datetime(timezone=True), | ||
column_modified_datetime(timezone=True), | ||
sa.UniqueConstraint("project_node_id"), | ||
) | ||
|
||
|
||
register_modified_datetime_auto_update_trigger(projects_nodes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.