-
Notifications
You must be signed in to change notification settings - Fork 1
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
soft deletes #22
Closed
Closed
soft deletes #22
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5cb2d73
soft deletes initial commit
Zimovchik 23a3ec1
fix
Zimovchik 770f528
fix
Zimovchik 041d8d1
relationship
Zimovchik 8dadb9f
relationships
Zimovchik 7882607
tests fix up to soft deletes
Zimovchik 9765040
Merge branch 'main' into soft-deletes
Zimovchik 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
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
migrations/versions/0c117913717b_adding_is_deleted_fields.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,31 @@ | ||
"""adding_is_deleted_fields | ||
|
||
Revision ID: 0c117913717b | ||
Revises: 656228b2d6e0 | ||
Create Date: 2024-10-24 06:59:27.285029 | ||
|
||
""" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = '0c117913717b' | ||
down_revision = '656228b2d6e0' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.add_column('comment', sa.Column('is_deleted', sa.Boolean(), nullable=False, server_default=sa.false())) | ||
op.add_column('lecturer', sa.Column('is_deleted', sa.Boolean(), nullable=False, server_default=sa.false())) | ||
op.add_column( | ||
'lecturer_user_comment', sa.Column('is_deleted', sa.Boolean(), nullable=False, server_default=sa.false()) | ||
) | ||
|
||
|
||
def downgrade(): | ||
op.drop_column('lecturer_user_comment', 'is_deleted') | ||
op.drop_column('lecturer', 'is_deleted') | ||
op.drop_column('comment', 'is_deleted') |
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 |
---|---|---|
|
@@ -33,7 +33,12 @@ class Lecturer(BaseDbModel): | |
middle_name: Mapped[str] = mapped_column(String, nullable=False) | ||
avatar_link: Mapped[str] = mapped_column(String, nullable=True) | ||
timetable_id: Mapped[int] = mapped_column(Integer, unique=True, nullable=False) | ||
comments: Mapped[list[Comment]] = relationship("Comment", back_populates="lecturer") | ||
comments: Mapped[list[Comment]] = relationship( | ||
"Comment", | ||
back_populates="lecturer", | ||
primaryjoin="and_(Lecturer.id == Comment.lecturer_id, not_(Comment.is_deleted))", | ||
) | ||
is_deleted: Mapped[bool] = mapped_column(Boolean, default=False) | ||
|
||
@hybrid_method | ||
def search(self, query: str) -> bool: | ||
|
@@ -56,14 +61,24 @@ class Comment(BaseDbModel): | |
mark_kindness: Mapped[int] = mapped_column(Integer, nullable=False) | ||
mark_freebie: Mapped[int] = mapped_column(Integer, nullable=False) | ||
mark_clarity: Mapped[int] = mapped_column(Integer, nullable=False) | ||
lecturer_id: Mapped[int] = mapped_column(Integer, ForeignKey("lecturer.id")) | ||
lecturer_id: Mapped[int] = mapped_column( | ||
Integer, | ||
ForeignKey("lecturer.id"), | ||
primary_join="and_(Comment.lecturer_id==Lecturer.id, not_(Lecturer.is_deleted))", | ||
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. не туда вписал) |
||
) | ||
lecturer: Mapped[Lecturer] = relationship("Lecturer", back_populates="comments") | ||
review_status: Mapped[ReviewStatus] = mapped_column(DbEnum(ReviewStatus, native_enum=False), nullable=False) | ||
is_deleted: Mapped[bool] = mapped_column(Boolean, default=False) | ||
|
||
|
||
class LecturerUserComment(BaseDbModel): | ||
id: Mapped[int] = mapped_column(Integer, primary_key=True) | ||
lecturer_id: Mapped[int] = mapped_column(Integer, ForeignKey("lecturer.id")) | ||
lecturer_id: Mapped[int] = mapped_column( | ||
Integer, | ||
ForeignKey("lecturer.id"), | ||
primary_join="and_(LecturerUserComment.lecturer_id==Lecturer.id),not_(Lecturer.is_deleted))", | ||
) | ||
user_id: Mapped[int] = mapped_column(Integer, nullable=False) | ||
create_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False) | ||
update_ts: Mapped[datetime.datetime] = mapped_column(DateTime, default=datetime.datetime.utcnow, nullable=False) | ||
is_deleted: Mapped[bool] = mapped_column(Boolean, default=False) |
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
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.
nullable False
надо тогда докинуть update на старые строки в базе, чтоб не упало