1 """added household recipe lock setting and household management user permission
2
3 Revision ID: be568e39ffdf
4 Revises: feecc8ffb956
5 Create Date: 2024-09-02 21:39:49.210355
6
7 """
8
9 from textwrap import dedent 1 ctx 1a
10
11 import sqlalchemy as sa 1 ctx 1a
12 from alembic import op 1 ctx 1a
13
14 # revision identifiers, used by Alembic.
15 revision = "be568e39ffdf" 1 ctx 1a
16 down_revision = "feecc8ffb956" 1 ctx 1a
17 branch_labels : str | tuple [ str , ... ] | None = None 1 ctx 1a
18 depends_on : str | tuple [ str , ... ] | None = None 1 ctx 1a
19
20
21 def populate_defaults ( ) : 1 ctx 1a
22 if op . get_context ( ) . dialect . name == "postgresql" : 22 ↛ 23 line 22 didn't jump to line 23 because the condition on line 22 was never true 1 ctx 1a
23 TRUE = "TRUE"
24 FALSE = "FALSE"
25 else :
26 TRUE = "1" 1 ctx 1a
27 FALSE = "0" 1 ctx 1a
28
29 op . execute ( 1 ctx 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 ( 1 ctx 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 ( 1 ctx 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
58 def upgrade ( ) : 1 ctx 1a
59 # ### commands auto generated by Alembic - please adjust! ###
60 op . add_column ( 1 ctx 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 ) ) 1 ctx 1a
65 # ### end Alembic commands ###
66
67 populate_defaults ( ) 1 ctx 1a
68
69
70 def downgrade ( ) : 1 ctx 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 ###