Coverage for /usr/local/lib/python3.12/site-packages/prefect/server/database/_migrations/versions/sqlite/2025_02_05_152431_07ecde74d74d_add_slug_column_to_deployment_schedule.py: 70%

20 statements  

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

1"""Add slug column to deployment_schedule 

2 

3Revision ID: 07ecde74d74d 

4Revises: 67f886da208e 

5Create Date: 2025-02-05 15:24:31.503016 

6 

7""" 

8 

9import sqlalchemy as sa 1a

10from alembic import op 1a

11 

12# revision identifiers, used by Alembic. 

13revision = "07ecde74d74d" 1a

14down_revision = "67f886da208e" 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("deployment_schedule", schema=None) as batch_op: 1a

23 batch_op.add_column( 1a

24 sa.Column("slug", sa.String, nullable=True), 

25 ) 

26 batch_op.create_index( 1a

27 "ix_deployment_schedule__slug", 

28 ["slug"], 

29 unique=False, 

30 if_not_exists=True, 

31 ) 

32 

33 op.execute( 1a

34 """ 

35 CREATE UNIQUE INDEX IF NOT EXISTS 

36 ix_deployment_schedule__deployment_id__slug 

37 ON deployment_schedule(deployment_id, slug) 

38 WHERE slug IS NOT NULL; 

39 """ 

40 ) 

41 

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

43 

44 

45def downgrade(): 1a

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

47 with op.batch_alter_table("deployment_schedule", schema=None) as batch_op: 

48 batch_op.drop_index(batch_op.f("ix_deployment_schedule__deployment_id__slug")) 

49 batch_op.drop_index("ix_deployment_schedule__slug") 

50 batch_op.drop_column("slug") 

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