1
- """introduce officer tables
1
+ """create user session table
2
2
3
- Revision ID: 75857bf0c826
4
- Revises: 0db2c57ce969
5
- Create Date: 2024-06-03 06:36:40.642476
3
+ Revision ID: 166f3772fce7
4
+ Revises:
5
+ Create Date: 2024-02-23 00:58:50.320796
6
6
7
7
"""
8
8
9
9
from collections .abc import Sequence
10
+ from datetime import datetime
10
11
from typing import Union
11
12
12
13
import sqlalchemy as sa
13
14
from alembic import op
14
15
15
16
# revision identifiers, used by Alembic.
16
- revision : str = "75857bf0c826 "
17
- down_revision : str | None = "0db2c57ce969"
17
+ revision : str = "166f3772fce7 "
18
+ down_revision : str | None = None
18
19
branch_labels : str | Sequence [str ] | None = None
19
20
depends_on : str | Sequence [str ] | None = None
20
21
21
22
22
23
def upgrade () -> None :
23
- # drop all existing user session data
24
- # TODO: combine all past migrations into this one
25
- op .drop_table ("user_session" )
26
- op .create_table (
27
- "user_session" ,
28
- sa .Column ("session_id" , sa .String (512 ), nullable = False , primary_key = True ),
29
- sa .Column ("issue_time" , sa .DateTime , nullable = False ),
30
- sa .Column ("computing_id" , sa .String (32 ), nullable = False ),
31
- )
32
- op .create_unique_constraint ("unique__user_session__session_id" , "user_session" , ["session_id" ])
33
-
34
- # drop all existing site user data
35
- # TODO: combine all past migrations into this one
36
- op .drop_table ("site_user" )
37
24
op .create_table (
38
25
"site_user" ,
39
- sa .Column ("computing_id" , sa .String (32 ), nullable = False , primary_key = True ),
26
+ sa .Column ("computing_id" , sa .String (32 ), primary_key = True ),
27
+ sa .Column ("first_logged_in" , sa .DateTime , nullable = False , default = datetime (2024 , 6 , 16 )),
28
+ sa .Column ("last_logged_in" , sa .DateTime , nullable = False , default = datetime (2024 , 6 , 16 )),
40
29
)
41
-
42
30
op .create_table (
43
- "officer_info" ,
44
- sa .Column ("is_filled_in" , sa .Boolean (), nullable = False ),
45
- sa .Column ("legal_name" , sa .String (length = 128 ), nullable = False ),
46
- sa .Column ("discord_id" , sa .String (length = 18 ), nullable = True ),
47
- sa .Column ("discord_name" , sa .String (length = 32 ), nullable = True ),
48
- sa .Column ("discord_nickname" , sa .String (length = 32 ), nullable = True ),
49
- sa .Column ("computing_id" , sa .String (length = 32 ), nullable = False ),
50
- sa .Column ("phone_number" , sa .String (length = 24 ), nullable = True ),
51
- sa .Column ("github_username" , sa .String (length = 39 ), nullable = True ),
52
- sa .Column ("google_drive_email" , sa .Text (), nullable = True ),
53
- sa .PrimaryKeyConstraint ("computing_id" , name = "pk__officer_info__computing_id" ),
31
+ "user_session" ,
32
+ # NOTE: order is important; site_user must be created first!
33
+ sa .Column ("computing_id" , sa .String (32 ), sa .ForeignKey ("site_user.computing_id" ), primary_key = True ),
34
+ sa .Column ("issue_time" , sa .DateTime , nullable = False ),
35
+ sa .Column ("session_id" , sa .String (512 ), nullable = False , unique = True ),
54
36
)
37
+
55
38
op .create_table (
56
39
"officer_term" ,
57
- sa .Column ("id" , sa .Integer (), nullable = False ),
58
- sa .Column ("computing_id" , sa .String (length = 32 ), nullable = False ),
40
+ sa .Column ("id" , sa .Integer (), primary_key = True , autoincrement = True ),
41
+ sa .Column ("computing_id" , sa .String (length = 32 ), sa . ForeignKey ( "site_user.computing_id" ), nullable = False ),
59
42
sa .Column ("is_filled_in" , sa .Boolean (), nullable = False ),
60
43
sa .Column ("position" , sa .String (length = 128 ), nullable = False ),
61
44
sa .Column ("start_date" , sa .DateTime (), nullable = False ),
@@ -67,26 +50,23 @@ def upgrade() -> None:
67
50
sa .Column ("favourite_pl_1" , sa .String (length = 32 ), nullable = True ),
68
51
sa .Column ("biography" , sa .Text (), nullable = True ),
69
52
sa .Column ("photo_url" , sa .Text (), nullable = True ),
70
- sa .PrimaryKeyConstraint ("id" , name = "pk__officer_term__id" ),
71
53
)
72
-
54
+ op .create_table (
55
+ "officer_info" ,
56
+ sa .Column ("is_filled_in" , sa .Boolean (), nullable = False ),
57
+ sa .Column ("legal_name" , sa .String (length = 128 ), nullable = False ),
58
+ sa .Column ("discord_id" , sa .String (length = 18 ), nullable = True ),
59
+ sa .Column ("discord_name" , sa .String (length = 32 ), nullable = True ),
60
+ sa .Column ("discord_nickname" , sa .String (length = 32 ), nullable = True ),
61
+ sa .Column ("computing_id" , sa .String (length = 32 ), sa .ForeignKey ("user_session.computing_id" ), primary_key = True ),
62
+ sa .Column ("phone_number" , sa .String (length = 24 ), nullable = True ),
63
+ sa .Column ("github_username" , sa .String (length = 39 ), nullable = True ),
64
+ sa .Column ("google_drive_email" , sa .String (length = 256 ), nullable = True ),
65
+ )
73
66
74
67
def downgrade () -> None :
75
- op .drop_table ("officer_term" )
76
68
op .drop_table ("officer_info" )
77
-
78
- op .drop_table ("site_user" )
79
- op .create_table (
80
- "site_user" ,
81
- sa .Column ("id" , sa .Integer , primary_key = True , autoincrement = True ),
82
- sa .Column ("computing_id" , sa .String (32 ), nullable = False ),
83
- )
69
+ op .drop_table ("officer_term" )
84
70
85
71
op .drop_table ("user_session" )
86
- op .create_table (
87
- "user_session" ,
88
- sa .Column ("id" , sa .Integer , primary_key = True , autoincrement = True ),
89
- sa .Column ("issue_time" , sa .DateTime , nullable = False ),
90
- sa .Column ("session_id" , sa .String (512 ), nullable = False ),
91
- sa .Column ("computing_id" , sa .String (32 ), nullable = False ),
92
- )
72
+ op .drop_table ("site_user" )
0 commit comments