Skip to content

Commit 322e5cf

Browse files
1.part of spliting licensed_items to licenses + licensed_resources
1 parent f89181c commit 322e5cf

File tree

12 files changed

+991
-44
lines changed

12 files changed

+991
-44
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from datetime import datetime
2+
from typing import TypeAlias
3+
from uuid import UUID
4+
5+
from pydantic import BaseModel, ConfigDict
6+
7+
from .licensed_items import LicensedResourceType
8+
from .products import ProductName
9+
from .resource_tracker import PricingPlanId
10+
11+
LicenseID: TypeAlias = UUID
12+
13+
14+
#
15+
# DB
16+
#
17+
18+
19+
class LicenseDB(BaseModel):
20+
license_id: LicenseID
21+
display_name: str
22+
licensed_resource_type: LicensedResourceType
23+
pricing_plan_id: PricingPlanId
24+
product_name: ProductName
25+
26+
# states
27+
created: datetime
28+
modified: datetime
29+
30+
model_config = ConfigDict(from_attributes=True)
31+
32+
33+
class LicenseUpdateDB(BaseModel):
34+
display_name: str | None = None
35+
pricing_plan_id: PricingPlanId | None = None
36+
37+
38+
#
39+
# License Domain
40+
#
41+
42+
43+
class License(BaseModel):
44+
license_id: LicenseID
45+
display_name: str
46+
licensed_resource_type: LicensedResourceType
47+
resources: list[dict]
48+
pricing_plan_id: PricingPlanId
49+
product_name: ProductName
50+
51+
model_config = ConfigDict(from_attributes=True)
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
"""add licenses table
2+
3+
Revision ID: 2215301c2496
4+
Revises: e71ea59858f4
5+
Create Date: 2025-02-04 15:26:27.325429+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 = "2215301c2496"
14+
down_revision = "e71ea59858f4"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.create_table(
22+
"licensed_resources",
23+
sa.Column(
24+
"licensed_item_id",
25+
postgresql.UUID(as_uuid=True),
26+
server_default=sa.text("gen_random_uuid()"),
27+
nullable=False,
28+
),
29+
sa.Column("display_name", sa.String(), nullable=False),
30+
sa.Column("licensed_resource_name", sa.String(), nullable=False),
31+
sa.Column(
32+
"licensed_resource_type",
33+
sa.Enum("VIP_MODEL", name="licensedresourcetype"),
34+
nullable=False,
35+
),
36+
sa.Column(
37+
"licensed_resource_data",
38+
postgresql.JSONB(astext_type=sa.Text()),
39+
nullable=True,
40+
),
41+
sa.Column("pricing_plan_id", sa.BigInteger(), nullable=True),
42+
sa.Column("product_name", sa.String(), nullable=True),
43+
sa.Column(
44+
"created",
45+
sa.DateTime(timezone=True),
46+
server_default=sa.text("now()"),
47+
nullable=False,
48+
),
49+
sa.Column(
50+
"modified",
51+
sa.DateTime(timezone=True),
52+
server_default=sa.text("now()"),
53+
nullable=False,
54+
),
55+
sa.Column(
56+
"trashed",
57+
sa.DateTime(timezone=True),
58+
nullable=True,
59+
comment="The date and time when the licensed_item was marked as trashed. Null if the licensed_item has not been trashed [default].",
60+
),
61+
sa.ForeignKeyConstraint(
62+
["pricing_plan_id"],
63+
["resource_tracker_pricing_plans.pricing_plan_id"],
64+
name="fk_resource_tracker_license_packages_pricing_plan_id",
65+
onupdate="CASCADE",
66+
ondelete="RESTRICT",
67+
),
68+
sa.ForeignKeyConstraint(
69+
["product_name"],
70+
["products.name"],
71+
name="fk_resource_tracker_license_packages_product_name",
72+
onupdate="CASCADE",
73+
ondelete="CASCADE",
74+
),
75+
sa.PrimaryKeyConstraint("licensed_item_id"),
76+
# sa.UniqueConstraint(
77+
# "licensed_resource_name",
78+
# "licensed_resource_type",
79+
# name="uq_licensed_resource_name_type",
80+
# ),
81+
)
82+
op.create_table(
83+
"licenses",
84+
sa.Column(
85+
"license_id",
86+
postgresql.UUID(as_uuid=True),
87+
server_default=sa.text("gen_random_uuid()"),
88+
nullable=False,
89+
),
90+
sa.Column("display_name", sa.String(), nullable=False),
91+
sa.Column(
92+
"licensed_resource_type",
93+
sa.Enum("VIP_MODEL", name="licensedresourcetype"),
94+
nullable=False,
95+
),
96+
sa.Column("pricing_plan_id", sa.BigInteger(), nullable=False),
97+
sa.Column("product_name", sa.String(), nullable=False),
98+
sa.Column(
99+
"created",
100+
sa.DateTime(timezone=True),
101+
server_default=sa.text("now()"),
102+
nullable=False,
103+
),
104+
sa.Column(
105+
"modified",
106+
sa.DateTime(timezone=True),
107+
server_default=sa.text("now()"),
108+
nullable=False,
109+
),
110+
sa.ForeignKeyConstraint(
111+
["pricing_plan_id"],
112+
["resource_tracker_pricing_plans.pricing_plan_id"],
113+
name="fk_resource_tracker_license_packages_pricing_plan_id",
114+
onupdate="CASCADE",
115+
ondelete="RESTRICT",
116+
),
117+
sa.ForeignKeyConstraint(
118+
["product_name"],
119+
["products.name"],
120+
name="fk_resource_tracker_license_packages_product_name",
121+
onupdate="CASCADE",
122+
ondelete="CASCADE",
123+
),
124+
sa.PrimaryKeyConstraint("license_id"),
125+
)
126+
op.create_table(
127+
"license_to_resource",
128+
sa.Column("license_id", postgresql.UUID(as_uuid=True), nullable=False),
129+
sa.Column("licensed_item_id", postgresql.UUID(as_uuid=True), nullable=False),
130+
sa.Column(
131+
"created",
132+
sa.DateTime(timezone=True),
133+
server_default=sa.text("now()"),
134+
nullable=False,
135+
),
136+
sa.Column(
137+
"modified",
138+
sa.DateTime(timezone=True),
139+
server_default=sa.text("now()"),
140+
nullable=False,
141+
),
142+
sa.ForeignKeyConstraint(
143+
["license_id"],
144+
["licenses.license_id"],
145+
name="fk_license_to_resource_license_id",
146+
onupdate="CASCADE",
147+
ondelete="CASCADE",
148+
),
149+
sa.ForeignKeyConstraint(
150+
["licensed_item_id"],
151+
["licensed_resources.licensed_item_id"],
152+
name="fk_license_to_resource_licensed_item_id",
153+
onupdate="CASCADE",
154+
ondelete="CASCADE",
155+
),
156+
)
157+
op.drop_table("licensed_items")
158+
# ### end Alembic commands ###
159+
160+
161+
def downgrade():
162+
# ### commands auto generated by Alembic - please adjust! ###
163+
op.create_table(
164+
"licensed_items",
165+
sa.Column(
166+
"licensed_item_id",
167+
postgresql.UUID(),
168+
server_default=sa.text("gen_random_uuid()"),
169+
autoincrement=False,
170+
nullable=False,
171+
),
172+
sa.Column(
173+
"licensed_resource_name", sa.VARCHAR(), autoincrement=False, nullable=False
174+
),
175+
sa.Column(
176+
"licensed_resource_type",
177+
postgresql.ENUM("VIP_MODEL", name="licensedresourcetype"),
178+
autoincrement=False,
179+
nullable=False,
180+
),
181+
sa.Column("pricing_plan_id", sa.BIGINT(), autoincrement=False, nullable=True),
182+
sa.Column("product_name", sa.VARCHAR(), autoincrement=False, nullable=True),
183+
sa.Column(
184+
"created",
185+
postgresql.TIMESTAMP(timezone=True),
186+
server_default=sa.text("now()"),
187+
autoincrement=False,
188+
nullable=False,
189+
),
190+
sa.Column(
191+
"modified",
192+
postgresql.TIMESTAMP(timezone=True),
193+
server_default=sa.text("now()"),
194+
autoincrement=False,
195+
nullable=False,
196+
),
197+
sa.Column(
198+
"licensed_resource_data",
199+
postgresql.JSONB(astext_type=sa.Text()),
200+
autoincrement=False,
201+
nullable=True,
202+
),
203+
sa.Column(
204+
"trashed",
205+
postgresql.TIMESTAMP(timezone=True),
206+
autoincrement=False,
207+
nullable=True,
208+
comment="The date and time when the licensed_item was marked as trashed. Null if the licensed_item has not been trashed [default].",
209+
),
210+
sa.Column("display_name", sa.VARCHAR(), autoincrement=False, nullable=False),
211+
sa.ForeignKeyConstraint(
212+
["pricing_plan_id"],
213+
["resource_tracker_pricing_plans.pricing_plan_id"],
214+
name="fk_resource_tracker_license_packages_pricing_plan_id",
215+
onupdate="CASCADE",
216+
ondelete="RESTRICT",
217+
),
218+
sa.ForeignKeyConstraint(
219+
["product_name"],
220+
["products.name"],
221+
name="fk_resource_tracker_license_packages_product_name",
222+
onupdate="CASCADE",
223+
ondelete="CASCADE",
224+
),
225+
sa.PrimaryKeyConstraint("licensed_item_id", name="licensed_items_pkey"),
226+
sa.UniqueConstraint(
227+
"licensed_resource_name",
228+
"licensed_resource_type",
229+
name="uq_licensed_resource_name_type",
230+
),
231+
)
232+
op.drop_table("license_to_resource")
233+
op.drop_table("licenses")
234+
op.drop_table("licensed_resources")
235+
# ### end Alembic commands ###
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import sqlalchemy as sa
2+
from sqlalchemy.dialects import postgresql
3+
4+
from ._common import RefActions, column_created_datetime, column_modified_datetime
5+
from .base import metadata
6+
7+
license_to_resource = sa.Table(
8+
"license_to_resource",
9+
metadata,
10+
sa.Column(
11+
"license_id",
12+
postgresql.UUID(as_uuid=True),
13+
sa.ForeignKey(
14+
"licenses.license_id",
15+
name="fk_license_to_resource_license_id",
16+
onupdate=RefActions.CASCADE,
17+
ondelete=RefActions.CASCADE,
18+
),
19+
nullable=False,
20+
),
21+
sa.Column(
22+
"licensed_item_id", # <-- This will be renamed to "licensed_resource_id"
23+
postgresql.UUID(as_uuid=True),
24+
sa.ForeignKey(
25+
"licensed_resources.licensed_item_id", # <-- This will be renamed to "licensed_resource_id"
26+
name="fk_license_to_resource_licensed_item_id",
27+
onupdate=RefActions.CASCADE,
28+
ondelete=RefActions.CASCADE,
29+
),
30+
nullable=False,
31+
),
32+
column_created_datetime(timezone=True),
33+
column_modified_datetime(timezone=True),
34+
)

packages/postgres-database/src/simcore_postgres_database/models/licensed_items.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
""" resource_tracker_service_runs table
2-
"""
3-
4-
import enum
5-
61
import sqlalchemy as sa
72
from sqlalchemy.dialects import postgresql
83

@@ -13,17 +8,13 @@
138
column_trashed_datetime,
149
)
1510
from .base import metadata
11+
from .licenses import LicensedResourceType
1612

17-
18-
class LicensedResourceType(str, enum.Enum):
19-
VIP_MODEL = "VIP_MODEL"
20-
21-
22-
licensed_items = sa.Table(
23-
"licensed_items",
13+
licensed_resources = sa.Table(
14+
"licensed_resources", # <-- This will be renamed to "licensed_resources"
2415
metadata,
2516
sa.Column(
26-
"licensed_item_id",
17+
"licensed_item_id", # <-- This will be renamed to "licensed_resource_id"
2718
postgresql.UUID(as_uuid=True),
2819
nullable=False,
2920
primary_key=True,

0 commit comments

Comments
 (0)