1 """Adds artifact_collection table
2
3 Revision ID: b9aafc3ab936
4 Revises: 1d7441c031d0
5 Create Date: 2023-03-20 18:45:34.438841
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 = "b9aafc3ab936" 1 ctx 1a
16 down_revision = "1d7441c031d0" 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 . execute ( "PRAGMA foreign_keys=OFF" ) 1 ctx 1a
23
24 op . create_table ( 1 ctx 1a
25 "artifact_collection" ,
26 sa . Column (
27 "id" ,
28 prefect . server . utilities . database . UUID ( ) ,
29 server_default = sa . text (
30 "(\n (\n lower(hex(randomblob(4)))\n || '-'\n "
31 " || lower(hex(randomblob(2)))\n || '-4'\n ||"
32 " substr(lower(hex(randomblob(2))),2)\n || '-'\n ||"
33 " substr('89ab',abs(random()) % 4 + 1, 1)\n ||"
34 " substr(lower(hex(randomblob(2))),2)\n || '-'\n ||"
35 " 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 . Column ( "key" , sa . String ( ) , nullable = False ) ,
52 sa . Column (
53 "latest_id" , prefect . server . utilities . database . UUID ( ) , nullable = False
54 ) ,
55 sa . PrimaryKeyConstraint ( "id" , name = op . f ( "pk_artifact_collection" ) ) ,
56 sa . UniqueConstraint ( "key" , name = op . f ( "uq_artifact_collection__key" ) ) ,
57 )
58 op . create_index ( 1 ctx 1a
59 op . f ( "ix_artifact_collection__key_latest_id" ) ,
60 "artifact_collection" ,
61 [ "key" , "latest_id" ] ,
62 )
63
64 op . execute ( "PRAGMA foreign_keys=ON" ) 1 ctx 1a
65
66
67 def downgrade ( ) : 1 ctx 1a
68 op . execute ( "PRAGMA foreign_keys=OFF" )
69
70 op . drop_index (
71 op . f ( "ix_artifact_collection__key_latest_id" ) , table_name = "artifact_collection"
72 )
73
74 op . drop_table ( "artifact_collection" )
75
76 op . execute ( "PRAGMA foreign_keys=ON" )