Skip to content

Commit 483c30b

Browse files
authored
Merge branch 'master' into is34/catalog-inherit-icon
2 parents 964ef59 + 8df1e20 commit 483c30b

File tree

40 files changed

+2119
-213
lines changed

40 files changed

+2119
-213
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from models_library.basic_regex import UUID_RE_BASE
88
from models_library.basic_types import ConstrainedStr
99
from models_library.groups import GroupID
10+
from models_library.products import ProductName
1011
from models_library.services_types import ServiceKey, ServiceVersion
1112
from models_library.users import UserID
1213
from pydantic import BaseModel, ConfigDict, Field
@@ -278,6 +279,7 @@ class FunctionGroupAccessRights(FunctionAccessRights):
278279

279280
class FunctionAccessRightsDB(BaseModel):
280281
group_id: GroupID | None = None
282+
product_name: ProductName | None = None
281283
read: bool = False
282284
write: bool = False
283285
execute: bool = False
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""Add functions product access
2+
3+
Revision ID: afb1ba08f3c2
4+
Revises: 275642b33db0
5+
Create Date: 2025-05-30 14:24:46.198755+00:00
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "afb1ba08f3c2"
14+
down_revision = "275642b33db0"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column(
22+
"funcapi_function_job_collections_access_rights",
23+
sa.Column("product_name", sa.String(), nullable=True),
24+
)
25+
op.create_foreign_key(
26+
"fk_func_access_to_products_product_name",
27+
"funcapi_function_job_collections_access_rights",
28+
"products",
29+
["product_name"],
30+
["name"],
31+
onupdate="CASCADE",
32+
ondelete="CASCADE",
33+
)
34+
op.add_column(
35+
"funcapi_function_jobs_access_rights",
36+
sa.Column("product_name", sa.String(), nullable=True),
37+
)
38+
op.create_foreign_key(
39+
"fk_func_access_to_products_product_name",
40+
"funcapi_function_jobs_access_rights",
41+
"products",
42+
["product_name"],
43+
["name"],
44+
onupdate="CASCADE",
45+
ondelete="CASCADE",
46+
)
47+
op.add_column(
48+
"funcapi_functions_access_rights",
49+
sa.Column("product_name", sa.String(), nullable=True),
50+
)
51+
op.create_foreign_key(
52+
"fk_func_access_to_products_product_name",
53+
"funcapi_functions_access_rights",
54+
"products",
55+
["product_name"],
56+
["name"],
57+
onupdate="CASCADE",
58+
ondelete="CASCADE",
59+
)
60+
61+
# Backfill existing rows with "osparc"
62+
op.execute(
63+
"""
64+
UPDATE funcapi_function_job_collections_access_rights
65+
SET product_name = 'osparc'
66+
WHERE product_name IS NULL
67+
"""
68+
)
69+
op.execute(
70+
"""
71+
UPDATE funcapi_function_jobs_access_rights
72+
SET product_name = 'osparc'
73+
WHERE product_name IS NULL
74+
"""
75+
)
76+
op.execute(
77+
"""
78+
UPDATE funcapi_functions_access_rights
79+
SET product_name = 'osparc'
80+
WHERE product_name IS NULL
81+
"""
82+
)
83+
84+
# Alter columns to set nullable=False
85+
op.alter_column(
86+
"funcapi_function_job_collections_access_rights",
87+
"product_name",
88+
existing_type=sa.String(),
89+
nullable=False,
90+
)
91+
op.alter_column(
92+
"funcapi_function_jobs_access_rights",
93+
"product_name",
94+
existing_type=sa.String(),
95+
nullable=False,
96+
)
97+
op.alter_column(
98+
"funcapi_functions_access_rights",
99+
"product_name",
100+
existing_type=sa.String(),
101+
nullable=False,
102+
)
103+
# ### end Alembic commands ###
104+
105+
106+
def downgrade():
107+
# ### commands auto generated by Alembic - please adjust! ###
108+
op.drop_constraint(
109+
"fk_func_access_to_products_product_name",
110+
"funcapi_functions_access_rights",
111+
type_="foreignkey",
112+
)
113+
op.drop_column("funcapi_functions_access_rights", "product_name")
114+
op.drop_constraint(
115+
"fk_func_access_to_products_product_name",
116+
"funcapi_function_jobs_access_rights",
117+
type_="foreignkey",
118+
)
119+
op.drop_column("funcapi_function_jobs_access_rights", "product_name")
120+
op.drop_constraint(
121+
"fk_func_access_to_products_product_name",
122+
"funcapi_function_job_collections_access_rights",
123+
type_="foreignkey",
124+
)
125+
op.drop_column("funcapi_function_job_collections_access_rights", "product_name")
126+
# ### end Alembic commands ###

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,20 @@
3232
onupdate=RefActions.CASCADE,
3333
ondelete=RefActions.CASCADE,
3434
),
35-
nullable=True,
35+
nullable=False,
3636
doc="Group id",
3737
),
38+
sa.Column(
39+
"product_name",
40+
sa.ForeignKey(
41+
"products.name",
42+
name="fk_func_access_to_products_product_name",
43+
onupdate=RefActions.CASCADE,
44+
ondelete=RefActions.CASCADE,
45+
),
46+
nullable=False,
47+
doc="Name of the product",
48+
),
3849
sa.Column(
3950
"read",
4051
sa.Boolean,
@@ -58,6 +69,7 @@
5869
sa.PrimaryKeyConstraint(
5970
"function_job_collection_uuid",
6071
"group_id",
72+
"product_name",
6173
name="pk_func_access_to_func_job_colls_group",
6274
),
6375
)

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
nullable=False,
3636
doc="Group id",
3737
),
38+
sa.Column(
39+
"product_name",
40+
sa.ForeignKey(
41+
"products.name",
42+
name="fk_func_access_to_products_product_name",
43+
onupdate=RefActions.CASCADE,
44+
ondelete=RefActions.CASCADE,
45+
),
46+
nullable=False,
47+
doc="Name of the product",
48+
),
3849
sa.Column(
3950
"read",
4051
sa.Boolean,
@@ -56,6 +67,9 @@
5667
column_created_datetime(),
5768
column_modified_datetime(),
5869
sa.PrimaryKeyConstraint(
59-
"function_job_uuid", "group_id", name="pk_func_access_to_func_jobs_group"
70+
"function_job_uuid",
71+
"group_id",
72+
"product_name",
73+
name="pk_func_access_to_func_jobs_group",
6074
),
6175
)

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
nullable=False,
3636
doc="Group id",
3737
),
38+
sa.Column(
39+
"product_name",
40+
sa.ForeignKey(
41+
"products.name",
42+
name="fk_func_access_to_products_product_name",
43+
onupdate=RefActions.CASCADE,
44+
ondelete=RefActions.CASCADE,
45+
),
46+
nullable=False,
47+
doc="Name of the product",
48+
),
3849
sa.Column(
3950
"read",
4051
sa.Boolean,
@@ -56,6 +67,6 @@
5667
column_created_datetime(),
5768
column_modified_datetime(),
5869
sa.PrimaryKeyConstraint(
59-
"function_uuid", "group_id", name="pk_func_access_to_func_group"
70+
"function_uuid", "group_id", "product_name", name="pk_func_access_to_func_group"
6071
),
6172
)

0 commit comments

Comments
 (0)