Coverage for slidge/db/alembic/versions/4f24f40edb4e_participant_dedup.py: 96%

24 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-11-10 12:26 +0000

1"""participant dedup 

2 

3Revision ID: 4f24f40edb4e 

4Revises: 85d6e2a9ee7f 

5Create Date: 2026-10-26 18:55:40.369485 

6 

7""" 

8 

9from collections.abc import Sequence 

10 

11import sqlalchemy as sa 

12from alembic import op 

13 

14# revision identifiers, used by Alembic. 

15revision: str = "4f24f40edb4e" 

16down_revision: str | None = "85d6e2a9ee7f" 

17branch_labels: str | Sequence[str] | None = None 

18depends_on: str | Sequence[str] | None = None 

19 

20 

21def upgrade() -> None: 

22 with op.batch_alter_table("participant", schema=None) as batch_op: 

23 batch_op.drop_constraint( 

24 batch_op.f("uq_participant_room_id_resource"), type_="unique" 

25 ) 

26 batch_op.drop_column("nickname_no_illegal") 

27 

28 batch_op.alter_column( 

29 "affiliation", new_column_name="_affiliation", nullable=True 

30 ) 

31 batch_op.alter_column("role", new_column_name="_role", nullable=True) 

32 batch_op.alter_column("resource", new_column_name="_resource", nullable=True) 

33 batch_op.alter_column("occupant_id", existing_type=sa.VARCHAR(), nullable=True) 

34 

35 with op.batch_alter_table("participant", schema=None) as batch_op: 

36 batch_op.create_unique_constraint( 

37 "uq_participant_room_id__resource", ["room_id", "_resource"] 

38 ) 

39 

40 op.execute("UPDATE participant SET _resource = NULL WHERE _resource = nickname") 

41 op.execute("UPDATE participant SET _role = NULL WHERE _role = 'participant'") 

42 op.execute( 

43 "UPDATE participant SET _affiliation = NULL WHERE _affiliation = 'member'" 

44 ) 

45 op.execute( 

46 "UPDATE participant SET occupant_id = NULL WHERE occupant_id LIKE '%/slidge'" 

47 ) 

48 op.execute( 

49 "UPDATE participant SET occupant_id = NULL WHERE occupant_id = 'slidge-user'" 

50 ) 

51 

52 

53def downgrade() -> None: 

54 raise RuntimeError("downgrades are not supported")