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

21 statements  

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

1"""Automation event follower 

2 

3Revision ID: cc510aec4689 

4Revises: 8644a9595a08 

5Create Date: 2024-04-09 12:57:12.420482 

6 

7""" 

8 

9import sqlalchemy as sa 1a

10from alembic import op 1a

11 

12import prefect 1a

13import prefect.server.utilities.database 1a

14from prefect.server.events.schemas.events import ReceivedEvent 1a

15 

16# revision identifiers, used by Alembic. 

17revision = "cc510aec4689" 1a

18down_revision = "8644a9595a08" 1a

19branch_labels = None 1a

20depends_on = None 1a

21 

22 

23def upgrade(): 1a

24 op.create_table( 1a

25 "automation_event_follower", 

26 sa.Column( 

27 "leader_event_id", prefect.server.utilities.database.UUID(), nullable=False 

28 ), 

29 sa.Column( 

30 "follower_event_id", 

31 prefect.server.utilities.database.UUID(), 

32 nullable=False, 

33 ), 

34 sa.Column( 

35 "received", 

36 prefect.server.utilities.database.Timestamp(timezone=True), 

37 nullable=False, 

38 ), 

39 sa.Column( 

40 "follower", 

41 prefect.server.utilities.database.Pydantic(ReceivedEvent), 

42 nullable=False, 

43 ), 

44 sa.Column( 

45 "id", 

46 prefect.server.utilities.database.UUID(), 

47 server_default=sa.text( 

48 "(\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 )" 

49 ), 

50 nullable=False, 

51 ), 

52 sa.Column( 

53 "created", 

54 prefect.server.utilities.database.Timestamp(timezone=True), 

55 server_default=sa.text("(strftime('%Y-%m-%d %H:%M:%f000', 'now'))"), 

56 nullable=False, 

57 ), 

58 sa.Column( 

59 "updated", 

60 prefect.server.utilities.database.Timestamp(timezone=True), 

61 server_default=sa.text("(strftime('%Y-%m-%d %H:%M:%f000', 'now'))"), 

62 nullable=False, 

63 ), 

64 sa.PrimaryKeyConstraint("id", name=op.f("pk_automation_event_follower")), 

65 sa.UniqueConstraint( 

66 "follower_event_id", 

67 name=op.f("uq_automation_event_follower__follower_event_id"), 

68 ), 

69 ) 

70 with op.batch_alter_table("automation_event_follower", schema=None) as batch_op: 1a

71 batch_op.create_index( 1a

72 batch_op.f("ix_automation_event_follower__leader_event_id"), 

73 ["leader_event_id"], 

74 unique=False, 

75 ) 

76 batch_op.create_index( 1a

77 batch_op.f("ix_automation_event_follower__received"), 

78 ["received"], 

79 unique=False, 

80 ) 

81 batch_op.create_index( 1a

82 batch_op.f("ix_automation_event_follower__updated"), 

83 ["updated"], 

84 unique=False, 

85 ) 

86 

87 

88def downgrade(): 1a

89 with op.batch_alter_table("automation_event_follower", schema=None) as batch_op: 

90 batch_op.drop_index(batch_op.f("ix_automation_event_follower__updated")) 

91 batch_op.drop_index(batch_op.f("ix_automation_event_follower__received")) 

92 batch_op.drop_index(batch_op.f("ix_automation_event_follower__leader_event_id")) 

93 

94 op.drop_table("automation_event_follower")