11"""Add function access rights
22
3- Revision ID: d3982ce629b9
3+ Revision ID: d6b0f843ae3e
44Revises: 278daef7e99d
5- Create Date: 2025-05-28 06:29:49.436254 +00:00
5+ Create Date: 2025-05-28 10:50:43.486807 +00:00
66
77"""
88
1111from sqlalchemy .dialects import postgresql
1212
1313# revision identifiers, used by Alembic.
14- revision = "d3982ce629b9 "
14+ revision = "d6b0f843ae3e "
1515down_revision = "278daef7e99d"
1616branch_labels = None
1717depends_on = None
@@ -21,13 +21,11 @@ def upgrade():
2121 # ### commands auto generated by Alembic - please adjust! ###
2222 op .create_table (
2323 "funcapi_function_job_collections_access_rights" ,
24- sa .Column ("id" , sa .Integer (), autoincrement = True , nullable = False ),
2524 sa .Column (
2625 "function_job_collection_uuid" ,
2726 postgresql .UUID (as_uuid = True ),
2827 nullable = False ,
2928 ),
30- sa .Column ("user_id" , sa .BigInteger (), nullable = True ),
3129 sa .Column ("group_id" , sa .BigInteger (), nullable = True ),
3230 sa .Column ("read" , sa .Boolean (), nullable = True ),
3331 sa .Column ("write" , sa .Boolean (), nullable = True ),
@@ -44,10 +42,6 @@ def upgrade():
4442 server_default = sa .text ("now()" ),
4543 nullable = False ,
4644 ),
47- sa .CheckConstraint (
48- "user_id IS NULL AND group_id IS NOT NULL OR user_id IS NOT NULL AND group_id IS NULL" ,
49- name = "ck_user_or_group_exclusive" ,
50- ),
5145 sa .ForeignKeyConstraint (
5246 ["function_job_collection_uuid" ],
5347 ["funcapi_function_job_collections.uuid" ],
@@ -62,26 +56,16 @@ def upgrade():
6256 onupdate = "CASCADE" ,
6357 ondelete = "CASCADE" ,
6458 ),
65- sa .ForeignKeyConstraint (
66- ["user_id" ],
67- ["users.id" ],
68- name = "fk_func_access_to_users_user_id" ,
69- onupdate = "CASCADE" ,
70- ondelete = "CASCADE" ,
71- ),
72- sa .PrimaryKeyConstraint ("id" ),
73- sa .UniqueConstraint (
74- "user_id" ,
59+ sa .PrimaryKeyConstraint (
60+ "function_job_collection_uuid" ,
7561 "group_id" ,
76- name = "uq_funcapi_function_job_colls_access_rights_user_group " ,
62+ name = "pk_func_access_to_func_job_colls_group " ,
7763 ),
7864 )
7965 op .create_table (
80- "funcapi_function_jobs_access_rights" ,
81- sa .Column ("id" , sa .Integer (), autoincrement = True , nullable = False ),
82- sa .Column ("function_job_uuid" , postgresql .UUID (as_uuid = True ), nullable = False ),
83- sa .Column ("user_id" , sa .BigInteger (), nullable = True ),
84- sa .Column ("group_id" , sa .BigInteger (), nullable = True ),
66+ "funcapi_functions_access_rights" ,
67+ sa .Column ("function_uuid" , postgresql .UUID (as_uuid = True ), nullable = False ),
68+ sa .Column ("group_id" , sa .BigInteger (), nullable = False ),
8569 sa .Column ("read" , sa .Boolean (), nullable = True ),
8670 sa .Column ("write" , sa .Boolean (), nullable = True ),
8771 sa .Column ("execute" , sa .Boolean (), nullable = True ),
@@ -97,14 +81,10 @@ def upgrade():
9781 server_default = sa .text ("now()" ),
9882 nullable = False ,
9983 ),
100- sa .CheckConstraint (
101- "user_id IS NULL AND group_id IS NOT NULL OR user_id IS NOT NULL AND group_id IS NULL" ,
102- name = "ck_user_or_group_exclusive" ,
103- ),
10484 sa .ForeignKeyConstraint (
105- ["function_job_uuid " ],
106- ["funcapi_function_jobs .uuid" ],
107- name = "fk_func_access_to_func_jobs_to_func_job_uuid " ,
85+ ["function_uuid " ],
86+ ["funcapi_functions .uuid" ],
87+ name = "fk_func_access_to_func_to_func_uuid " ,
10888 onupdate = "CASCADE" ,
10989 ondelete = "CASCADE" ,
11090 ),
@@ -115,26 +95,14 @@ def upgrade():
11595 onupdate = "CASCADE" ,
11696 ondelete = "CASCADE" ,
11797 ),
118- sa .ForeignKeyConstraint (
119- ["user_id" ],
120- ["users.id" ],
121- name = "fk_func_access_to_users_user_id" ,
122- onupdate = "CASCADE" ,
123- ondelete = "CASCADE" ,
124- ),
125- sa .PrimaryKeyConstraint ("id" ),
126- sa .UniqueConstraint (
127- "user_id" ,
128- "group_id" ,
129- name = "uq_funcapi_function_jobs_access_rights_user_group" ,
98+ sa .PrimaryKeyConstraint (
99+ "function_uuid" , "group_id" , name = "pk_func_access_to_func_group"
130100 ),
131101 )
132102 op .create_table (
133- "funcapi_functions_access_rights" ,
134- sa .Column ("id" , sa .Integer (), autoincrement = True , nullable = False ),
135- sa .Column ("function_uuid" , postgresql .UUID (as_uuid = True ), nullable = False ),
136- sa .Column ("user_id" , sa .BigInteger (), nullable = True ),
137- sa .Column ("group_id" , sa .BigInteger (), nullable = True ),
103+ "funcapi_function_jobs_access_rights" ,
104+ sa .Column ("function_job_uuid" , postgresql .UUID (as_uuid = True ), nullable = False ),
105+ sa .Column ("group_id" , sa .BigInteger (), nullable = False ),
138106 sa .Column ("read" , sa .Boolean (), nullable = True ),
139107 sa .Column ("write" , sa .Boolean (), nullable = True ),
140108 sa .Column ("execute" , sa .Boolean (), nullable = True ),
@@ -150,14 +118,10 @@ def upgrade():
150118 server_default = sa .text ("now()" ),
151119 nullable = False ,
152120 ),
153- sa .CheckConstraint (
154- "user_id IS NULL AND group_id IS NOT NULL OR user_id IS NOT NULL AND group_id IS NULL" ,
155- name = "ck_user_or_group_exclusive" ,
156- ),
157121 sa .ForeignKeyConstraint (
158- ["function_uuid " ],
159- ["funcapi_functions .uuid" ],
160- name = "fk_func_access_to_func_to_func_uuid " ,
122+ ["function_job_uuid " ],
123+ ["funcapi_function_jobs .uuid" ],
124+ name = "fk_func_access_to_func_jobs_to_func_job_uuid " ,
161125 onupdate = "CASCADE" ,
162126 ondelete = "CASCADE" ,
163127 ),
@@ -168,24 +132,16 @@ def upgrade():
168132 onupdate = "CASCADE" ,
169133 ondelete = "CASCADE" ,
170134 ),
171- sa .ForeignKeyConstraint (
172- ["user_id" ],
173- ["users.id" ],
174- name = "fk_func_access_to_users_user_id" ,
175- onupdate = "CASCADE" ,
176- ondelete = "CASCADE" ,
177- ),
178- sa .PrimaryKeyConstraint ("id" ),
179- sa .UniqueConstraint (
180- "user_id" , "group_id" , name = "uq_funcapi_functions_access_rights_user_group"
135+ sa .PrimaryKeyConstraint (
136+ "function_job_uuid" , "group_id" , name = "pk_func_access_to_func_jobs_group"
181137 ),
182138 )
183139 # ### end Alembic commands ###
184140
185141
186142def downgrade ():
187143 # ### commands auto generated by Alembic - please adjust! ###
188- op .drop_table ("funcapi_functions_access_rights" )
189144 op .drop_table ("funcapi_function_jobs_access_rights" )
145+ op .drop_table ("funcapi_functions_access_rights" )
190146 op .drop_table ("funcapi_function_job_collections_access_rights" )
191147 # ### end Alembic commands ###
0 commit comments