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

19 statements  

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

1"""Add `trigger_id` to the unique index for `automation_bucket` 

2 

3Revision ID: 2b6c2b548f95 

4Revises: cc510aec4689 

5Create Date: 2024-04-09 13:18:32.041914 

6 

7""" 

8 

9import sqlalchemy as sa 1a

10from alembic import op 1a

11 

12import prefect.server.utilities.database 1a

13 

14# revision identifiers, used by Alembic. 

15revision = "2b6c2b548f95" 1a

16down_revision = "cc510aec4689" 1a

17branch_labels = None 1a

18depends_on = None 1a

19 

20 

21def upgrade(): 1a

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

23 batch_op.alter_column( 1a

24 "trigger_id", 

25 existing_type=prefect.server.utilities.database.UUID(), 

26 nullable=False, 

27 ) 

28 batch_op.alter_column( 1a

29 "triggered_at", 

30 existing_type=sa.TIMESTAMP(), 

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

32 nullable=True, 

33 ) 

34 batch_op.drop_index("uq_automation_bucket__automation_id__bucketing_key") 1a

35 batch_op.create_index( 1a

36 "uq_automation_bucket__automation_id__trigger_id__bucketing_key", 

37 ["automation_id", "trigger_id", "bucketing_key"], 

38 unique=True, 

39 ) 

40 

41 

42def downgrade(): 1a

43 with op.batch_alter_table("automation_bucket", schema=None) as batch_op: 

44 batch_op.drop_index( 

45 "uq_automation_bucket__automation_id__trigger_id__bucketing_key" 

46 ) 

47 batch_op.create_index( 

48 "uq_automation_bucket__automation_id__bucketing_key", 

49 ["automation_id", "bucketing_key"], 

50 unique=1, 

51 ) 

52 batch_op.alter_column( 

53 "trigger_id", 

54 existing_type=prefect.server.utilities.database.UUID(), 

55 nullable=True, 

56 ) 

57 batch_op.alter_column( 

58 "triggered_at", 

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

60 type_=sa.TIMESTAMP(), 

61 nullable=False, 

62 )