Coverage for slidge/db/alembic/versions/bdf1c8b85ea3_spaces.py: 74%

19 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-08-18 04:30 +0000

1"""Spaces 

2 

3Revision ID: bdf1c8b85ea3 

4Revises: e365e04e9ac3 

5Create Date: 2026-05-19 20:20:35.452386 

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 = "bdf1c8b85ea3" 

16down_revision: str | None = "e365e04e9ac3" 

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

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

19 

20 

21def upgrade() -> None: 

22 op.create_table( 

23 "space", 

24 sa.Column("id", sa.Integer(), nullable=False), 

25 sa.Column("updated", sa.Boolean(), nullable=False), 

26 sa.Column("user_account_id", sa.Integer(), nullable=False), 

27 sa.Column("legacy_id", sa.String(), nullable=False), 

28 sa.Column("name", sa.String(), nullable=True), 

29 sa.Column("description", sa.String(), nullable=True), 

30 sa.Column("member_count", sa.Integer(), nullable=True), 

31 sa.Column("creator_pk", sa.Integer(), nullable=True), 

32 sa.ForeignKeyConstraint( 

33 ["creator_pk"], ["contact.id"], name=op.f("fk_space_creator_pk_contact") 

34 ), 

35 sa.ForeignKeyConstraint( 

36 ["user_account_id"], 

37 ["user_account.id"], 

38 name=op.f("fk_space_user_account_id_user_account"), 

39 ), 

40 sa.PrimaryKeyConstraint("id", name=op.f("pk_space")), 

41 sa.UniqueConstraint( 

42 "user_account_id", "legacy_id", name="uq_space_user_account_id_legacy_id" 

43 ), 

44 ) 

45 op.create_table( 

46 "space_owner_association", 

47 sa.Column("space_id", sa.Integer(), nullable=False), 

48 sa.Column("contact_id", sa.Integer(), nullable=False), 

49 sa.ForeignKeyConstraint( 

50 ["contact_id"], 

51 ["contact.id"], 

52 name=op.f("fk_space_owner_association_contact_id_contact"), 

53 ), 

54 sa.ForeignKeyConstraint( 

55 ["space_id"], 

56 ["space.id"], 

57 name=op.f("fk_space_owner_association_space_id_space"), 

58 ), 

59 sa.PrimaryKeyConstraint( 

60 "space_id", "contact_id", name=op.f("pk_space_owner_association") 

61 ), 

62 ) 

63 with op.batch_alter_table("room", schema=None) as batch_op: 

64 batch_op.add_column(sa.Column("space_id", sa.Integer(), nullable=True)) 

65 batch_op.create_foreign_key( 

66 batch_op.f("fk_room_space_id_space"), "space", ["space_id"], ["id"] 

67 ) 

68 

69 

70def downgrade() -> None: 

71 with op.batch_alter_table("room", schema=None) as batch_op: 

72 batch_op.drop_constraint( 

73 batch_op.f("fk_room_space_id_space"), type_="foreignkey" 

74 ) 

75 batch_op.drop_column("space_id") 

76 

77 op.drop_table("space_owner_association") 

78 op.drop_table("space")