-
Notifications
You must be signed in to change notification settings - Fork 0
Add: Denormalization: delete ace attributeTypeId, add attribute_type_name #975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
milov-dmitriy
wants to merge
7
commits into
feature/subtask_1258_add_ldap_display_name
Choose a base branch
from
feature/subsubtask_1258_denormalization_delete_ace_attr_type_id
base: feature/subtask_1258_add_ldap_display_name
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f0f93e5
draft
milov-dmitriy 7cb750e
fix: sql request subsubtask_1258
milov-dmitriy ec627ea
fix: naming subsubtask_1258
milov-dmitriy d2f43c7
fix: migration subsubtask_1258
milov-dmitriy adb0551
tests: fix subsubtask_1258
milov-dmitriy 5d9d942
fix: migrations collision: models vs DB-tables subsubtask_1258
milov-dmitriy ae9c373
fix: delete duplicate attributes for schema dirs subsubtask_1258
milov-dmitriy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
app/alembic/versions/1b71cafba681_replace_attributeTypeId.py
This file contains hidden or 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,88 @@ | ||
| """Delete attributeTypeId add attribute_type_name from AccessControlEntries. | ||
| Revision ID: 1b71cafba681 | ||
| Revises: 708b01eaf025 | ||
| Create Date: 2026-03-24 16:28:49.116712 | ||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
| from dishka import AsyncContainer | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: None | str = "1b71cafba681" | ||
| down_revision: None | str = "708b01eaf025" | ||
| branch_labels: None | list[str] = None | ||
| depends_on: None | list[str] = None | ||
|
|
||
|
|
||
| def upgrade(container: AsyncContainer) -> None: # noqa: ARG001 | ||
| """Upgrade.""" | ||
| op.add_column( | ||
| "AccessControlEntries", | ||
| sa.Column("attribute_type_name", sa.String(), nullable=True), | ||
| ) | ||
| op.execute( | ||
| sa.text( | ||
| """ | ||
| UPDATE "AccessControlEntries" AS ace | ||
| SET attribute_type_name = directory.name | ||
| FROM "Directory" AS directory | ||
| WHERE ace."attributeTypeId" = directory.id | ||
| """, | ||
| ), | ||
| ) | ||
milov-dmitriy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| op.drop_index( | ||
| op.f("idx_ace_attribute_type_id"), | ||
| table_name="AccessControlEntries", | ||
| postgresql_using="hash", | ||
milov-dmitriy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| op.drop_constraint( | ||
| op.f("AccessControlEntries_directoryAttributeTypeId_fkey"), | ||
| "AccessControlEntries", | ||
| type_="foreignkey", | ||
| ) | ||
| op.drop_column("AccessControlEntries", "attributeTypeId") | ||
|
|
||
|
|
||
| def downgrade(container: AsyncContainer) -> None: # noqa: ARG001 | ||
| """Downgrade.""" | ||
| op.add_column( | ||
| "AccessControlEntries", | ||
| sa.Column( | ||
| "attributeTypeId", | ||
| sa.INTEGER(), | ||
| autoincrement=False, | ||
| nullable=True, | ||
| ), | ||
| ) | ||
|
|
||
| op.execute( | ||
| sa.text( | ||
| """ | ||
| UPDATE "AccessControlEntries" AS ace | ||
| SET "attributeTypeId" = directory.id | ||
| FROM "Directory" AS directory | ||
| WHERE ace.attribute_type_name = directory.name | ||
milov-dmitriy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """, | ||
| ), | ||
| ) | ||
|
|
||
| op.create_foreign_key( | ||
| op.f("AccessControlEntries_directoryAttributeTypeId_fkey"), | ||
| "AccessControlEntries", | ||
| "Directory", | ||
| ["attributeTypeId"], | ||
| ["id"], | ||
| ondelete="CASCADE", | ||
| ) | ||
| op.create_index( | ||
| op.f("idx_ace_attribute_type_id"), | ||
| "AccessControlEntries", | ||
| ["attributeTypeId"], | ||
| unique=False, | ||
| postgresql_using="hash", | ||
| ) | ||
| op.drop_column("AccessControlEntries", "attribute_type_name") | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -80,7 +80,6 @@ async def create(self, dto: AttributeTypeDTO) -> None: | |
| entity_type_name=EntityTypeNames.ATTRIBUTE_TYPE, | ||
| attributes=( | ||
| AttributeDTO(name=Names.OID, values=[str(dto.oid)]), | ||
| AttributeDTO(name=Names.NAME, values=[str(dto.name)]), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. не совсем понял, зачем это удалено |
||
| AttributeDTO( | ||
| name=Names.OBJECT_CLASS, | ||
| values=ATTRIBUTE_TYPE_OBJECT_CLASS_NAMES, | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -63,10 +63,10 @@ async def _get_all_raw_aces_legacy(self) -> Sequence[Row[tuple[int, str]]]: | |
| select(qa(AccessControlEntry.id), qa(AttributeTypeLegacy.name)) | ||
| .join( | ||
| AttributeTypeLegacy, | ||
| qa(AccessControlEntry.attribute_type_id) | ||
| == qa(AttributeTypeLegacy.id), | ||
| qa(AccessControlEntry.attribute_type_name) | ||
| == qa(AttributeTypeLegacy.name), | ||
| ) | ||
| .where(qa(AccessControlEntry.attribute_type_id).is_not(None)), | ||
| .where(qa(AccessControlEntry.attribute_type_name).is_not(None)), | ||
| ) | ||
milov-dmitriy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return ace_rows_q.all() | ||
|
|
||
|
|
@@ -102,13 +102,14 @@ async def _get_all_raw_aces(self) -> Sequence[Row[tuple[int, str]]]: | |
| select(qa(AccessControlEntry.id), qa(Directory.name)) | ||
| .join( | ||
| Directory, | ||
| qa(AccessControlEntry.attribute_type_id) == qa(Directory.id), | ||
| qa(AccessControlEntry.attribute_type_name) | ||
| == qa(Directory.name), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ) | ||
milov-dmitriy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .join( | ||
| EntityType, | ||
| qa(EntityType.id) == qa(Directory.entity_type_id), | ||
| ) | ||
| .where(qa(EntityType.name) == EntityTypeNames.ATTRIBUTE_TYPE) | ||
| .where(qa(AccessControlEntry.attribute_type_id).is_not(None)), | ||
| .where(qa(AccessControlEntry.attribute_type_name).is_not(None)), | ||
| ) | ||
| return ace_rows_q.all() | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не такой запрос, мы же хотим сделать на ldapDisplayName связь, как жто было до этого. В AccessControlEntry.attribute_type.name лежал твой новый ldap_display_name, а directory.name у того же атрибута, который мы перенесли из таблицы в ldap дерево, может отличаться и сильно. Например, Directory.name = 'Address-Book-Container', а его lDAPDisplayName = addressBookContainer - разница колоссальная