Coverage for opt/mealie/lib/python3.12/site-packages/mealie/alembic/versions/2024-09-02-21.39.49_be568e39ffdf_added_household_recipe_lock_setting_and_.py: 80%

23 statements  

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

1"""added household recipe lock setting and household management user permission 

2 

3Revision ID: be568e39ffdf 

4Revises: feecc8ffb956 

5Create Date: 2024-09-02 21:39:49.210355 

6 

7""" 

8 

9from textwrap import dedent 1a

10 

11import sqlalchemy as sa 1a

12from alembic import op 1a

13 

14# revision identifiers, used by Alembic. 

15revision = "be568e39ffdf" 1a

16down_revision = "feecc8ffb956" 1a

17branch_labels: str | tuple[str, ...] | None = None 1a

18depends_on: str | tuple[str, ...] | None = None 1a

19 

20 

21def populate_defaults(): 1a

22 if op.get_context().dialect.name == "postgresql": 22 ↛ 23line 22 didn't jump to line 23 because the condition on line 22 was never true1a

23 TRUE = "TRUE" 

24 FALSE = "FALSE" 

25 else: 

26 TRUE = "1" 1a

27 FALSE = "0" 1a

28 

29 op.execute( 1a

30 dedent( 

31 f""" 

32 UPDATE household_preferences 

33 SET lock_recipe_edits_from_other_households = {TRUE} 

34 WHERE lock_recipe_edits_from_other_households IS NULL 

35 """ 

36 ) 

37 ) 

38 op.execute( 1a

39 dedent( 

40 f""" 

41 UPDATE users 

42 SET can_manage_household = {FALSE} 

43 WHERE can_manage_household IS NULL AND admin = {FALSE} 

44 """ 

45 ) 

46 ) 

47 op.execute( 1a

48 dedent( 

49 f""" 

50 UPDATE users 

51 SET can_manage_household = {TRUE} 

52 WHERE can_manage_household IS NULL AND admin = {TRUE} 

53 """ 

54 ) 

55 ) 

56 

57 

58def upgrade(): 1a

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

60 op.add_column( 1a

61 "household_preferences", 

62 sa.Column("lock_recipe_edits_from_other_households", sa.Boolean(), nullable=True), 

63 ) 

64 op.add_column("users", sa.Column("can_manage_household", sa.Boolean(), nullable=True)) 1a

65 # ### end Alembic commands ### 

66 

67 populate_defaults() 1a

68 

69 

70def downgrade(): 1a

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

72 op.drop_column("users", "can_manage_household") 

73 op.drop_column("household_preferences", "lock_recipe_edits_from_other_households") 

74 # ### end Alembic commands ###