Skip to content

Commit 08d4f80

Browse files
fix model
2 parents 45a1cbc + ee2bd0e commit 08d4f80

File tree

17 files changed

+354
-142
lines changed

17 files changed

+354
-142
lines changed

.github/mergify.yml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
# NOTE: the PR is added to the queue when all checks have passed
2-
# and the CI is fully green.
3-
# If the PR is behind the queue will take care of updating it
41
queue_rules:
52
- name: default
6-
queue_conditions:
3+
queue_conditions: # condtions to be met to add the PR to the queue (manually or automatically)
74
# general prerequisits fo accept the PR in the queue
85
- label=🤖-automerge # let Mergify know that the PR can be merged (added manually)
96
- label!=🤖-do-not-merge # block Mergify from merging the PR (added manually)
@@ -16,17 +13,17 @@ queue_rules:
1613
- "#changes-requested-reviews-by=0" # No changes requested
1714
- "#review-threads-unresolved=0" # All review threads resolved
1815

19-
merge_conditions:
16+
merge_conditions: # conditions to be met before being able to merge
2017
# list of CI checks that need to pass
18+
- check-success=system-test-environment-setup
19+
- check-success=changes
20+
- check-success=build-test-images
21+
- check-success=build-test-images-frontend
2122
- check-success=unit-tests
2223
- check-success=integration-tests
2324
- check-success=system-tests
2425

25-
# NOTE: in case of flaky tests you above checks will fail
26-
# the PR will be removed from the queue.
27-
# Once the PR is ready to be merged the flaky tests will
28-
# be retried automatically.
29-
# As soon as the CI is green, the PR will be pushed to the queue
26+
3027
pull_request_rules:
3128
- name: retry flaky tests (when PR is approved)
3229
conditions:
@@ -41,6 +38,10 @@ pull_request_rules:
4138
- "#review-threads-unresolved=0" # All review threads resolved
4239

4340
- or:
41+
- check-failure=system-test-environment-setup
42+
- check-failure=changes
43+
- check-failure=build-test-images
44+
- check-failure=build-test-images-frontend
4445
- check-failure=unit-tests
4546
- check-failure=integration-tests
4647
- check-failure=system-tests
@@ -51,3 +52,18 @@ pull_request_rules:
5152
workflow:
5253
dispatch:
5354
- workflow: ci-testing-deploy.yml
55+
56+
- name: Automatically add PR to queue if it meets conditions
57+
conditions:
58+
- "label=🤖-automerge"
59+
- "label!=🤖-do-not-merge"
60+
- "base=master"
61+
62+
- "-draft" # PR is not in draft state
63+
- "-conflict" # PR has no conflicts
64+
- "#approved-reviews-by>=2" # Requires 2 approvals
65+
- "#changes-requested-reviews-by=0" # No requested changes
66+
- "#review-threads-unresolved=0" # All review threads resolved
67+
actions:
68+
queue:
69+
name: default

packages/models-library/src/models_library/api_schemas_webserver/licensed_items.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
from datetime import datetime
2-
from typing import Any, NamedTuple
2+
from typing import NamedTuple
33

4+
from common_library.dict_tools import remap_keys
45
from models_library.licensed_items import (
56
VIP_DETAILS_EXAMPLE,
7+
LicensedItemDB,
68
LicensedItemID,
79
LicensedResourceType,
810
)
911
from models_library.resource_tracker import PricingPlanId
1012
from models_library.utils.common_validators import to_camel_recursive
1113
from pydantic import AfterValidator, BaseModel, ConfigDict, PositiveInt
12-
from pydantic.alias_generators import to_camel
1314
from typing_extensions import Annotated
1415

1516
from ._base import OutputSchema
@@ -48,17 +49,6 @@ class LicensedItemRpcGetPage(NamedTuple):
4849

4950

5051
# Rest
51-
class CustomBaseModel(BaseModel):
52-
model_config = ConfigDict(
53-
alias_generator=to_camel, populate_by_name=True, extra="allow"
54-
)
55-
56-
def model_dump_camel(self):
57-
data = self.model_dump(by_alias=True)
58-
if hasattr(self, "__pydantic_extra__") and self.__pydantic_extra__:
59-
extra_camel = {to_camel(k): v for k, v in self.__pydantic_extra__.items()}
60-
data.update(extra_camel)
61-
return data
6252

6353

6454
class LicensedItemRestGet(OutputSchema):
@@ -87,6 +77,28 @@ class LicensedItemRestGet(OutputSchema):
8777
}
8878
)
8979

80+
@classmethod
81+
def from_domain_model(cls, licensed_item_db: LicensedItemDB) -> Self:
82+
return cls.model_validate(
83+
remap_keys(
84+
licensed_item_db.model_dump(
85+
include={
86+
"licensed_item_id",
87+
"licensed_resource_name",
88+
"license_key",
89+
"pricing_plan_id",
90+
"created",
91+
"modified",
92+
}
93+
),
94+
{
95+
"licensed_resource_name": "name",
96+
"created": "created_at",
97+
"modified": "modified_at",
98+
},
99+
)
100+
)
101+
90102

91103
class LicensedItemRestGetPage(NamedTuple):
92104
items: list[LicensedItemRestGet]

packages/models-library/src/models_library/licensed_items.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import Any, TypeAlias
44
from uuid import UUID
55

6-
from pydantic import BaseModel, ConfigDict, Field
6+
from pydantic import BaseModel, ConfigDict
77

88
from .products import ProductName
99
from .resource_tracker import PricingPlanId
@@ -50,23 +50,23 @@ class LicensedResourceType(StrAutoEnum):
5050

5151
class LicensedItemDB(BaseModel):
5252
licensed_item_id: LicensedItemID
53-
display_name: str
53+
54+
licensed_resource_name: str
5455
licensed_resource_type: LicensedResourceType
55-
pricing_plan_id: PricingPlanId
56-
product_name: ProductName
57-
licensed_resource_type_details: dict[str, Any]
58-
created: datetime = Field(
59-
...,
60-
description="Timestamp on creation",
61-
)
62-
modified: datetime = Field(
63-
...,
64-
description="Timestamp of last modification",
65-
)
66-
# ----
56+
licensed_resource_data: dict[str, Any] | None
57+
58+
pricing_plan_id: PricingPlanId | None
59+
product_name: ProductName | None
60+
61+
# states
62+
created: datetime
63+
modified: datetime
64+
trashed: datetime | None
65+
6766
model_config = ConfigDict(from_attributes=True)
6867

6968

7069
class LicensedItemUpdateDB(BaseModel):
7170
display_name: str | None = None
7271
pricing_plan_id: PricingPlanId | None = None
72+
trash: bool | None = None
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
"""add data to licensed_items
2+
3+
Revision ID: 4f31760a63ba
4+
Revises: 1bc517536e0a
5+
Create Date: 2025-01-29 16:51:16.453069+00:00
6+
7+
"""
8+
import sqlalchemy as sa
9+
from alembic import op
10+
from sqlalchemy.dialects import postgresql
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "4f31760a63ba"
14+
down_revision = "1bc517536e0a"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
21+
with op.batch_alter_table("licensed_items") as batch_op:
22+
batch_op.alter_column(
23+
"name",
24+
new_column_name="licensed_resource_name",
25+
existing_type=sa.String(),
26+
nullable=False,
27+
)
28+
batch_op.alter_column(
29+
"pricing_plan_id",
30+
existing_type=sa.Integer(),
31+
nullable=True,
32+
)
33+
batch_op.alter_column(
34+
"product_name",
35+
existing_type=sa.String(),
36+
nullable=True,
37+
)
38+
39+
# ### commands auto generated by Alembic - please adjust! ###
40+
op.add_column(
41+
"licensed_items",
42+
sa.Column(
43+
"licensed_resource_data",
44+
postgresql.JSONB(astext_type=sa.Text()),
45+
nullable=True,
46+
),
47+
)
48+
op.add_column(
49+
"licensed_items",
50+
sa.Column(
51+
"trashed",
52+
sa.DateTime(timezone=True),
53+
nullable=True,
54+
comment="The date and time when the licensed_item was marked as trashed. Null if the licensed_item has not been trashed [default].",
55+
),
56+
)
57+
# ### end Alembic commands ###
58+
59+
60+
def downgrade():
61+
# ### commands auto generated by Alembic - please adjust! ###
62+
op.drop_column("licensed_items", "trashed")
63+
op.drop_column("licensed_items", "licensed_resource_data")
64+
# ### end Alembic commands ###
65+
66+
# Delete rows with null values in pricing_plan_id and product_name
67+
op.execute(
68+
sa.DDL(
69+
"""
70+
DELETE FROM licensed_items
71+
WHERE pricing_plan_id IS NULL OR product_name IS NULL;
72+
"""
73+
)
74+
)
75+
print(
76+
"Warning: Rows with null values in pricing_plan_id or product_name have been deleted."
77+
)
78+
79+
with op.batch_alter_table("licensed_items") as batch_op:
80+
81+
batch_op.alter_column(
82+
"product_name",
83+
existing_type=sa.String(),
84+
nullable=False,
85+
)
86+
batch_op.alter_column(
87+
"pricing_plan_id",
88+
existing_type=sa.Integer(),
89+
nullable=False,
90+
)
91+
batch_op.alter_column(
92+
"licensed_resource_name",
93+
new_column_name="name",
94+
existing_type=sa.String(),
95+
nullable=False,
96+
)

packages/postgres-database/src/simcore_postgres_database/migration/versions/7bde20ddf18e_modify_licensed_items_db.py

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""modify licensed items DB
2+
3+
Revision ID: b8e3837d8d87
4+
Revises: 4f31760a63ba
5+
Create Date: 2025-01-30 12:52:12.401782+00:00
6+
7+
"""
8+
import sqlalchemy as sa
9+
from alembic import op
10+
11+
# revision identifiers, used by Alembic.
12+
revision = "b8e3837d8d87"
13+
down_revision = "4f31760a63ba"
14+
branch_labels = None
15+
depends_on = None
16+
17+
18+
def upgrade():
19+
# ### commands auto generated by Alembic - please adjust! ###
20+
op.drop_column("licensed_items", "license_key")
21+
# ### end Alembic commands ###
22+
23+
24+
def downgrade():
25+
# ### commands auto generated by Alembic - please adjust! ###
26+
op.add_column(
27+
"licensed_items",
28+
sa.Column("license_key", sa.VARCHAR(), autoincrement=False, nullable=True),
29+
)
30+
# ### end Alembic commands ###

0 commit comments

Comments
 (0)