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

26 statements  

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

1"""Clean up work queue migration 

2 

3Revision ID: bfe42b7090d6 

4Revises: 1678f2fb8b33 

5Create Date: 2023-01-31 13:24:09.241377 

6 

7""" 

8 

9import sqlalchemy as sa 1a

10from alembic import op 1a

11 

12# revision identifiers, used by Alembic. 

13revision = "bfe42b7090d6" 1a

14down_revision = "1678f2fb8b33" 1a

15branch_labels = None 1a

16depends_on = None 1a

17 

18 

19def upgrade(): 1a

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

21 

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

23 batch_op.drop_index("ix_work_pool_queue__updated") 1a

24 batch_op.drop_index("ix_work_pool_queue__work_pool_id") 1a

25 batch_op.drop_index("ix_work_pool_queue__work_pool_id_priority") 1a

26 

27 op.drop_table("work_pool_queue") 1a

28 

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

30 batch_op.alter_column( 1a

31 "work_pool_id", existing_type=sa.CHAR(length=36), nullable=False 

32 ) 

33 

34 op.execute("PRAGMA foreign_keys=ON") 1a

35 

36 

37def downgrade(): 1a

38 op.execute("PRAGMA foreign_keys=OFF") 

39 

40 with op.batch_alter_table("work_queue", schema=None) as batch_op: 

41 batch_op.alter_column( 

42 "work_pool_id", existing_type=sa.CHAR(length=36), nullable=True 

43 ) 

44 

45 op.create_table( 

46 "work_pool_queue", 

47 sa.Column( 

48 "id", 

49 sa.CHAR(length=36), 

50 server_default=sa.text( 

51 "(((\n lower(hex(randomblob(4)))\n || '-'\n ||" 

52 " lower(hex(randomblob(2)))\n || '-4'\n ||" 

53 " substr(lower(hex(randomblob(2))),2)\n || '-'\n ||" 

54 " substr('89ab',abs(random()) % 4 + 1, 1)\n ||" 

55 " substr(lower(hex(randomblob(2))),2)\n || '-'\n ||" 

56 " lower(hex(randomblob(6)))\n )))" 

57 ), 

58 nullable=False, 

59 ), 

60 sa.Column( 

61 "created", 

62 sa.DATETIME(), 

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

64 nullable=False, 

65 ), 

66 sa.Column( 

67 "updated", 

68 sa.DATETIME(), 

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

70 nullable=False, 

71 ), 

72 sa.Column("name", sa.VARCHAR(), nullable=False), 

73 sa.Column("description", sa.VARCHAR(), nullable=True), 

74 sa.Column( 

75 "is_paused", sa.BOOLEAN(), server_default=sa.text("'0'"), nullable=False 

76 ), 

77 sa.Column("concurrency_limit", sa.INTEGER(), nullable=True), 

78 sa.Column("priority", sa.INTEGER(), nullable=False), 

79 sa.Column("work_pool_id", sa.CHAR(length=36), nullable=False), 

80 sa.ForeignKeyConstraint( 

81 ["work_pool_id"], 

82 ["work_pool.id"], 

83 name="fk_work_pool_queue__work_pool_id__work_pool", 

84 ondelete="CASCADE", 

85 ), 

86 sa.PrimaryKeyConstraint("id", name="pk_work_pool_queue"), 

87 sa.UniqueConstraint( 

88 "work_pool_id", "name", name="uq_work_pool_queue__work_pool_id_name" 

89 ), 

90 ) 

91 with op.batch_alter_table("work_pool_queue", schema=None) as batch_op: 

92 batch_op.create_index( 

93 "ix_work_pool_queue__work_pool_id_priority", 

94 ["work_pool_id", "priority"], 

95 unique=False, 

96 ) 

97 batch_op.create_index( 

98 "ix_work_pool_queue__work_pool_id", ["work_pool_id"], unique=False 

99 ) 

100 batch_op.create_index("ix_work_pool_queue__updated", ["updated"], unique=False) 

101 

102 op.execute("PRAGMA foreign_keys=ON")