Skip to content

Commit 6513314

Browse files
committed
feat: enhance pre-registration details with product name and foreign key support
1 parent b3f0181 commit 6513314

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

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

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
from ._common import (
66
RefActions,
7+
column_created_by_user,
78
column_created_datetime,
89
column_modified_datetime,
910
register_modified_datetime_auto_update_trigger,
1011
)
1112
from .base import metadata
13+
from .products import products # Import the products table
1214
from .users import users
1315

1416
users_pre_registration_details = sa.Table(
@@ -19,6 +21,13 @@
1921
# a row can be added in this table during pre-registration i.e. even before the `users` row exists.
2022
#
2123
metadata,
24+
sa.Column(
25+
"id",
26+
sa.BigInteger,
27+
sa.Identity(start=1, cycle=False),
28+
primary_key=True,
29+
doc="Primary key for the pre-registration entry",
30+
),
2231
sa.Column(
2332
"user_id",
2433
sa.Integer,
@@ -35,7 +44,7 @@
3544
"pre_email",
3645
sa.String(),
3746
nullable=False,
38-
unique=True,
47+
unique=False, # Same email could be used for different products
3948
doc="Email of the user on pre-registration (copied to users.email upon registration)",
4049
),
4150
sa.Column(
@@ -61,6 +70,19 @@
6170
nullable=False,
6271
server_default=sa.text("'PENDING'::account_request_status"),
6372
),
73+
# Product the user is requesting access to
74+
sa.Column(
75+
"product_name",
76+
sa.String,
77+
sa.ForeignKey(
78+
products.c.name,
79+
onupdate=RefActions.CASCADE,
80+
ondelete=RefActions.SET_NULL,
81+
name="fk_users_pre_registration_details_product_name",
82+
),
83+
nullable=True,
84+
doc="Product that the user is requesting an account for",
85+
),
6486
# Billable address columns:
6587
sa.Column("institution", sa.String(), doc="the name of a company or university"),
6688
sa.Column("address", sa.String()),
@@ -75,17 +97,7 @@
7597
doc="Extra information provided in the form but still not defined as a column.",
7698
),
7799
# Other related users
78-
sa.Column(
79-
"created_by",
80-
sa.Integer,
81-
sa.ForeignKey(
82-
users.c.id,
83-
onupdate=RefActions.CASCADE,
84-
ondelete=RefActions.SET_NULL,
85-
),
86-
nullable=True,
87-
doc="PO user that issued this pre-registration",
88-
),
100+
column_created_by_user(users_table=users, required=False),
89101
column_created_datetime(timezone=False),
90102
column_modified_datetime(timezone=False),
91103
)

packages/pytest-simcore/src/pytest_simcore/helpers/faker_factories.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,10 @@ def random_user(
8585
def random_pre_registration_details(
8686
fake: Faker = DEFAULT_FAKER,
8787
*,
88+
# foreign keys
8889
user_id: int | None = None,
8990
created_by: int | None = None,
91+
product_name: str | None = None,
9092
**overrides,
9193
):
9294
from simcore_postgres_database.models.users_details import (
@@ -117,6 +119,7 @@ def random_pre_registration_details(
117119
"eula": True,
118120
"ipinfo": {"x-real-ip": "127.0.0.1"},
119121
},
122+
"product_name": product_name,
120123
"created_by": created_by, # user id
121124
}
122125

0 commit comments

Comments
 (0)