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

15 statements  

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

1"""Create concurrency_limit_v2 table 

2 

3Revision ID: 5b0bd3b41a23 

4Revises: 2dbcec43c857 

5Create Date: 2023-08-02 11:38:13.546075 

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 = "5b0bd3b41a23" 1a

16down_revision = "2dbcec43c857" 1a

17branch_labels = None 1a

18depends_on = None 1a

19 

20 

21def upgrade(): 1a

22 # ### commands auto generated by Alembic - please adjust! ### 

23 op.create_table( 1a

24 "concurrency_limit_v2", 

25 sa.Column( 

26 "id", 

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

28 server_default=sa.text( 

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

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

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

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

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

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

35 ), 

36 nullable=False, 

37 ), 

38 sa.Column( 

39 "created", 

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

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

42 nullable=False, 

43 ), 

44 sa.Column( 

45 "updated", 

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

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

48 nullable=False, 

49 ), 

50 sa.Column("active", sa.Boolean(), nullable=False), 

51 sa.Column("name", sa.String(), nullable=False), 

52 sa.Column("limit", sa.Integer(), nullable=False), 

53 sa.Column("active_slots", sa.Integer(), nullable=False), 

54 sa.Column("denied_slots", sa.Integer(), nullable=False), 

55 sa.Column("slot_decay_per_second", sa.Float(), nullable=True), 

56 sa.Column("avg_slot_occupancy_seconds", sa.Float(), nullable=False), 

57 sa.PrimaryKeyConstraint("id", name=op.f("pk_concurrency_limit_v2")), 

58 sa.UniqueConstraint("name", name=op.f("uq_concurrency_limit_v2__name")), 

59 ) 

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

61 batch_op.create_index( 1a

62 batch_op.f("ix_concurrency_limit_v2__updated"), ["updated"], unique=False 

63 ) 

64 

65 

66def downgrade(): 1a

67 with op.batch_alter_table("concurrency_limit_v2", schema=None) as batch_op: 

68 batch_op.drop_index(batch_op.f("ix_concurrency_limit_v2__updated")) 

69 

70 op.drop_table("concurrency_limit_v2")