Coverage for /usr/local/lib/python3.12/site-packages/prefect/server/database/_migrations/versions/sqlite/2023_03_20_184534_b9aafc3ab936_add_artifact_collection_table.py: 76%

17 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-12-05 11:21 +0000

1"""Adds artifact_collection table 

2 

3Revision ID: b9aafc3ab936 

4Revises: 1d7441c031d0 

5Create Date: 2023-03-20 18:45:34.438841 

6 

7""" 

8 

9import sqlalchemy as sa 1a

10from alembic import op 1a

11 

12import prefect 1a

13 

14# revision identifiers, used by Alembic. 

15revision = "b9aafc3ab936" 1a

16down_revision = "1d7441c031d0" 1a

17branch_labels = None 1a

18depends_on = None 1a

19 

20 

21def upgrade(): 1a

22 op.execute("PRAGMA foreign_keys=OFF") 1a

23 

24 op.create_table( 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( 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") 1a

65 

66 

67def downgrade(): 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")