1 """Create csrf_token toble
2
3 Revision ID: bacc60edce16
4 Revises: 342220764f0b
5 Create Date: 2024-03-13 11:13:16.487004
6
7 """
8
9 import sqlalchemy as sa 1 ctx 1a
10 from alembic import op 1 ctx 1a
11
12 import prefect 1 ctx 1a
13
14 # revision identifiers, used by Alembic.
15 revision = "bacc60edce16" 1 ctx 1a
16 down_revision = "342220764f0b" 1 ctx 1a
17 branch_labels = None 1 ctx 1a
18 depends_on = None 1 ctx 1a
19
20
21 def upgrade ( ) : 1 ctx 1a
22 op . create_table ( 1 ctx 1a
23 "csrf_token" ,
24 sa . Column ( "token" , sa . String ( ) , nullable = False ) ,
25 sa . Column ( "client" , sa . String ( ) , nullable = False ) ,
26 sa . Column (
27 "expiration" ,
28 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
29 nullable = False ,
30 ) ,
31 sa . Column (
32 "id" ,
33 prefect . server . utilities . database . UUID ( ) ,
34 server_default = sa . text (
35 "(\n (\n lower(hex(randomblob(4)))\n || '-'\n || lower(hex(randomblob(2)))\n || '-4'\n || substr(lower(hex(randomblob(2))),2)\n || '-'\n || substr('89ab',abs(random()) % 4 + 1, 1)\n || substr(lower(hex(randomblob(2))),2)\n || '-'\n || lower(hex(randomblob(6)))\n )\n )"
36 ) ,
37 nullable = False ,
38 ) ,
39 sa . Column (
40 "created" ,
41 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
42 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
43 nullable = False ,
44 ) ,
45 sa . Column (
46 "updated" ,
47 prefect . server . utilities . database . Timestamp ( timezone = True ) ,
48 server_default = sa . text ( "(strftime('%Y-%m-%d %H:%M:%f000', 'now'))" ) ,
49 nullable = False ,
50 ) ,
51 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_csrf_token" ) ) ,
52 sa . UniqueConstraint ( "client" , name = op . f ( "uq_csrf_token__client" ) ) ,
53 )
54 with op . batch_alter_table ( "csrf_token" , schema = None ) as batch_op : 1 ctx 1a
55 batch_op . create_index ( 1 ctx 1a
56 batch_op . f ( "ix_csrf_token__updated" ) , [ "updated" ] , unique = False
57 )
58
59
60 def downgrade ( ) : 1 ctx 1a
61 with op . batch_alter_table ( "csrf_token" , schema = None ) as batch_op :
62 batch_op . drop_index ( batch_op . f ( "ix_csrf_token__updated" ) )
63
64 op . drop_table ( "csrf_token" )