@@ -59,20 +59,37 @@ class UserStatus(Enum):
5959 """
6060 pending: user registered but not confirmed
6161 active: user is confirmed and can use the platform
62+ expired: user is not authorized because it expired after a trial period
6263 banned: user is not authorized
6364 """
6465
6566 CONFIRMATION_PENDING = "PENDING"
6667 ACTIVE = "ACTIVE"
68+ EXPIRED = "EXPIRED"
6769 BANNED = "BANNED"
6870
6971
7072users = sa .Table (
7173 "users" ,
7274 metadata ,
73- sa .Column ("id" , sa .BigInteger , nullable = False ),
74- sa .Column ("name" , sa .String , nullable = False ),
75- sa .Column ("email" , sa .String , nullable = False ),
75+ sa .Column (
76+ "id" ,
77+ sa .BigInteger ,
78+ nullable = False ,
79+ doc = "Primary key for user identifier" ,
80+ ),
81+ sa .Column (
82+ "name" ,
83+ sa .String ,
84+ nullable = False ,
85+ doc = "Display name. NOTE: this is NOT a user name since uniqueness is NOT guaranteed" ,
86+ ),
87+ sa .Column (
88+ "email" ,
89+ sa .String ,
90+ nullable = False ,
91+ doc = "User email is used as username since it is a unique human-readable identifier" ,
92+ ),
7693 sa .Column (
7794 "phone" ,
7895 sa .String ,
@@ -89,30 +106,57 @@ class UserStatus(Enum):
89106 onupdate = "CASCADE" ,
90107 ondelete = "RESTRICT" ,
91108 ),
109+ doc = "User's group ID" ,
92110 ),
93111 sa .Column (
94112 "status" ,
95113 sa .Enum (UserStatus ),
96114 nullable = False ,
97115 default = UserStatus .CONFIRMATION_PENDING ,
116+ doc = "Status of the user account. SEE UserStatus" ,
117+ ),
118+ sa .Column (
119+ "role" ,
120+ sa .Enum (UserRole ),
121+ nullable = False ,
122+ default = UserRole .USER ,
123+ doc = "Use for role-base authorization" ,
124+ ),
125+ sa .Column (
126+ "created_at" ,
127+ sa .DateTime (),
128+ nullable = False ,
129+ server_default = func .now (),
130+ doc = "Registration timestamp" ,
98131 ),
99- sa .Column ("role" , sa .Enum (UserRole ), nullable = False , default = UserRole .USER ),
100- sa .Column ("created_at" , sa .DateTime (), nullable = False , server_default = func .now ()),
101132 sa .Column (
102133 "modified" ,
103134 sa .DateTime (),
104135 nullable = False ,
105136 server_default = func .now (),
106137 onupdate = func .now (), # this will auto-update on modification
138+ doc = "Last modification timestamp" ,
139+ ),
140+ sa .Column (
141+ "expires_at" ,
142+ sa .DateTime (),
143+ nullable = True ,
144+ doc = "Sets the expiration date for trial accounts."
145+ "If set to NULL then the account does not expire." ,
146+ ),
147+ sa .Column (
148+ "created_ip" ,
149+ sa .String (),
150+ nullable = True ,
151+ doc = "User IP from which use was created" ,
107152 ),
108- sa .Column ("created_ip" , sa .String (), nullable = True ),
109- #
153+ # ---------------------------
110154 sa .PrimaryKeyConstraint ("id" , name = "user_pkey" ),
111155 sa .UniqueConstraint ("email" , name = "user_login_key" ),
112156 sa .UniqueConstraint (
113157 "phone" ,
114158 name = "user_phone_unique_constraint" ,
115- # cannot use same phone for two users
159+ # NOTE: that cannot use same phone for two user accounts
116160 ),
117161)
118162
0 commit comments