Skip to content

Commit

Permalink
✨ adding migration of projects_nodes + connect pricing-unit with proj…
Browse files Browse the repository at this point in the history
…ect_nodes endpoint ( 🗃️) (#4834)
  • Loading branch information
matusdrobuliak66 authored Oct 9, 2023
1 parent 2cda9fd commit 7b16e96
Show file tree
Hide file tree
Showing 17 changed files with 769 additions and 17 deletions.
63 changes: 63 additions & 0 deletions api/specs/web-server/_project_nodes_pricing_unit.py
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
)
4 changes: 2 additions & 2 deletions api/specs/web-server/_projects_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from simcore_service_webserver._meta import API_VTAG
from simcore_service_webserver.projects._crud_handlers import ProjectPathParams
from simcore_service_webserver.projects._nodes_handlers import (
_NodePathParams,
NodePathParams,
_ProjectGroupAccess,
_ProjectNodePreview,
)
Expand Down Expand Up @@ -170,4 +170,4 @@ async def get_project_node_preview(project_id: ProjectID, node_id: NodeID):
...


assert_handler_signature_against_model(get_project_node_preview, _NodePathParams)
assert_handler_signature_against_model(get_project_node_preview, NodePathParams)
8 changes: 8 additions & 0 deletions api/specs/web-server/_wallets.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ async def list_wallets():
...


@router.get(
"/wallets/{wallet_id}",
response_model=Envelope[WalletGetWithAvailableCredits],
)
async def get_wallet(wallet_id: WalletID):
...


@router.put(
"/wallets/{wallet_id}",
response_model=Envelope[WalletGet],
Expand Down
1 change: 1 addition & 0 deletions api/specs/web-server/openapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"_projects_crud",
"_projects_metadata",
"_projects_nodes",
"_project_nodes_pricing_unit",
"_projects_ports",
"_projects_states",
"_projects_tags",
Expand Down
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)")
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)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
projects_nodes = sa.Table(
"projects_nodes",
metadata,
sa.Column(
"project_node_id",
sa.Integer,
nullable=False,
autoincrement=True,
primary_key=True,
doc="Project node index",
),
sa.Column(
"project_uuid",
sa.String,
Expand All @@ -28,14 +36,14 @@
name="fk_projects_to_projects_nodes_to_projects_uuid",
),
nullable=False,
primary_key=False,
index=True,
doc="The project unique identifier",
),
sa.Column(
"node_id",
sa.String,
nullable=False,
primary_key=False,
index=True,
doc="The node unique identifier",
),
sa.Column(
Expand All @@ -48,7 +56,7 @@
# TIME STAMPS ----
column_created_datetime(timezone=True),
column_modified_datetime(timezone=True),
sa.PrimaryKeyConstraint("project_uuid", "node_id"),
sa.UniqueConstraint("project_uuid", "node_id"),
)


Expand Down
Loading

0 comments on commit 7b16e96

Please sign in to comment.