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

31 statements  

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

1"""Add block_spec table 

2 

3Revision ID: e1ff4973a9eb 

4Revises: 4c4a6a138053 

5Create Date: 2022-02-20 10:36:10.457956 

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

16down_revision = "4c4a6a138053" 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 "block_spec", 

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("name", sa.String(), nullable=False), 

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

52 sa.Column("type", sa.String(), nullable=True), 

53 sa.Column( 

54 "fields", 

55 prefect.server.utilities.database.JSON(astext_type=sa.Text()), 

56 server_default="{}", 

57 nullable=False, 

58 ), 

59 sa.PrimaryKeyConstraint("id", name=op.f("pk_block_spec")), 

60 ) 

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

62 batch_op.create_index( 1a

63 batch_op.f("ix_block_spec__updated"), ["updated"], unique=False 

64 ) 

65 batch_op.create_index( 1a

66 "uq_block_spec__name_version", ["name", "version"], unique=True 

67 ) 

68 batch_op.create_index(batch_op.f("ix_block_spec__type"), ["type"], unique=False) 1a

69 

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

71 batch_op.drop_index("ix_block_data__name") 1a

72 batch_op.drop_index("ix_block_data__updated") 1a

73 batch_op.create_index(batch_op.f("ix_block__name"), ["name"], unique=False) 1a

74 batch_op.create_index( 1a

75 batch_op.f("ix_block__updated"), ["updated"], unique=False 

76 ) 

77 batch_op.create_unique_constraint(batch_op.f("uq_block__name"), ["name"]) 1a

78 

79 # ### end Alembic commands ### 

80 

81 

82def downgrade(): 1a

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

84 with op.batch_alter_table("block", schema=None) as batch_op: 

85 batch_op.drop_constraint(batch_op.f("uq_block__name"), type_="unique") 

86 batch_op.drop_index(batch_op.f("ix_block__updated")) 

87 batch_op.drop_index(batch_op.f("ix_block__name")) 

88 batch_op.create_index("ix_block_data__updated", ["updated"], unique=False) 

89 batch_op.create_index("ix_block_data__name", ["name"], unique=False) 

90 

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

92 batch_op.drop_index("uq_block_spec__name_version") 

93 batch_op.drop_index(batch_op.f("ix_block_spec__updated")) 

94 batch_op.drop_index(batch_op.f("ix_block_spec__type")) 

95 

96 op.drop_table("block_spec") 

97 # ### end Alembic commands ###