|
4 | 4 |
|
5 | 5 | from ._common import ( |
6 | 6 | RefActions, |
| 7 | + column_created_by_user, |
7 | 8 | column_created_datetime, |
8 | 9 | column_modified_datetime, |
9 | 10 | register_modified_datetime_auto_update_trigger, |
10 | 11 | ) |
11 | 12 | from .base import metadata |
| 13 | +from .products import products # Import the products table |
12 | 14 | from .users import users |
13 | 15 |
|
14 | 16 | users_pre_registration_details = sa.Table( |
|
19 | 21 | # a row can be added in this table during pre-registration i.e. even before the `users` row exists. |
20 | 22 | # |
21 | 23 | 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 | + ), |
22 | 31 | sa.Column( |
23 | 32 | "user_id", |
24 | 33 | sa.Integer, |
|
35 | 44 | "pre_email", |
36 | 45 | sa.String(), |
37 | 46 | nullable=False, |
38 | | - unique=True, |
| 47 | + unique=False, # Same email could be used for different products |
39 | 48 | doc="Email of the user on pre-registration (copied to users.email upon registration)", |
40 | 49 | ), |
41 | 50 | sa.Column( |
|
61 | 70 | nullable=False, |
62 | 71 | server_default=sa.text("'PENDING'::account_request_status"), |
63 | 72 | ), |
| 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 | + ), |
64 | 86 | # Billable address columns: |
65 | 87 | sa.Column("institution", sa.String(), doc="the name of a company or university"), |
66 | 88 | sa.Column("address", sa.String()), |
|
75 | 97 | doc="Extra information provided in the form but still not defined as a column.", |
76 | 98 | ), |
77 | 99 | # 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), |
89 | 101 | column_created_datetime(timezone=False), |
90 | 102 | column_modified_datetime(timezone=False), |
91 | 103 | ) |
|
0 commit comments