-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18777 from jdavcs/dev_assoc_handling2
Backend handling of setting user-role, user-group, and group-role associations
- Loading branch information
Showing
26 changed files
with
2,083 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...l/migrations/alembic/versions_gxy/13fe10b8e35b_add_not_null_constraints_to_user_group_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Add not-null constraints to user_group_association | ||
Revision ID: 13fe10b8e35b | ||
Revises: 56ddf316dbd0 | ||
Create Date: 2024-09-09 21:26:26.032842 | ||
""" | ||
|
||
from alembic import op | ||
|
||
from galaxy.model.migrations.data_fixes.association_table_fixer import UserGroupAssociationNullFix | ||
from galaxy.model.migrations.util import ( | ||
alter_column, | ||
transaction, | ||
) | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "13fe10b8e35b" | ||
down_revision = "56ddf316dbd0" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
table_name = "user_group_association" | ||
|
||
|
||
def upgrade(): | ||
with transaction(): | ||
_remove_records_with_nulls() | ||
alter_column(table_name, "user_id", nullable=False) | ||
alter_column(table_name, "group_id", nullable=False) | ||
|
||
|
||
def downgrade(): | ||
with transaction(): | ||
alter_column(table_name, "user_id", nullable=True) | ||
alter_column(table_name, "group_id", nullable=True) | ||
|
||
|
||
def _remove_records_with_nulls(): | ||
"""Remove associations having null as user_id or group_id""" | ||
connection = op.get_bind() | ||
UserGroupAssociationNullFix(connection).run() |
42 changes: 42 additions & 0 deletions
42
...el/migrations/alembic/versions_gxy/1fdd615f2cdb_add_not_null_constraints_to_user_role_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Add not-null constraints to user_role_association | ||
Revision ID: 1fdd615f2cdb | ||
Revises: 349dd9d9aac9 | ||
Create Date: 2024-09-09 21:28:11.987054 | ||
""" | ||
|
||
from alembic import op | ||
|
||
from galaxy.model.migrations.data_fixes.association_table_fixer import UserRoleAssociationNullFix | ||
from galaxy.model.migrations.util import ( | ||
alter_column, | ||
transaction, | ||
) | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "1fdd615f2cdb" | ||
down_revision = "349dd9d9aac9" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
table_name = "user_role_association" | ||
|
||
|
||
def upgrade(): | ||
with transaction(): | ||
_remove_records_with_nulls() | ||
alter_column(table_name, "user_id", nullable=False) | ||
alter_column(table_name, "role_id", nullable=False) | ||
|
||
|
||
def downgrade(): | ||
with transaction(): | ||
alter_column(table_name, "user_id", nullable=True) | ||
alter_column(table_name, "role_id", nullable=True) | ||
|
||
|
||
def _remove_records_with_nulls(): | ||
"""Remove associations having null as user_id or role_id""" | ||
connection = op.get_bind() | ||
UserRoleAssociationNullFix(connection).run() |
42 changes: 42 additions & 0 deletions
42
...l/migrations/alembic/versions_gxy/25b092f7938b_add_not_null_constraints_to_group_role_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"""Add not-null constraints to group_role_association | ||
Revision ID: 25b092f7938b | ||
Revises: 9ef6431f3a4e | ||
Create Date: 2024-09-09 16:17:26.652865 | ||
""" | ||
|
||
from alembic import op | ||
|
||
from galaxy.model.migrations.data_fixes.association_table_fixer import GroupRoleAssociationNullFix | ||
from galaxy.model.migrations.util import ( | ||
alter_column, | ||
transaction, | ||
) | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "25b092f7938b" | ||
down_revision = "9ef6431f3a4e" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
table_name = "group_role_association" | ||
|
||
|
||
def upgrade(): | ||
with transaction(): | ||
_remove_records_with_nulls() | ||
alter_column(table_name, "group_id", nullable=True) | ||
alter_column(table_name, "role_id", nullable=False) | ||
|
||
|
||
def downgrade(): | ||
with transaction(): | ||
alter_column(table_name, "group_id", nullable=True) | ||
alter_column(table_name, "role_id", nullable=True) | ||
|
||
|
||
def _remove_records_with_nulls(): | ||
"""Remove associations having null as group_id or role_id""" | ||
connection = op.get_bind() | ||
GroupRoleAssociationNullFix(connection).run() |
45 changes: 45 additions & 0 deletions
45
.../migrations/alembic/versions_gxy/349dd9d9aac9_add_unique_constraint_to_user_role_assoc.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Add unique constraint to user_role_association | ||
Revision ID: 349dd9d9aac9 | ||
Revises: 1cf595475b58 | ||
Create Date: 2024-09-09 16:14:58.278850 | ||
""" | ||
|
||
from alembic import op | ||
|
||
from galaxy.model.migrations.data_fixes.association_table_fixer import UserRoleAssociationDuplicateFix | ||
from galaxy.model.migrations.util import ( | ||
create_unique_constraint, | ||
drop_constraint, | ||
transaction, | ||
) | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "349dd9d9aac9" | ||
down_revision = "1cf595475b58" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
table_name = "user_role_association" | ||
constraint_column_names = ["user_id", "role_id"] | ||
unique_constraint_name = ( | ||
"user_role_association_user_id_key" # This is what the model's naming convention will generate. | ||
) | ||
|
||
|
||
def upgrade(): | ||
with transaction(): | ||
_remove_duplicate_records() | ||
create_unique_constraint(unique_constraint_name, table_name, constraint_column_names) | ||
|
||
|
||
def downgrade(): | ||
with transaction(): | ||
drop_constraint(unique_constraint_name, table_name) | ||
|
||
|
||
def _remove_duplicate_records(): | ||
"""Remove duplicate associations""" | ||
connection = op.get_bind() | ||
UserRoleAssociationDuplicateFix(connection).run() |
45 changes: 45 additions & 0 deletions
45
...odel/migrations/alembic/versions_gxy/56ddf316dbd0_add_unique_constraint_to_user_group_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Add unique constraint to user_group_association | ||
Revision ID: 56ddf316dbd0 | ||
Revises: 1fdd615f2cdb | ||
Create Date: 2024-09-09 16:10:37.081834 | ||
""" | ||
|
||
from alembic import op | ||
|
||
from galaxy.model.migrations.data_fixes.association_table_fixer import UserGroupAssociationDuplicateFix | ||
from galaxy.model.migrations.util import ( | ||
create_unique_constraint, | ||
drop_constraint, | ||
transaction, | ||
) | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "56ddf316dbd0" | ||
down_revision = "1fdd615f2cdb" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
table_name = "user_group_association" | ||
constraint_column_names = ["user_id", "group_id"] | ||
unique_constraint_name = ( | ||
"user_group_association_user_id_key" # This is what the model's naming convention will generate. | ||
) | ||
|
||
|
||
def upgrade(): | ||
with transaction(): | ||
_remove_duplicate_records() | ||
create_unique_constraint(unique_constraint_name, table_name, constraint_column_names) | ||
|
||
|
||
def downgrade(): | ||
with transaction(): | ||
drop_constraint(unique_constraint_name, table_name) | ||
|
||
|
||
def _remove_duplicate_records(): | ||
"""Remove duplicate associations""" | ||
connection = op.get_bind() | ||
UserGroupAssociationDuplicateFix(connection).run() |
45 changes: 45 additions & 0 deletions
45
...odel/migrations/alembic/versions_gxy/9ef6431f3a4e_add_unique_constraint_to_group_role_.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Add unique constraint to group_role_association | ||
Revision ID: 9ef6431f3a4e | ||
Revises: 13fe10b8e35b | ||
Create Date: 2024-09-09 15:01:20.426534 | ||
""" | ||
|
||
from alembic import op | ||
|
||
from galaxy.model.migrations.data_fixes.association_table_fixer import GroupRoleAssociationDuplicateFix | ||
from galaxy.model.migrations.util import ( | ||
create_unique_constraint, | ||
drop_constraint, | ||
transaction, | ||
) | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "9ef6431f3a4e" | ||
down_revision = "13fe10b8e35b" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
table_name = "group_role_association" | ||
constraint_column_names = ["group_id", "role_id"] | ||
unique_constraint_name = ( | ||
"group_role_association_group_id_key" # This is what the model's naming convention will generate. | ||
) | ||
|
||
|
||
def upgrade(): | ||
with transaction(): | ||
_remove_duplicate_records() | ||
create_unique_constraint(unique_constraint_name, table_name, constraint_column_names) | ||
|
||
|
||
def downgrade(): | ||
with transaction(): | ||
drop_constraint(unique_constraint_name, table_name) | ||
|
||
|
||
def _remove_duplicate_records(): | ||
"""Remove duplicate associations""" | ||
connection = op.get_bind() | ||
GroupRoleAssociationDuplicateFix(connection).run() |
Oops, something went wrong.